Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / djbunix.h / open_write_closeat.3.md

% limb manual
% open_write_closeat(3)
% limb 0.1.0
% 2023-07-24

# NAME

open_write_closeat, open_write_close, open_writev_closeat, open_writev_close -
open, write & close a file

# SYNOPSIS

    #include <limb/unix-transactional.h>

```pre hl
int open_write_closeat(int <em>fd</em>, const char *<em>file</em>, const char *<em>data</em>, size_t <em>dlen</em>)
int open_write_close(const char *<em>file</em>, const char *<em>data</em>, size_t <em>dlen</em>)

int open_writev_closeat(int <em>fd</em>, const char *<em>file</em>, const struct iovec *<em>v</em>, unsigned <em>n</em>)
int open_writev_close(const char *<em>file</em>, const struct iovec *<em>v</em>, unsigned <em>n</em>)
```

# DESCRIPTION

The `open_write_closeat`() function will write the data pointed by `data` of
length `dlen` bytes into a file named `file`. If `file` describes a relative
path, it is relative to the directory associated with the file descriptor `fd`,
which may be *AT_FDCWD* to use the current working directory.

It actually creates a new temporary file into which all data is written first,
and then renames it to `file`. As such, any error will leave any previously
existing file of the same name unchanged (and the temporary file will have been
removed).

The `open_write_close`() macro is similar to `open_write_closeat`() except
relative paths are relative to the current working directory.

The `open_writev_closeat`() function is similar to `open_write_closeat`(),
except the data to be written will be gathered from the array pointed by `v` of
`n` vectors.

The `open_writev_close`() macro is similar to `open_writev_closeat`() except
relative paths are relative to the current working directory.

# RETURN VALUE

These functions return 1 on success. Otherwise they return 0 and set `errno` to
indicate the error.

# ERRORS

These functions may fail and set `errno` for the errors described for
[open_tmpat](3) and [renameat](3).

The `open_write_close`() and `open_write_closeat`() functions may also fail and
set `errno` for the errors described for [allwrite](3).

The `open_writev_close`() and `open_writev_closeat`() functions may also fail
and set `errno` for the errors described for [allwritev](3).