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