OPEN system call

Function prototype

int open (char * pathname, int how);
path name pathname open method how

Three ways to open

O_RDONLY Read only
O_WRONLY Write only
O_RDWR Read and write
There are these three macro definitions in <fcntl.h>

return value

-1 Open failed
int Successful return returns a file descriptor

Code

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
    
    
	int fd = -1;
	fd = open("/home/zzh35/TestWho/1.txt", O_RDONLY);
	
	if(-1 != fd)
	{
    
    
		printf("%d\n",fd);
	}
	else if(-1 == fd)
	{
    
    
		printf("-1 Open fail\n");
	}
	return 0;
}

The operation result returned a file descriptor 3
details

Guess you like

Origin blog.csdn.net/ZZHinclude/article/details/114944268