Applications evaluate errno in case of a -1 return value. Examples
within util-linux are fsck.cramfs and mkfs.minix. Set errno more often
to offer reasonable error codes to the application and user.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/ioctl.h>
+#include <errno.h>
#include <unistd.h>
#include <stdint.h>
uintmax_t high, low = 0;
for (high = 1024; blkdev_valid_offset (fd, high); ) {
- if (high == UINTMAX_MAX)
+ if (high == UINTMAX_MAX) {
+ errno = EFBIG;
return -1;
+ }
low = high;
*bytes = st.st_size;
return 0;
}
- if (!S_ISBLK(st.st_mode))
+ if (!S_ISBLK(st.st_mode)) {
+ errno = ENOTBLK;
return -1;
+ }
}
*bytes = blkdev_find_size(fd);