summaryrefslogtreecommitdiff
path: root/usr.bin/mkuzip
diff options
context:
space:
mode:
authorMax Khon <fjoe@FreeBSD.org>2007-03-06 17:04:15 +0000
committerMax Khon <fjoe@FreeBSD.org>2007-03-06 17:04:15 +0000
commit27d0a1a493460aa1e4f3e11c566fe2368f091ba4 (patch)
treed1594e39041ce4ea06466650e5ce73998f8fe9a3 /usr.bin/mkuzip
parentd73d2e1de2b921fb988964ff7813f943c2c73463 (diff)
downloadsrc-test-27d0a1a493460aa1e4f3e11c566fe2368f091ba4.tar.gz
src-test-27d0a1a493460aa1e4f3e11c566fe2368f091ba4.zip
Support character device as input file.
PR: 103500
Notes
Notes: svn path=/head/; revision=167272
Diffstat (limited to 'usr.bin/mkuzip')
-rw-r--r--usr.bin/mkuzip/mkuzip.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/usr.bin/mkuzip/mkuzip.c b/usr.bin/mkuzip/mkuzip.c
index 4cad2fb79fb43..02ebefa8094f6 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) {