From 7d06701bfaad445e48832ba4fd189ffc36e34387 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 5 May 2015 12:50:24 +0000 Subject: - add stat_at - make case_diff* work as a function is more cases - make sig_number case-insensitive - make child signal unblocking work in child_spawn* --- src/libunixonacid/stat_at.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/libunixonacid/stat_at.c (limited to 'src/libunixonacid') diff --git a/src/libunixonacid/stat_at.c b/src/libunixonacid/stat_at.c new file mode 100644 index 0000000..e8b049f --- /dev/null +++ b/src/libunixonacid/stat_at.c @@ -0,0 +1,77 @@ +/* ISC license. */ + +#include + +#ifdef SKALIBS_HASOPENAT + +#ifndef _ATFILE_SOURCE +#define _ATFILE_SOURCE +#endif + +#include +#include +#include +#include +#include + +int stat_at (int dirfd, char const *file, struct stat *st) +{ + return fstatat(dirfd, file, st, 0) ; +} + +int lstat_at (int dirfd, char const *file, struct stat *st) +{ + return fstatat(dirfd, file, st, AT_SYMLINK_NOFOLLOW) ; +} + +#else + +#include +#include +#include +#include +#include +#include + +static int fstat_at (int dirfd, char const *file, struct stat *st, int (*dostat)(char const *, struct stat *)) +{ + int r ; + int fdhere = open_read(".") ; + if (fdhere < 0) return -1 ; + if (fd_chdir(dirfd) < 0) + { + register int e = errno ; + fd_close(fdhere) ; + errno = e ; + return -1 ; + } + r = (*dostat)(file, st) ; + if (r < 0) + { + register int e = errno ; + fd_chdir(fdhere) ; + fd_close(fdhere) ; + errno = e ; + return -1 ; + } + if (fd_chdir(fdhere) < 0) + { + register int e = errno ; + fd_close(fdhere) ; + errno = e ; + return -1 ; + } + return r ; +} + +int stat_at (int dirfd, char const *file, struct stat *st) +{ + return fstat_at(dirfd, file, st, &stat) ; +} + +int lstat_at (int dirfd, char const *file, struct stat *st) +{ + return fstat_at(dirfd, file, st, &lstat) ; +} + +#endif -- cgit v1.2.3