aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-03-13 15:45:16 +0000
committerRob Landley <rob@landley.net>2006-03-13 15:45:16 +0000
commitc5b1d4d6b14f22b5e2f7ae42eb01bf2746b8001c (patch)
treee44405a7e5212758d20a9595cbb0a82609d4a347
parent965030e35aed6a8b9c09267baba4c2342d5223d6 (diff)
downloadbusybox-w32-c5b1d4d6b14f22b5e2f7ae42eb01bf2746b8001c.tar.gz
busybox-w32-c5b1d4d6b14f22b5e2f7ae42eb01bf2746b8001c.tar.bz2
busybox-w32-c5b1d4d6b14f22b5e2f7ae42eb01bf2746b8001c.zip
Patch from Denis Vlasenko to add xstat() and use it.
-rw-r--r--archival/gunzip.c4
-rw-r--r--coreutils/date.c3
-rw-r--r--coreutils/ls.c2
-rw-r--r--coreutils/uuencode.c4
-rw-r--r--debianutils/start_stop_daemon.c4
-rw-r--r--findutils/find.c9
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/run_parts.c4
-rw-r--r--libbb/xstat.c11
-rw-r--r--miscutils/hdparm.c3
-rw-r--r--util-linux/swaponoff.c3
12 files changed, 26 insertions, 25 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 4fb77044a..7b939290b 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -103,9 +103,7 @@ int gunzip_main(int argc, char **argv)
103 src_fd = bb_xopen(old_path, O_RDONLY); 103 src_fd = bb_xopen(old_path, O_RDONLY);
104 104
105 /* Get the time stamp on the input file. */ 105 /* Get the time stamp on the input file. */
106 if (stat(old_path, &stat_buf) < 0) { 106 xstat(old_path, &stat_buf);
107 bb_error_msg_and_die("Couldn't stat file %s", old_path);
108 }
109 } 107 }
110 108
111 /* Check that the input is sane. */ 109 /* Check that the input is sane. */
diff --git a/coreutils/date.c b/coreutils/date.c
index c111b6161..401d2ffb7 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -165,8 +165,7 @@ int date_main(int argc, char **argv)
165 165
166 if(filename) { 166 if(filename) {
167 struct stat statbuf; 167 struct stat statbuf;
168 if(stat(filename,&statbuf)) 168 xstat(filename,&statbuf);
169 bb_perror_msg_and_die("File '%s' not found.", filename);
170 tm=statbuf.st_mtime; 169 tm=statbuf.st_mtime;
171 } else time(&tm); 170 } else time(&tm);
172 memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); 171 memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
diff --git a/coreutils/ls.c b/coreutils/ls.c
index a575a02cb..964e7c964 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -230,7 +230,7 @@ static struct dnode *my_stat(char *fullname, char *name)
230 rc = getfilecon(fullname,&sid); 230 rc = getfilecon(fullname,&sid);
231 } 231 }
232#endif 232#endif
233 rc = stat(fullname, &dstat); 233 rc = stat(fullname, &dstat);
234 if(rc) { 234 if(rc) {
235 bb_perror_msg("%s", fullname); 235 bb_perror_msg("%s", fullname);
236 status = EXIT_FAILURE; 236 status = EXIT_FAILURE;
diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c
index d45565c6e..6a82a4b43 100644
--- a/coreutils/uuencode.c
+++ b/coreutils/uuencode.c
@@ -105,9 +105,7 @@ int uuencode_main(int argc, char **argv)
105 switch (argc - optind) { 105 switch (argc - optind) {
106 case 2: 106 case 2:
107 src_stream = bb_xfopen(argv[optind], "r"); 107 src_stream = bb_xfopen(argv[optind], "r");
108 if (stat(argv[optind], &stat_buf) < 0) { 108 xstat(argv[optind], &stat_buf);
109 bb_perror_msg_and_die("stat");
110 }
111 mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); 109 mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
112 if (src_stream == stdout) { 110 if (src_stream == stdout) {
113 puts("NULL"); 111 puts("NULL");
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index aa1b3c7a0..1dd2231dc 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -53,8 +53,8 @@ pid_is_exec(pid_t pid, const char *name)
53 char buf[32]; 53 char buf[32];
54 struct stat sb, exec_stat; 54 struct stat sb, exec_stat;
55 55
56 if (name && stat(name, &exec_stat)) 56 if (name)
57 bb_perror_msg_and_die("stat %s", name); 57 xstat(name, &exec_stat);
58 58
59 sprintf(buf, "/proc/%d/exe", pid); 59 sprintf(buf, "/proc/%d/exe", pid);
60 if (stat(buf, &sb) != 0) 60 if (stat(buf, &sb) != 0)
diff --git a/findutils/find.c b/findutils/find.c
index 0f2f2144c..c6aaf7aab 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -274,15 +274,13 @@ int find_main(int argc, char **argv)
274 xdev_dev = xmalloc ( xdev_count * sizeof( dev_t )); 274 xdev_dev = xmalloc ( xdev_count * sizeof( dev_t ));
275 275
276 if ( firstopt == 1 ) { 276 if ( firstopt == 1 ) {
277 if ( stat ( ".", &stbuf ) < 0 ) 277 xstat ( ".", &stbuf );
278 bb_error_msg_and_die("could not stat '.'" );
279 xdev_dev [0] = stbuf. st_dev; 278 xdev_dev [0] = stbuf. st_dev;
280 } 279 }
281 else { 280 else {
282 281
283 for (i = 1; i < firstopt; i++) { 282 for (i = 1; i < firstopt; i++) {
284 if ( stat ( argv [i], &stbuf ) < 0 ) 283 xstat ( argv [i], &stbuf );
285 bb_error_msg_and_die("could not stat '%s'", argv [i] );
286 xdev_dev [i-1] = stbuf. st_dev; 284 xdev_dev [i-1] = stbuf. st_dev;
287 } 285 }
288 } 286 }
@@ -292,8 +290,7 @@ int find_main(int argc, char **argv)
292 struct stat stat_newer; 290 struct stat stat_newer;
293 if (++i == argc) 291 if (++i == argc)
294 bb_error_msg_and_die(msg_req_arg, "-newer"); 292 bb_error_msg_and_die(msg_req_arg, "-newer");
295 if (stat (argv[i], &stat_newer) != 0) 293 xstat (argv[i], &stat_newer);
296 bb_error_msg_and_die("file %s not found", argv[i]);
297 newer_mtime = stat_newer.st_mtime; 294 newer_mtime = stat_newer.st_mtime;
298#endif 295#endif
299#ifdef CONFIG_FEATURE_FIND_INUM 296#ifdef CONFIG_FEATURE_FIND_INUM
diff --git a/include/libbb.h b/include/libbb.h
index bc3fa5990..0ec332b30 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -122,6 +122,8 @@ extern FILE *bb_xfopen(const char *path, const char *mode);
122extern int bb_fclose_nonstdin(FILE *f); 122extern int bb_fclose_nonstdin(FILE *f);
123extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; 123extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
124 124
125extern void xstat(const char *filename, struct stat *buf);
126
125#define BB_GETOPT_ERROR 0x80000000UL 127#define BB_GETOPT_ERROR 0x80000000UL
126extern const char *bb_opt_complementally; 128extern const char *bb_opt_complementally;
127extern const struct option *bb_applet_long_options; 129extern const struct option *bb_applet_long_options;
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index b4ee3f501..159957aa4 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -26,7 +26,7 @@ LIBBB-y:= \
26 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \ 26 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
27 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \ 27 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
28 trim.c u_signal_names.c vdprintf.c verror_msg.c \ 28 trim.c u_signal_names.c vdprintf.c verror_msg.c \
29 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \ 29 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
30 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ 30 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
31 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ 31 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
32 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ 32 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
diff --git a/libbb/run_parts.c b/libbb/run_parts.c
index 7f5fe459b..864460d0d 100644
--- a/libbb/run_parts.c
+++ b/libbb/run_parts.c
@@ -76,9 +76,7 @@ int run_parts(char **args, const unsigned char test_mode, char **env)
76 76
77 filename = concat_path_file(arg0, namelist[i]->d_name); 77 filename = concat_path_file(arg0, namelist[i]->d_name);
78 78
79 if (stat(filename, &st) < 0) { 79 xstat(filename, &st);
80 bb_perror_msg_and_die("failed to stat component %s", filename);
81 }
82 if (S_ISREG(st.st_mode) && !access(filename, X_OK)) { 80 if (S_ISREG(st.st_mode) && !access(filename, X_OK)) {
83 if (test_mode) { 81 if (test_mode) {
84 puts(filename); 82 puts(filename);
diff --git a/libbb/xstat.c b/libbb/xstat.c
new file mode 100644
index 000000000..ca6686403
--- /dev/null
+++ b/libbb/xstat.c
@@ -0,0 +1,11 @@
1/*
2 * xstat.c - a stat() which dies on failure with meaningful error message
3 */
4#include <unistd.h>
5#include "libbb.h"
6
7void xstat(const char *name, struct stat *stat_buf)
8{
9 if (stat(name, stat_buf))
10 bb_perror_msg_and_die("Can't stat '%s'", name);
11}
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index bd3065d7e..ca60dcf37 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -1871,8 +1871,7 @@ static void process_dev (char *devname)
1871#ifndef HDIO_DRIVE_CMD 1871#ifndef HDIO_DRIVE_CMD
1872 int force_operation = 0; 1872 int force_operation = 0;
1873#endif 1873#endif
1874 if (stat(devname,&stat_buf)) 1874 xstat(devname,&stat_buf);
1875 bb_perror_msg_and_die(devname);
1876 1875
1877 switch(major(stat_buf.st_rdev)) 1876 switch(major(stat_buf.st_rdev))
1878 { 1877 {
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index ce55a132a..473325d0c 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -23,8 +23,7 @@ static int swap_enable_disable(const char *device)
23 int status; 23 int status;
24 struct stat st; 24 struct stat st;
25 25
26 if (stat(device, &st) < 0) 26 xstat(device, &st);
27 bb_perror_msg_and_die("cannot stat %s", device);
28 27
29 /* test for holes */ 28 /* test for holes */
30 if (S_ISREG(st.st_mode)) 29 if (S_ISREG(st.st_mode))