NAME
mkfiletemp, mkfiletempat - open a new temporary file
SYNOPSIS
#include <limb/posixplz.h>
typedef int (*create_fn) (const char *file, mode_t mode, void *data) typedef int (*createat_fn) (int fd, const char *file, mode_t mode, void *data) int mkfiletemp(char *name, create_fn fn, mode_t mode, void *data) int mkfiletempat(int bfd, char *name, createat_fn fnat, mode_t mode, void *data)
DESCRIPTION
The mkfiletemp
() function will open a new temporary file using the function
pointed by fn
, passing it a file name based on the template pointed by
name
- which must bend with at least 6 characters X
that will be replaced
with random (printable) characters - as well as the mode
and data
arguments.
The memory pointed by name
will be modified, replacing the trailing X
characters so that name
contains the name of the file actually opened.
The fn
function should create & open a file whose name is pointed by its first
argument. It should return the file descriptor of the newly created file on
success, otherwise returning -1 and setting errno
appropriately. In case of
failure due to EEXIST a new file name will automatically be generated and a
new call made.
The mkfiletempat
() function is similar to mkfiletemp
() except it takes
a file descriptor bfd
which will be passed as first argument to fnat
.
The fnat
function should create & open a file whose name is pointed by its
second argument, which, when specifying a relative path, should be determined
relative to the directory associated with the file descriptor passed as its
first argument.
If passed the special value AT_FDCWD in the bfd
parameter, the current
working directory should be used used.
It should otherwise behave as fn
, notably returning the file descriptor of the
newly created file on success, otherwise -1 and setting errno
appropriately
RETURN VALUE
These functions return the file descriptor to the newly created temporary file,
as returned by fn
or fnat
, on success. Otherwise they return -1 and set
errno
to indicate the error.
ERRORS
These functions may fail if :
EINVAL
The template filename pointed by name
did not end with at least 6 X
.
They may also fail and set errno
for any of the errors described for the
function pointed by fn
or fnat
, save for EEXIST.