diff options
Diffstat (limited to 'usr.bin/mkuzip')
-rw-r--r-- | usr.bin/mkuzip/mkuzip.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/usr.bin/mkuzip/mkuzip.c b/usr.bin/mkuzip/mkuzip.c index 4cad2fb..02ebefa 100644 --- a/usr.bin/mkuzip/mkuzip.c +++ b/usr.bin/mkuzip/mkuzip.c @@ -11,6 +11,7 @@ */ #include <sys/types.h> +#include <sys/disk.h> #include <sys/endian.h> #include <sys/param.h> #include <sys/stat.h> @@ -122,10 +123,28 @@ int main(int argc, char **argv) signal(SIGXFSZ, exit); atexit(cleanup); - if (stat(iname, &sb) != 0) { - err(1, "stat(%s)", iname); + fdr = open(iname, O_RDONLY); + if (fdr < 0) { + err(1, "open(%s)", iname); /* Not reached */ } + if (fstat(fdr, &sb) != 0) { + err(1, "fstat(%s)", iname); + /* Not reached */ + } + if (S_ISCHR(sb.st_mode)) { + off_t ms; + + if (ioctl(fdr, DIOCGMEDIASIZE, &ms) < 0) { + err(1, "ioctl(DIOCGMEDIASIZE)"); + /* Not reached */ + } + sb.st_size = ms; + } else if (!S_ISREG(sb.st_mode)) { + fprintf(stderr, "%s: not a character device or regular file\n", + iname); + exit(1); + } hdr.nblocks = sb.st_size / hdr.blksz; if ((sb.st_size % hdr.blksz) != 0) { if (verbose != 0) @@ -135,11 +154,6 @@ int main(int argc, char **argv) } toc = safe_malloc((hdr.nblocks + 1) * sizeof(*toc)); - fdr = open(iname, O_RDONLY); - if (fdr < 0) { - err(1, "open(%s)", iname); - /* Not reached */ - } fdw = open(oname, O_WRONLY | O_TRUNC | O_CREAT, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (fdw < 0) { |