3.4. creat FunctionA new file can also be created by calling the creat function.
Historically, in early versions of the UNIX System, the second argument to open could be only 0, 1, or 2. There was no way to open a file that didn't already exist. Therefore, a separate system call, creat, was needed to create new files. With the O_CREAT and O_TRUNC options now provided by open, a separate creat function is no longer needed.We'll show how to specify mode in Section 4.5 when we describe a file's access permissions in detail.One deficiency with creat is that the file is opened only for writing. Before the new version of open was provided, if we were creating a temporary file that we wanted to write and then read back, we had to call creat, close, and then open. A better way is to use the open function, as inopen (pathname , O_RDWR | O_CREAT | O_TRUNC, mode ); |