[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: make lchmodat friendlier
From: |
Eric Blake |
Subject: |
Re: make lchmodat friendlier |
Date: |
Mon, 07 Sep 2009 05:35:35 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Jim Meyering on 9/6/2009 11:49 PM:
>> Also, should "openat.h" provide shortcuts named:
>>
>> accessat() => faccessat(,0)
>> euidaccessat() => faccessat(,AT_EACCESS)
>> statat() => fstatat(,0)
>> lstatat() => fstatat(,AT_SYMLINK_NOFOLLOW)
>>
>> to match the existing shortcuts of chownat, lchownat, etc.
>
> Good idea.
> I hesitated to appropriate the names initially, but the combination
> of increased readability and orthogonality make it worthwhile.
Done as follows.
Unfortunately, the naming of unlinkat prevents doing:
unlinkat() => unlinkat(,0)
so, I did not do this (even though I debated about it):
rmdirat() => unlinkat(,AT_REMOVEDIR)
Likewise, once we have support, we could do:
lutimensat() => utimensat(,AT_SYMLINK_NOFOLLOW)
but not utimensat. And I don't know of any good naming for the two
variants of linkat (there is no well-known short name that indicates
whether link will hard-link a symlink or follow it).
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkqk8AcACgkQ84KuGfSFAYBi/ACbB427B01pHBheU9GTiINZ4KlA
3KgAoJ6p1KEYdaj3n4uIeOUVKrczUNJu
=LDNW
-----END PGP SIGNATURE-----
>From 370fec14f2e177cf533cb967e2dc04354e883c45 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 7 Sep 2009 05:28:13 -0600
Subject: [PATCH] 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 <address@hidden>
---
ChangeLog | 10 ++++++++++
lib/openat.h | 30 ++++++++++++++++++++++++++++++
lib/unistd.in.h | 2 +-
modules/faccessat | 1 +
top/maint.mk | 2 +-
5 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 04e5cc1..f7ac99c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-09-07 Eric Blake <address@hidden>
+
+ 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 <address@hidden>
doc: fix comments in recent patches
diff --git a/lib/openat.h b/lib/openat.h
index 1d8596f..433b998 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 6503529..902b025 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 d7737ba..92d8185 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 45bc0c9..c0c3f27 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.
--
1.6.3.3.334.g916e1