From: Karel Zak Date: Mon, 1 Feb 2010 12:07:17 +0000 (+0100) Subject: libblkid: add blkid_openat(), cleanup blkid_fstatat() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d96648b822a69e88e9597315a03ccb28bf55267a;p=util-linux libblkid: add blkid_openat(), cleanup blkid_fstatat() Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index 975878c4..4d21304e 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -267,6 +267,8 @@ extern char *blkid_strndup(const char *s, const int length); extern char *blkid_strconcat(const char *a, const char *b, const char *c); extern int blkid_fstatat(DIR *dir, const char *dirname, const char *filename, struct stat *st, int nofollow); +extern int blkid_openat(DIR *dir, const char *dirname, const char *filename, + int flags); #define BLKID_CACHE_FILE "/etc/blkid.tab" #define BLKID_CONFIG_FILE "/etc/blkid.conf" diff --git a/shlibs/blkid/src/devno.c b/shlibs/blkid/src/devno.c index 7b9438ff..284f8733 100644 --- a/shlibs/blkid/src/devno.c +++ b/shlibs/blkid/src/devno.c @@ -96,14 +96,30 @@ int blkid_fstatat(DIR *dir, const char *dirname, const char *filename, return fstatat(dirfd(dir), filename, st, nofollow ? AT_SYMLINK_NOFOLLOW : 0); #else - char device[PATH_MAX]; + char path[PATH_MAX]; + int len; + + len = snprintf(path, sizeof(path), "%s/%s", dirname, filename); + if (len < 0 || len + 1 > sizeof(path)) + return -1; + + return nofollow ? lstat(path, st) : stat(path, st); +#endif +} + +int blkid_openat(DIR *dir, const char *dirname, const char *filename, int flags) +{ +#ifdef HAVE_FSTATAT + return openat(dirfd(dir), filename, flags); +#else + char path[PATH_MAX]; int len; - len = snprintf(device, sizeof(device), "%s/%s", dirname, filename); - if (len < 0 || len + 1 > sizeof(device)) + len = snprintf(path, sizeof(path), "%s/%s", dirname, filename); + if (len < 0 || len + 1 > sizeof(path)) return -1; - return nofollow ? lstat(device, st) : stat(device, st); + return open(path, flags); #endif }