diff options
author | fjoe <fjoe@FreeBSD.org> | 2007-03-06 17:04:15 +0000 |
---|---|---|
committer | fjoe <fjoe@FreeBSD.org> | 2007-03-06 17:04:15 +0000 |
commit | b67850e4380a4cfabfe3e85e61cc3e3b0376683c (patch) | |
tree | d1594e39041ce4ea06466650e5ce73998f8fe9a3 /usr.bin | |
parent | 6c577a7377fc199307cbe92722393ad3b087786b (diff) | |
download | FreeBSD-src-b67850e4380a4cfabfe3e85e61cc3e3b0376683c.zip FreeBSD-src-b67850e4380a4cfabfe3e85e61cc3e3b0376683c.tar.gz |
Support character device as input file.
PR: 103500
Diffstat (limited to 'usr.bin')
-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) { |