open:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char * filepath, int flags);
int open(const char * filepath, int flags, mode_t mode);
fd or -1
close:
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int close(int fd); 0 or -1
create:
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int creat(const char * pathname, mode_t mode); fd or -1
A demo of open
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main(int argc, char ** argv)
{
errno = 0;
int fd;
if(fd = open("testOpen.c", O_CREAT | O_EXCL, S_IRUSR | S_IWUSR) == -1)
{
perror("open");
exit(1);
}
else
printf("Open file testOpen.c successfully./n");
close(fd);
return 0;
}
save as demo_oPen.c
gcc demo_oPen.c