add open_read_close() and similar stuff

This commit is contained in:
Denis Vlasenko
2006-10-14 02:23:43 +00:00
parent 88ca067690
commit ea62077b85
38 changed files with 228 additions and 234 deletions

View File

@@ -140,7 +140,7 @@ static int godaemon(void)
case 0:
pw = getpwnam(nobodystr);
if (pw == NULL)
bb_error_msg_and_die("Cannot find uid/gid of user '%s'", nobodystr);
bb_error_msg_and_die("cannot find uid/gid of user '%s'", nobodystr);
nobody = pw->pw_uid;
nogrp = pw->pw_gid;
writepid(nobody, nogrp);

View File

@@ -166,7 +166,7 @@ int ftp_receive(ftp_host_info_t *server, FILE *control_stream,
if (do_continue) {
fd_local = xopen(local_path, O_APPEND | O_WRONLY);
} else {
fd_local = xopen3(local_path, O_CREAT | O_TRUNC | O_WRONLY, 0777);
fd_local = xopen3(local_path, O_CREAT | O_TRUNC | O_WRONLY, 0666);
}
}

View File

@@ -1371,7 +1371,7 @@ inetd_main(int argc, char *argv[])
socklen_t plen = sizeof(peer);
if (getpeername(ctrl, (struct sockaddr *) &peer, &plen) < 0) {
bb_error_msg("could not getpeername");
bb_error_msg("cannot getpeername");
close(ctrl);
continue;
}

View File

@@ -126,7 +126,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
void *arg2)
{
char buf[8192];
char buf[8192];
struct sockaddr_nl nladdr;
struct iovec iov = { buf, sizeof(buf) };

View File

@@ -496,7 +496,6 @@ static void unix_do_one(int nr, const char *line)
static void do_info(const char *file, const char *name, void (*proc)(int, const char *))
{
char buffer[8192];
int lnr = 0;
FILE *procinfo;
@@ -505,12 +504,15 @@ static void do_info(const char *file, const char *name, void (*proc)(int, const
if (errno != ENOENT) {
perror(file);
} else {
bb_error_msg("no support for `%s' on this system", name);
bb_error_msg("no support for '%s' on this system", name);
}
} else {
do {
if (fgets(buffer, sizeof(buffer), procinfo))
char *buffer = xmalloc_fgets(procinfo);
if (buffer) {
(proc)(lnr++, buffer);
free(buffer);
}
} while (!feof(procinfo));
fclose(procinfo);
}

View File

@@ -417,7 +417,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp)
++nipaddr;
}
if (nipaddr == 0)
bb_error_msg_and_die ("Can't find any network interfaces");
bb_error_msg_and_die ("can't find any network interfaces");
(void)close(fd);
*ipaddrp = st_ifaddrlist;
@@ -472,7 +472,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
fclose(f);
if (device[0] == '\0')
bb_error_msg_and_die ("Can't find interface");
bb_error_msg_and_die ("can't find interface");
/* Get the interface address list */
n = ifaddrlist(&al);
@@ -482,7 +482,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
if (strcmp(device, al->device) == 0)
break;
if (i <= 0)
bb_error_msg_and_die("Can't find interface %s", device);
bb_error_msg_and_die("can't find interface %s", device);
setsin(from, al->addr);
}
@@ -1156,7 +1156,7 @@ traceroute_main(int argc, char *argv[])
if (strcmp(device, al->device) == 0)
break;
if (i <= 0) {
bb_error_msg_and_die("Can't find interface %s", device);
bb_error_msg_and_die("can't find interface %s", device);
}
}

View File

@@ -49,7 +49,7 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
}
if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) {
bb_perror_msg("Could not setsocketopt on raw socket");
bb_perror_msg("cannot setsocketopt on raw socket");
close(s);
return -1;
}

View File

@@ -39,16 +39,13 @@ unsigned long random_xid(void)
{
static int initialized;
if (!initialized) {
int fd;
unsigned long seed;
fd = open("/dev/urandom", 0);
if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) {
bb_info_msg("Could not load seed "
if (open_read_close("/dev/urandom", &seed, sizeof(seed)) < 0) {
bb_info_msg("Cannot load seed "
"from /dev/urandom: %s", strerror(errno));
seed = time(0);
}
if (fd >= 0) close(fd);
srand(seed);
initialized++;
}

View File

@@ -171,6 +171,6 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
}
}
bb_error_msg("Could not add option 0x%02x", code);
bb_error_msg("cannot add option 0x%02x", code);
return 0;
}

View File

@@ -36,7 +36,7 @@ static int signal_pipe[2];
static void signal_handler(int sig)
{
if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0)
bb_perror_msg("Could not send signal");
bb_perror_msg("cannot send signal");
}

View File

@@ -219,9 +219,7 @@ int wget_main(int argc, char **argv)
} else if (opt & WGET_OPT_CONTINUE) {
output_fd = open(fname_out, O_WRONLY);
if (output_fd >= 0) {
beg_range = lseek(output_fd, 0, SEEK_END);
if (beg_range == (off_t)-1)
bb_perror_msg_and_die("lseek");
beg_range = xlseek(output_fd, 0, SEEK_END);
}
/* File doesn't exist. We do not create file here yet.
We are not sure it exists on remove side */