aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-03-02 11:52:38 -0600
committerRob Landley <rob@landley.net>2016-03-02 11:52:38 -0600
commit7ca5dc4232b9ac5ee5cd25c8b5b33a58904cd251 (patch)
tree258fe0d485c5793e19a56be81f9d71e51476f0d8 /lib
parent323819c689448fffcf4d3ed20f2485b75ac64b64 (diff)
downloadtoybox-7ca5dc4232b9ac5ee5cd25c8b5b33a58904cd251.tar.gz
For years the man pages have said to #include <sys/types.h> to get
major/minor/makedev, but glibc has vowed to break existing programs (https://sourceware.org/ml/libc-alpha/2015-11/msg00253.html) and replace it with _another_ non-standard header (not in posix or lsb), so let's just add functions to lib/ that do the transform ourselves.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c15
-rw-r--r--lib/lib.h3
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 43db2e37..1c1f2248 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1043,3 +1043,18 @@ char *strnstr(char *line, char *str)
return *s ? s : 0;
}
+
+int dev_minor(int dev)
+{
+ return ((dev&0xfff00000)>>12)|(dev&0xff);
+}
+
+int dev_major(int dev)
+{
+ return (dev&0xfff00)>>8;
+}
+
+int dev_makedev(int major, int minor)
+{
+ return (minor&0xff)|((major&0xfff)<<8)|((minor&0xfff00)<<12);
+}
diff --git a/lib/lib.h b/lib/lib.h
index dac3b67f..c8cff6ef 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -200,6 +200,9 @@ void create_uuid(char *uuid);
char *show_uuid(char *uuid);
char *next_printf(char *s, char **start);
char *strnstr(char *line, char *str);
+int dev_minor(int dev);
+int dev_major(int dev);
+int dev_makedev(int major, int minor);
#define HR_SPACE 1 // Space between number and units
#define HR_B 2 // Use "B" for single byte units