Patch from Denis Vlasenko to add xstat() and use it.

This commit is contained in:
Rob Landley
2006-03-13 15:45:16 +00:00
parent 965030e35a
commit c5b1d4d6b1
12 changed files with 26 additions and 25 deletions

View File

@ -26,7 +26,7 @@ LIBBB-y:= \
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
trim.c u_signal_names.c vdprintf.c verror_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \

View File

@ -76,9 +76,7 @@ int run_parts(char **args, const unsigned char test_mode, char **env)
filename = concat_path_file(arg0, namelist[i]->d_name);
if (stat(filename, &st) < 0) {
bb_perror_msg_and_die("failed to stat component %s", filename);
}
xstat(filename, &st);
if (S_ISREG(st.st_mode) && !access(filename, X_OK)) {
if (test_mode) {
puts(filename);

11
libbb/xstat.c Normal file
View File

@ -0,0 +1,11 @@
/*
* xstat.c - a stat() which dies on failure with meaningful error message
*/
#include <unistd.h>
#include "libbb.h"
void xstat(const char *name, struct stat *stat_buf)
{
if (stat(name, stat_buf))
bb_perror_msg_and_die("Can't stat '%s'", name);
}