author | Olivier Brunel
<jjk@jjacky.com> 2023-05-14 12:02:06 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-05-20 18:06:40 UTC |
parent | c5e94fcc22572d882c412370a670f47037e9ef93 |
src/doc/unix-transactional.h.0.md | +6 | -0 |
src/doc/unix-transactional.h/openb_readat.3.md | +35 | -0 |
src/liblimb/include/limb/unix-transactional.h | +3 | -0 |
src/liblimb/unix-transactional.h/openb_readat.c | +11 | -0 |
src/liblimb/unix-transactional.h/openbc_readat.c | +11 | -0 |
diff --git a/src/doc/unix-transactional.h.0.md b/src/doc/unix-transactional.h.0.md index b48d1c9..e0afbe3 100644 --- a/src/doc/unix-transactional.h.0.md +++ b/src/doc/unix-transactional.h.0.md @@ -22,6 +22,12 @@ operations. The following functions are defined : +: [openb_readat](3) +:: Same as [openb_read](3) but relative path are based on given file descriptor. + +: [openbc_readat](3) +:: Same as [openc_read](3) but relative path are based on given file descriptor. + : [open_createat](3) :: Same as [open_create](3) but relative path are based of given file descriptor diff --git a/src/doc/unix-transactional.h/openb_readat.3.md b/src/doc/unix-transactional.h/openb_readat.3.md new file mode 100644 index 0000000..3cd837d --- /dev/null +++ b/src/doc/unix-transactional.h/openb_readat.3.md @@ -0,0 +1,35 @@ +% limb manual +% openb_readat(3) + +# NAME + +openb\_readat, openbc\_readat - open file relative to directory file descriptor + +# SYNOPSIS + + #include <limb/unix-transactional.h> + +```pre hl +int openb_readat(int <em>fd</em>, const char *<em>file</em>); +int openbc_readat(int <em>fd</em>, const char *<em>file</em>); +``` + +# DESCRIPTION + +The `openb_readat`() function opens `file` for reading in blocking mode. If +`file` specifies a relative path, it is relative to the directory associated +with the file descripor `fd`, which may be *AT_FDCWD* to use the current working +directory. + +The `openbc_readat`() function is similar, only with the *FD_CLOEXEC* flag set +for the opened file descriptor. + +# RETURN VALUE + +These functions return the opened file descriptor on success. Otherwise they +return -1 and set `errno` to indicate the error. + +# ERRORS + +These functions may fail and set `errno` for any of the errors described for +[open2_at](3). diff --git a/src/liblimb/include/limb/unix-transactional.h b/src/liblimb/include/limb/unix-transactional.h index 736dc96..5fff355 100644 --- a/src/liblimb/include/limb/unix-transactional.h +++ b/src/liblimb/include/limb/unix-transactional.h @@ -6,6 +6,9 @@ #include <skalibs/unix-transactional.h> +extern int openb_readat(int fd, const char *file); +extern int openbc_readat(int fd, const char *file); + extern int openc_createat(int fd, const char *file); extern int open_createat(int fd, const char *file); extern int openc_exclat(int fd, const char *file); diff --git a/src/liblimb/unix-transactional.h/openb_readat.c b/src/liblimb/unix-transactional.h/openb_readat.c new file mode 100644 index 0000000..a1fca88 --- /dev/null +++ b/src/liblimb/unix-transactional.h/openb_readat.c @@ -0,0 +1,11 @@ +/* This file is part of limb https://lila.oss/limb + * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <fcntl.h> +#include <limb/unix-transactional.h> + +int +openb_readat(int fd, const char *file) +{ + return open2_at(fd, file, O_RDONLY); +} diff --git a/src/liblimb/unix-transactional.h/openbc_readat.c b/src/liblimb/unix-transactional.h/openbc_readat.c new file mode 100644 index 0000000..4305316 --- /dev/null +++ b/src/liblimb/unix-transactional.h/openbc_readat.c @@ -0,0 +1,11 @@ +/* This file is part of limb https://lila.oss/limb + * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <fcntl.h> +#include <limb/unix-transactional.h> + +int +openbc_readat(int fd, const char *file) +{ + return open2_at(fd, file, O_RDONLY | O_CLOEXEC); +}