]> err.no Git - util-linux/commitdiff
libblkid: add blkid_openat(), cleanup blkid_fstatat()
authorKarel Zak <kzak@redhat.com>
Mon, 1 Feb 2010 12:07:17 +0000 (13:07 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 1 Feb 2010 12:08:45 +0000 (13:08 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/devno.c

index 975878c4ba43eaa9214c4cf4403ee9a29041cb62..4d21304e3d4348cfa30372cf7fa5cad64d19b231 100644 (file)
@@ -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"
index 7b9438ff797ec83dfc5841be8d569701ea7ae090..284f87334fe016e70b789fdf549c8a168403b49d 100644 (file)
@@ -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
 }