]> err.no Git - util-linux/commitdiff
lib: pttype - extend the API to work with file descriptors
authorKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2009 13:17:59 +0000 (14:17 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2009 13:17:59 +0000 (14:17 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/pttype.h
lib/pttype.c

index d6fe8128cf16c811915220d506bb1fd2ded78f59..d345501c08208a525c0a67755d95a1ed501edd7b 100644 (file)
@@ -6,5 +6,6 @@
  * libdisk from xfsprogs to util-linux-ng.
  */
 extern const char *get_pt_type(const char *device);
+extern const char *get_pt_type_pt(int fd);
 
 #endif
index 7e1657de85bd175224a2d725ec8bbccccad85319..c2294f13d585cd060b985fb6eca5422cc939aa05 100644 (file)
@@ -235,15 +235,12 @@ bsd_parttable(unsigned char *base)
 }
 
 const char *
-get_pt_type(const char *device)
+get_pt_type_fd(int fd)
 {
-       int     fd;
        char    *type = NULL;
        unsigned char   buf[PTTYPE_BUFSIZ];
 
-       if ((fd = open(device, O_RDONLY)) < 0)
-               ;
-       else if (read(fd, buf, PTTYPE_BUFSIZ) != PTTYPE_BUFSIZ)
+       if (read(fd, buf, PTTYPE_BUFSIZ) != PTTYPE_BUFSIZ)
                ;
        else {
                if (sgi_parttable(buf))
@@ -259,9 +256,20 @@ get_pt_type(const char *device)
                else if (bsd_parttable(buf))
                        type = "BSD";
        }
+       return type;
+}
+
+const char *
+get_pt_type(const char *device)
+{
+       int fd;
+       const char *type;
 
-       if (fd >= 0)
-               close(fd);
+       fd = open(device, O_RDONLY);
+       if (fd == -1)
+               return NULL;
+       type = get_pt_type_fd(fd);
+       close(fd);
        return type;
 }