aboutsummaryrefslogtreecommitdiff
path: root/rpmunpack.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-12-22 01:48:07 +0000
committerMatt Kraai <kraai@debian.org>2000-12-22 01:48:07 +0000
commita9819b290848e0a760f3805d5937fa050235d707 (patch)
treeb8cb8d939032c0806d62161b01e5836cb808dc3f /rpmunpack.c
parente9f07fb6e83b75a50760599a5d31f494841eddf7 (diff)
downloadbusybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.gz
busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.bz2
busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.zip
Use busybox error handling functions wherever possible.
Diffstat (limited to 'rpmunpack.c')
-rw-r--r--rpmunpack.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/rpmunpack.c b/rpmunpack.c
index 2178a247d..249d223c0 100644
--- a/rpmunpack.c
+++ b/rpmunpack.c
@@ -40,10 +40,9 @@ static void myread(int num)
40 40
41 if ((err = read(infile, buffer, num)) != num) { 41 if ((err = read(infile, buffer, num)) != num) {
42 if (err < 0) 42 if (err < 0)
43 perror(progname); 43 perror_msg_and_die(progname);
44 else 44 else
45 fprintf(stderr, "Unexpected end of input file!\n"); 45 error_msg_and_die("Unexpected end of input file!\n");
46 exit(1);
47 } 46 }
48} 47}
49 48
@@ -68,10 +67,8 @@ int rpmunpack_main(int argc, char **argv)
68 /* Open input file */ 67 /* Open input file */
69 if (argc == 1) 68 if (argc == 1)
70 infile = STDIN_FILENO; 69 infile = STDIN_FILENO;
71 else if ((infile = open(argv[1], O_RDONLY)) < 0) { 70 else if ((infile = open(argv[1], O_RDONLY)) < 0)
72 perror(progname); 71 perror_msg_and_die("%s", argv[1]);
73 exit(1);
74 }
75 72
76 /* Read magic ID and output filename */ 73 /* Read magic ID and output filename */
77 myread(4); 74 myread(4);
@@ -87,10 +84,8 @@ int rpmunpack_main(int argc, char **argv)
87 strcat(buffer, ".cpio.gz"); 84 strcat(buffer, ".cpio.gz");
88 if (infile == STDIN_FILENO) 85 if (infile == STDIN_FILENO)
89 outfile = STDOUT_FILENO; 86 outfile = STDOUT_FILENO;
90 else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { 87 else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
91 perror(progname); 88 perror_msg_and_die("%s", buffer);
92 exit(1);
93 }
94 89
95 /* 90 /*
96 * Now search for the GZIP signature. This is rather awkward, but I don't 91 * Now search for the GZIP signature. This is rather awkward, but I don't
@@ -114,23 +109,15 @@ int rpmunpack_main(int argc, char **argv)
114 } 109 }
115 buffer[0] = GZ_MAGIC_1; 110 buffer[0] = GZ_MAGIC_1;
116 buffer[1] = GZ_MAGIC_2; 111 buffer[1] = GZ_MAGIC_2;
117 if (write(outfile, buffer, 2) < 0) { 112 if (write(outfile, buffer, 2) < 0)
118 perror(progname); 113 perror_msg_and_die("write");
119 exit(1);
120 }
121 114
122 /* Now simply copy the GZIP archive into the output file */ 115 /* Now simply copy the GZIP archive into the output file */
123 while ((len = read(infile, buffer, BUFSIZE)) > 0) { 116 while ((len = read(infile, buffer, BUFSIZE)) > 0) {
124 if (write(outfile, buffer, len) < 0) { 117 if (write(outfile, buffer, len) < 0)
125 perror(progname); 118 perror_msg_and_die("write");
126 exit(1);
127 }
128 }
129 if (len < 0) {
130 perror(progname);
131 exit(1);
132 } 119 }
133 close(outfile); 120 if (len < 0)
134 close(infile); 121 perror_msg_and_die("read");
135 exit(0); 122 return EXIT_SUCCESS;
136} 123}