aboutsummaryrefslogtreecommitdiff
path: root/lib/portability.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-03-10 09:18:22 -0700
committerRob Landley <rob@landley.net>2020-03-11 09:40:00 -0500
commite400e605471a5bc6571623b4446c41bfc9eb4942 (patch)
tree1dc99958bfac5e57865b211b3118515393107b90 /lib/portability.c
parente6b3ac496f8b72f089247e93e6892bb6fa094976 (diff)
downloadtoybox-e400e605471a5bc6571623b4446c41bfc9eb4942.tar.gz
Fix Mac build.
The recent re-enablement of the BLKGETSIZE64 code broke the Mac build. Use the equivalent <sys/disk.h> ioctl() pair instead.
Diffstat (limited to 'lib/portability.c')
-rw-r--r--lib/portability.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/portability.c b/lib/portability.c
index 28aaf824..145ac474 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -575,3 +575,23 @@ char *fs_type_name(struct statfs *statfs)
return s;
#endif
}
+
+#if defined(__APPLE__)
+#include <sys/disk.h>
+int get_block_device_size(int fd, unsigned long long* size)
+{
+ unsigned long block_size, block_count;
+
+ if (!ioctl(fd, DKIOCGETBLOCKSIZE, &block_size) &&
+ !ioctl(fd, DKIOCGETBLOCKCOUNT, &block_count)) {
+ *size = block_count * block_size;
+ return 1;
+ }
+ return 0;
+}
+#elif defined(__linux__)
+int get_block_device_size(int fd, unsigned long long* size)
+{
+ return (ioctl(fd, BLKGETSIZE64, &size) >= 0);
+}
+#endif