Linux system programming (1) - system call

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);

For parameters and principles, please refer to the Linux file system

Example:

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

intmain()
{
	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;

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324730763&siteId=291194637