#include <unistd.h>
|
int
close (int d); |
When a process exits, all associated file descriptors are freed, but since there is a limit on active descriptors per processes, the close system call is useful when a large quantity of file descriptors are being handled.
/******************************************************************************************** * Detailed description : This test code demonstrates usage of close system call * * Preconditions : None. *******************************************************************************************/ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <fcntl.h> int main() { int fd = 0; fd = open("Example.txt" , O_CREAT | O_RDWR , 0666); if(fd < 0 ) { printf("Failed to open file Example.txt \n"); return -1; } if(close(fd) < 0 ) { printf("Failed to close file Example.txt \n"); return -1; } printf("File Example.txt closed \n" ); return 0; }
Output
File Example.txt closed
[EBADF] | |
The d argument is not an active descriptor. | |
[EINTR] | |
An interrupt was received(Not supported). | |
[ENOSPC] | |
The underlying object did not fit, cached data was lost(Not supported). | |
© 2005-2007 Nokia |