linux系统编程(一)-系统调用

1.open()

       #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>
       int open(const char *pathname, int flags);

       int open(const char *pathname, int flags, mode_t mode);

各个参数及原理参见Linux文件系统

示例:

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

int main()
{
	int fd=open("open1.c",O_RDONLY);
	if(fd==-1)
	{
		perror("open error");
	}
	else if(fd>0)
	{
		printf("file descriptor:%d\n",fd);
		close(fd);
	}
	return 0;

}

猜你喜欢

转载自blog.csdn.net/sunbo94/article/details/80040281
今日推荐