【设计开发】 Linux C文件创建Open函数

 

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

 

int main(int argc, char *argv[]) 
{
    int i ;
    int fd ;
    
    char wbuf[] = "This is write file test!";
    
    printf("hello, world!\n");

    fd=open("test.v",O_WRONLY | O_CREAT | O_TRUNC,0600);
    
    if(fd == -1)
    {
       printf("Open Failed!\n");
    }
    else
    {
       printf("Open Success!\n");
    }

    if(write(fd,wbuf,strlen(wbuf)) != -1)
    {
       printf("Write Success!\n");
    }
}

 

posted @ 2018-08-01 22:33  digital-world  阅读(1926)  评论(0编辑  收藏  举报