* 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
}
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))
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;
}