How does "UNIX" use BUF and fgets in the Open function in file IO

Source: Internet
Author: User
Tags tmp file

The Open function opens a few ways to create a file:

1) The first case is by specifying the path:

Open = ("/tmp/text". C ", o_rdwr| O_creat| o_append,0666);

This will automatically create a text.c file in the/tmp file directory.


2) Enter a command in the shell terminal via int mian (int argc,char *argv[]), specify the file, and automatically create the Do not customize the file path by default

Open = (argv[1],o_rdwr| O_creat| o_append,0666);


3) for the file pathname, in fact, the computer is also in the form of strings stored in the system cache, so that we can define a string array to create the file in disguise, but also through the fgets function through the standard input to create open files, but it is important to note that for the standard input, The system will add ' \ n ' at the end of the string to change the file path in the BUF, and we will have to strlen (BUF) in the buf of the fgets input to remove ' \ n '

The specific code is as follows:


How does "UNIX" use BUF and fgets in the Open function in file IO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.