As the name implies, Creat creates a new file, open opens the file. However, open can also play a role in creating a new file.
#include <fcntl.h>int creat (const char *pathname, mode_t mode);//returns:file descriptor opened for write-only if O K, 1 On Error
When the creat file already exists, creat truncates the file's original file, and the modified time access time of the file is also modified.
creat equivalent to: open (pathname, o_wronly | O_creat | O_trunc, mode);
Open
A file is opened or created by calling the open function.
#include <fcntl.h>int open (const char *pathname, int oflag, .../*mode_t mode */);//returns:file Descriptor if O K, 1 On Error
The third parameter is only useful if you are creating a file.
One deficiency with creat is, the file is opened only for writing. Before the new version of Open is provided, if we were creating a temporary file, we wanted to write and then read ba CK, we had to call creat, close, and then open. A better-to-use of the open function, as in
Open (Pathname, O_RDWR | O_creat | O_trunc, mode);
From Apue
In general, the open feature is more powerful and includes the functionality of the creat. It is recommended to use open.
The difference between the creat function and the Open function