sd-id128: introduce id128_write_at()

This commit is contained in:
Yu Watanabe
2023-04-04 11:46:18 +09:00
parent 0f44b76601
commit c227c46b8b
2 changed files with 8 additions and 4 deletions
+4 -3
View File
@@ -145,14 +145,15 @@ int id128_write_fd(int fd, Id128Flag f, sd_id128_t id) {
return 0;
}
int id128_write(const char *path, Id128Flag f, sd_id128_t id) {
int id128_write_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t id) {
_cleanup_close_ int fd = -EBADF;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
assert(path);
fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, 0444);
fd = xopenat(dir_fd, path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, 0444);
if (fd < 0)
return -errno;
return fd;
return id128_write_fd(fd, f, id);
}
+4 -1
View File
@@ -26,7 +26,10 @@ static inline int id128_read(const char *path, Id128Flag f, sd_id128_t *ret) {
}
int id128_write_fd(int fd, Id128Flag f, sd_id128_t id);
int id128_write(const char *path, Id128Flag f, sd_id128_t id);
int id128_write_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t id);
static inline int id128_write(const char *path, Id128Flag f, sd_id128_t id) {
return id128_write_at(AT_FDCWD, path, f, id);
}
void id128_hash_func(const sd_id128_t *p, struct siphash *state);
int id128_compare_func(const sd_id128_t *a, const sd_id128_t *b) _pure_;