词条 | Write (system call) | ||||||||||||||||||||||||||||||||||||||
释义 |
The write is one of the most basic routines provided by a Unix-like operating system kernel. It writes data from a buffer declared by the user to a given device, maybe a file. This is the primary way to output data from a program by directly using a system call. The destination is identified by a numeric code. The data to be written, for instance a piece of text, is defined by a pointer and a size, given in number of bytes.
POSIX usageThe write call interface[1][2][3] is standardized by the POSIX specification. Data is written to a file by calling the write function. The function prototype is:
In above syntax, The write function returns the number of bytes successfully written into the array, which may at times be less than the specified nbytes. It returns -1 if an exceptional condition is encountered, see section on errors below. Usage ExampleErrors encountered during operationListed below are some errors[4][5] that could be encountered during writing to a file. The errors are macros listed in errno.h.
Higher level I/O functions calling writeThe write system call is not an ordinary function, in spite of the close resemblance. For example, in Linux with the x86 architecture, the system call uses the instruction INT 80H, in order to transfer control over to the kernel.[6] The write system call, and its counterpart read, being low level functions, are only capable of understanding bytes. Write cannot be used to write records, like classes. Thus, higher level input-output functions (like printf) are required. Often, the high-level interface is preferred, as compared to the cluttered low-level interface. These functions call other functions internally, and these in turn can make calls to write, giving rise to a layered assembly of functions.[7][8] With the use of this assembly the higher level functions can collect bytes of data and then write the required data into a file. See also
References1. ^http://www.unix.com/man-page/FreeBSD/2/write/ Manual page for Write 2. ^https://www.gnu.org/s/hello/manual/libc/I_002fO-Primitives.html#I_002fO-Primitives I/O Primitives 3. ^http://pubs.opengroup.org/onlinepubs/007904875/functions/write.html 4. ^https://www.gnu.org/s/hello/manual/libc/Error-Codes.html GNU C Library Manual 5. ^http://www.ibm.com/developerworks/aix/library/au-errnovariable/ IBM page listing errors 6. ^LINUX assembly language programming By Bob Neveln {{ISBN|978-0-13-087940-0}} 7. ^https://www.gnu.org/s/libc/ GNU C Library 8. ^http://ftp.gnu.org/gnu/glibc/ GNU C Library Download External links
2 : C POSIX library|System calls |
||||||||||||||||||||||||||||||||||||||
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。