In late 1989, ANSI Standard X3.1591989 for the C programming language was approved. This standard has also been adopted as international standard ISO/IEC 9899:1990. In 1999, the ISO C standard was updated and approved as ISO/IEC 9899:1999, largely to improve support for applications that perform numerical processing.
· ISO/IEC 9945-1 (IEEE Standard 1003.1-1996), which includes
IEEE Standard 1003.1-1990 IEEE Standard 1003.1b-1993 (real-time extensions) IEEE Standard 1003.1c-1995 (pthreads) IEEE Standard 1003.1i-1995 (real-time technical corrigenda)
· IEEE P1003.1a draft standard (system interface revision)
· IEEE Standard 1003.1d-1999 (advanced real-time extensions)
· IEEE Standard 1003.1j-2000 (more advanced real-time extensions)
· IEEE Standard 1003.1q-2000 (tracing)
· IEEE Standard 1003.2d-1994 (batch extensions)
· IEEE P1003.2b draft standard (additional utilities)
· Parts of IEEE Standard 1003.1g-2000 (protocol-independent interfaces)
· ISO/IEC 9945-2 (IEEE Standard 1003.2-1993)
· The Base Specifications of the Single UNIX Specification, version 2, which include
· System Interface Definitions, Issue 5
· Commands and Utilities, Issue 5
· System Interfaces and Headers, Issue 5
· Open Group Technical Standard, Networking Services, Issue 5.2
A superset of the POSIX.1 standard, specifies additional interfaces that extend the functionality provided by the basic POSIX.1 specification.
9、The header <sys/types.h> defines some implementation-dependent data types, called theprimitive system data types. More of these data types are defined in other headers also. These data types are defined in the headers with the C typedef facility. Most end in _t. Figure 2.20. Some common primitive system data types Type Description caddr_t core address (Section 14.9) clock_t counter of clock ticks (process time) (Section 1.10) comp_t compressed clock ticks (Section 8.14) dev_t device numbers (major and minor) (Section 4.23) fd_set file descriptor sets (Section 14.5.1) fpos_t file position (Section 5.10) gid_t numeric group IDs ino_t i-node numbers (Section 4.14) mode_t file type, file creation mode ( ection 4.5) S nlink_t link counts for directory entries (Section 4.14) off_t file sizes and offsets (signed) (seek, Section 3.6) l pid_t process IDs and process group IDs (signed) ( ections 8.2 and 9.4) S ptrdiff_t result of subtracting two pointers (signed) rlim_t resource limits (Section 7.11) sig_atomic_t data type that can be accessed atomically ( ection 10.15) S sigset_t signal set (Section 10.11) size_t sizes of objects (such as strings) (unsigned) ( ection 3.7) S ssize_t functions that return a count of bytes (signed) (ead, write, Section 3.7) r time_t counter of seconds of calendar time (Section 1.10) uid_t numeric user IDs wchar_t can represent all distinct character codes 10 Conflicts Between Standards ISO C defines the function clock to return the amount of CPU time used by a process. The value returned is a value. To convert this value to seconds, we divide it by CLOCKS_PER_SEC, which is defined in the<time.h> header. POSIX.1 defines clock_t the function times that returns both the CPU time (for the caller and all its terminated children) and the clock time. All these time values are clock_t values. The sysconf function is used to obtain the number of clock ticks per second for use with the return values from the times function. What we have is the same term, clock ticks per second, defined differently by ISO C and POSIX.1. Both standards also use the same data type (clock_t ) to hold these different values. The difference can be seen in Solaris, whereclock returns microseconds (hence CLOCKS_PER_SEC is 1 million), whereassysyconf returns the value 100 for clock ticks per second. Another area of potential conflict is when the ISO C standard specifies a function, but doesn't specify it as strongly as POSIX.1 does. This is the case for functions that require a different implementation in a POSIX environment (with multiple processes) than in an ISO C environment (where very little can be assumed about the host operating system). Nevertheless, many POSIX-compliant systems implement the ISO C function, for compatibility. The signal function is an example. If we unknowingly use thesignal function provided by Solaris (hoping to write portable code that can be run in ISO C environments and under older UNIX systems), it'll provide semantics different from the POSIX.1 sigaction function. 11 Most file I/O on a UNIX system can be performed using only five functions: open, read, write, lseek, and close.They're are often referred to as unbuffered I/O, in contrast to the standard I/O routines. The term unbuffered means that each read or write invokes a system call in the kernel. These unbuffered I/O functions are not part of ISO C, but are part of POSIX.1 and the Single UNIX Specification. 12 File Descriptors
To the kernel, all open files are referred to by file descriptors. A file descriptor is a non-negative integer. When we open an existing file or create a new file, the kernel returns a file descriptor to the process. When we want to read or write a file, we identify the file with the file descriptor that was returned by open or creat as an argument to either read or write.
By convention, UNIX System shells associate file descriptor 0 with the standard input of a process, file descriptor 1 with the standard output, and file descriptor 2 with the standard error. This convention is used by the shells and many applications; it is not a feature of the UNIX kernel.
The magic numbers 0, 1, and 2 should be replaced in POSIX-compliant applications with the symbolic constants STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO. These constants are defined in the <unistd.h> header.
A file is opened or created by calling the open function.
int open(const char *pathname, int oflag, ... /*
|
A new file can also be created by calling the creat function.
int creat(const char *pathname, mode_t mode);
|
Returns: file descriptor opened for write-only if OK, 1 on error |
Note that this function is equivalent to
open (pathname, O_WRONLY | O_CREAT | O_TRUNC, mode);
An open file is closed by calling the close function.
|
off_t lseek(int filedes, off_t offset, int whence);
|
Data is read from an open file with the read function.
ssize_t read(int filedes, void *buf, size_t nbytes);
|
Data is written to an open file with the write function.
ssize_t write(int filedes, const void *buf, size_t
|