Updated: April 19, 2023 |
Make a unique temporary filename and open the file, specifying some flags
#include <stdlib.h> #include <fcntl.h> int mkostemp( char* template, int oflags ); int mkostemps( char *template, int slen, int oflags );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The mkostemp() and mkostemps() functions take the given file name template and overwrite a portion of it to create a filename.
The generated file name is unique and suitable for use by the application. The Xs are replaced with the current process number and/or a unique letter combination. The number of unique file names that these functions can return depends on the number of Xs provided; the functions try at least 231 combinations before giving up.
The mkostemp() and mkostemps() functions (unlike mktemp()) create the template file, mode 0600 (i.e., read-write for the owner), returning a file descriptor opened for reading and writing. This avoids the race between testing for a file's existence and opening it for use.
The file descriptor of the temporary file, or -1 if no suitable file could be created (errno is set).
This function may also set errno to any value specified by open().
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |