The role of Stdin_fileno and its difference from STDIN

Source: Internet
Author: User
Tags fread

Recently Learning "UNIX Advanced Environment Programming", encountered the problem of Stdin_fileno, in this summary.

In some Unix system calls to Stdin_fileno for standard input, Stdout_fileno for standard output, Stderr_fileno for standard error, header file required when using <unistd.h>

Under Unix There are also stdin,stdout,stderr that mean the same thing.


1. The role of Stdin_fileno Stdin_fileno belongs to the System API interface library, which is declared asintType, is an open file handle, the corresponding function mainly includes open/read/write/system-level calls such as close. The file APIs provided at the operating system level are represented by file descriptors. Stdin_fileno is a file descriptor for a standard input device (typically a keyboard). 2. Difference1) data type inconsistency: stdin type is FILE*the Stdin_fileno type isintthe functions that use stdin are: Fread, fwrite, fclose, and so on, basically all functions with stdin_fileno starting with F are: Read, write, close, etc.2) stdin is a file * type, which belongs to standard I/O and advanced input/output functions. In <stdio.h>. Stdin_fileno is a file descriptor, a non-negative integer, typically defined as 0,1,2, which belongs to I/O without buffer, calls the system call directly, in <unistd.h>. 3) Stdin_fileno is a standard input file descriptor, see/usr/include/unistd.h Code:/*Standard file descriptors.*/#defineStdin_fileno 0/* standard input. */#defineStdout_fileno 1/* standard output. */#defineStderr_fileno 2/* standard error output. */4) levels are different. STDIN belongs to the standard library processing input stream, which is declared as FILE type, and the corresponding function is preceded by F, such as fopen/fread/fwrite/fclose Standard library calls such as Stdin_fileno belong to the System API interface library, which is declared asintType, is an open file handle, the corresponding function mainly includes open/read/write/system-level calls such as close. The standard library encapsulates system API calls, such as fread internal implementations called read. 5the file APIs provided at the operating system level are represented by file descriptors. Stdin_fileno is a file descriptor for a standard input device (typically a keyboard). 6) Once wondered why a plastic fd (stdin_fileno=0) can represent an open file? Later understood, and our mobile phone number is similar, mobile phone number is only a 9-digit number of plastic, but in the mobile phone network, it can be used to distinguish between different mobile phone terminals. Standard CThe file Operation function library provided at the + + level is used file* to represent the file, and stdin is the file* that points to the standard input device file.
http://blog.csdn.net/yeyuangen/article/details/6781999
http://blog.csdn.net/mjay1234/article/details/7357261

The role of Stdin_fileno and its difference from STDIN

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.