From: Eric Blake Date: Mon, 7 Sep 2009 11:28:13 +0000 (-0600) Subject: openat: provide more convenience names X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=370fec14f2e177cf533cb967e2dc04354e883c45;p=pspp openat: provide more convenience names * modules/faccessat (configure.ac): Add C witness. * lib/unistd.in.h (readlinkat): Fix typo. * lib/openat.h (statat, lstatat, accessat, euidaccessat): New convenience wrappers. * top/maint.mk (sc_prohibit_openat_without_use): Allow these wrappers in syntax checks. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 04e5cc1956..f7ac99c4e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-09-07 Eric Blake + + openat: provide more convenience names + * modules/faccessat (configure.ac): Add C witness. + * lib/unistd.in.h (readlinkat): Fix typo. + * lib/openat.h (statat, lstatat, accessat, euidaccessat): New + convenience wrappers. + * top/maint.mk (sc_prohibit_openat_without_use): Allow these + wrappers in syntax checks. + 2009-09-06 Eric Blake doc: fix comments in recent patches diff --git a/lib/openat.h b/lib/openat.h index 1d8596fd86..433b9983df 100644 --- a/lib/openat.h +++ b/lib/openat.h @@ -81,4 +81,34 @@ lchmodat (int fd, char const *file, mode_t mode) return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW); } +static inline int +statat (int fd, char const *name, struct stat *st) +{ + return fstatat (fd, name, st, 0); +} + +static inline int +lstatat (int fd, char const *name, struct stat *st) +{ + return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW); +} + +#if GNULIB_FACCESSAT +/* For now, there are no wrappers named laccessat or leuidaccessat, + since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and + since access rights on symlinks are of limited utility. */ + +static inline int +accessat (int fd, char const *file, int mode) +{ + return faccessat (fd, file, mode, 0); +} + +static inline int +euidaccessat (int fd, char const *file, int mode) +{ + return faccessat (fd, file, mode, AT_EACCESS); +} +#endif + #endif /* _GL_HEADER_OPENAT */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 6503529115..902b025925 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -208,7 +208,7 @@ ssize_t readlinkat (int fd, char const *file, char *buf, size_t len); #elif defined GNULIB_POSIXCHECK # undef readlinkat # define readlinkat(d,n,b,l) \ - (GL_LINK_WARNING ("faccessat is not portable - " \ + (GL_LINK_WARNING ("readlinkat is not portable - " \ "use gnulib module symlinkat for portability"), \ readlinkat (d, n, b, l)) #endif diff --git a/modules/faccessat b/modules/faccessat index d7737bac9d..92d818556b 100644 --- a/modules/faccessat +++ b/modules/faccessat @@ -14,6 +14,7 @@ unistd configure.ac: gl_FUNC_FACCESSAT +gl_MODULE_INDICATOR([faccessat]) gl_UNISTD_MODULE_INDICATOR([faccessat]) Makefile.am: diff --git a/top/maint.mk b/top/maint.mk index 45bc0c9c1b..c0c3f271fe 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -295,7 +295,7 @@ sc_prohibit_root_dev_ino_without_use: sc_prohibit_openat_without_use: @h='"openat.h"' \ - re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?ch(own|mod)at)\>' \ + re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>' \ $(_header_without_use) # Prohibit the inclusion of c-ctype.h without an actual use.