This Linux Program illustrates Creating a new File using File Descriptors. To create a new file, we will going to use
creat() system call that takes two arguments. The first argument is the file-name and the second one is mode which sets the permissions of read, write and execute for file owner. In this example, we are using the mode as S_IRWXU which indicates that the file owner has the permissions to read, write and execute the file.
creat() system call that takes two arguments. The first argument is the file-name and the second one is mode which sets the permissions of read, write and execute for file owner. In this example, we are using the mode as S_IRWXU which indicates that the file owner has the permissions to read, write and execute the file.
Here is the source code of Linux Program to Create a File using File Descriptors. The Linux Program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* Linux Program to Create a File using File Descriptors.
*/
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
int fd;
if (argc 0) {
printf("New file %s created!\n", argv[1]);
} else {
perror("Problem in creating the file.");
exit(1);
}
}
$ gcc create_file.c $ ./a.out new_file After executing the above command, creat() system call tries to create a new file with the name new_file and if it has been created successfully then we will see the output given below, New file new_file created!
Sanfoundry Global Education & Learning Series – 1000 Linux Programs.
advertisement
If you wish to look at all Linux Programming examples, go to Linux Programs.
Related Posts:
- Check Information Technology Books
- Apply for Programming Internship
- Practice Programming MCQs
- Check Linux Books