(saved in variable long_name) that conatains the real filename */
const unsigned int long_offset = atoi(&ar.formatted.name[1]);
if (long_offset >= ar_long_name_size) {
- bb_error_msg_and_die("Cant resolve long filename");
+ bb_error_msg_and_die("can't resolve long filename");
}
typed->name = xstrdup(ar_long_names + long_offset);
}
int pid;
if (pipe(fd_pipe) != 0) {
- bb_perror_msg_and_die("Can't create pipe");
+ bb_perror_msg_and_die("can't create pipe");
}
pid = fork();
if (pid == -1) {
- bb_perror_msg_and_die("Fork failed");
+ bb_perror_msg_and_die("fork failed");
}
if (pid == 0) {
/* child process */
- close(fd_pipe[0]); /* We don't wan't to read from the parent */
- // FIXME: error check?
- transformer(src_fd, fd_pipe[1]);
- close(fd_pipe[1]); /* Send EOF */
+ close(fd_pipe[0]); /* We don't wan't to read from the parent */
+ // FIXME: error check?
+ transformer(src_fd, fd_pipe[1]);
+ close(fd_pipe[1]); /* Send EOF */
close(src_fd);
- exit(0);
- /* notreached */
+ exit(0);
+ /* notreached */
}
/* parent process */
if (n == 0 && vfork_exec_errno != 0) {
errno = vfork_exec_errno;
- bb_perror_msg_and_die("Could not exec %s", zip_exec);
+ bb_perror_msg_and_die("cannot exec %s", zip_exec);
} else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
continue; /* try it again */
break;
* driver routine. Both drivers use the contents of stb1 and stb2.
*/
if (argc < 2) {
- bb_error_msg("Missing filename");
+ bb_error_msg("missing filename");
bb_show_usage();
}
if (strcmp(argv[0], "-") == 0) {
} else
xstat(argv[1], &stb2);
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
- bb_error_msg_and_die("Can't compare - to a directory");
+ bb_error_msg_and_die("can't compare - to a directory");
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
#if ENABLE_FEATURE_DIFF_DIR
diffdir(argv[0], argv[1]);
#else
- bb_error_msg_and_die("Directory comparison not supported");
+ bb_error_msg_and_die("directory comparison not supported");
#endif
} else {
if (S_ISDIR(stb1.st_mode)) {
#endif
fd = open((char *) fn, O_RDONLY); // try read-only
if (fd < 0) {
- psbs("\"%s\" %s", fn, "could not open file");
+ psbs("\"%s\" %s", fn, "cannot open file");
goto fi0;
}
#ifdef CONFIG_FEATURE_VI_READONLY
if (cnt < 0) {
cnt = -1;
p = text_hole_delete(p, p + size - 1); // un-do buffer insert
- psbs("could not read file \"%s\"", fn);
+ psbs("cannot read file \"%s\"", fn);
} else if (cnt < size) {
// There was a partial read, shrink unused space text[]
p = text_hole_delete(p + cnt, p + (size - cnt) - 1); // un-do buffer insert
- psbs("could not read all of file \"%s\"", fn);
+ psbs("cannot read all of file \"%s\"", fn);
}
if (cnt >= size)
file_modified++;
extern DIR *warn_opendir(const char *path);
extern DIR *xopendir(const char *path);
-extern int remove_file(const char *path, int flags);
-extern int copy_file(const char *source, const char *dest, int flags);
extern ssize_t safe_read(int fd, void *buf, size_t count);
-extern ssize_t full_read(int fd, void *buf, size_t len);
+extern ssize_t full_read(int fd, void *buf, size_t count);
+extern void xread(int fd, void *buf, size_t count);
+extern unsigned char xread_char(int fd);
+extern char *reads(int fd, char *buf, size_t count);
+ssize_t read_close(int fd, void *buf, size_t count);
+ssize_t open_read_close(const char *filename, void *buf, size_t count);
+void *xmalloc_open_read_close(const char *filename, size_t *sizep);
+
extern ssize_t safe_write(int fd, const void *buf, size_t count);
-extern ssize_t full_write(int fd, const void *buf, size_t len);
+extern ssize_t full_write(int fd, const void *buf, size_t count);
+extern void xwrite(int fd, void *buf, size_t count);
+
+extern int remove_file(const char *path, int flags);
+extern int copy_file(const char *source, const char *dest, int flags);
+
extern int recursive_action(const char *fileName, int recurse,
int followLinks, int depthFirst,
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
extern void xsetenv(const char *key, const char *value);
extern int xopen(const char *pathname, int flags);
extern int xopen3(const char *pathname, int flags, int mode);
-extern void xread(int fd, void *buf, size_t count);
-extern unsigned char xread_char(int fd);
-extern void xlseek(int fd, off_t offset, int whence);
-extern void xwrite(int fd, void *buf, size_t count);
+extern off_t xlseek(int fd, off_t offset, int whence);
extern const char bb_uuenc_tbl_base64[];
extern const char bb_uuenc_tbl_std[];
execv(cmdpath, cmd);
/* We're still here? Some error happened. */
- message(LOG | CONSOLE, "Bummer, could not run '%s': %m", cmdpath);
+ message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath);
_exit(-1);
}
sigprocmask(SIG_SETMASK, &omask, NULL);
compare_string_array.o concat_path_file.o copy_file.o copyfd.o \
crc32.o create_icmp_socket.o create_icmp6_socket.o \
device_open.o dump.o error_msg.o error_msg_and_die.o \
- find_pid_by_name.o find_root_device.o fgets_str.o full_read.o \
+ find_pid_by_name.o find_root_device.o fgets_str.o \
full_write.o get_last_path_component.o get_line_from_file.o \
herror_msg.o herror_msg_and_die.o \
human_readable.o inet_common.o inode_hash.o isdirectory.o \
perror_msg_and_die.o get_console.o \
process_escape_sequence.o procps.o \
recursive_action.o remove_file.o \
- restricted_shell.o run_parts.o run_shell.o safe_read.o safe_write.o \
+ restricted_shell.o run_parts.o run_shell.o read.o safe_write.o \
safe_strncpy.o setup_environment.o sha1.o simplify_path.o \
trim.o u_signal_names.o vdprintf.o verror_msg.o \
vherror_msg.o vperror_msg.o wfopen.o xconnect.o xgetcwd.o \
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include "libbb.h"
-
-/*
- * Read all of the supplied buffer from a file.
- * This does multiple reads as necessary.
- * Returns the amount read, or -1 on an error.
- * A short read is returned on an end of file.
- */
-ssize_t full_read(int fd, void *buf, size_t len)
-{
- ssize_t cc;
- ssize_t total;
-
- total = 0;
-
- while (len) {
- cc = safe_read(fd, buf, len);
-
- if (cc < 0)
- return cc; /* read() returns -1 on failure. */
-
- if (cc == 0)
- break;
-
- buf = ((char *)buf) + cc;
- total += cc;
- len -= cc;
- }
-
- return total;
-}
static int read_to_buf(const char *filename, void *buf)
{
- int fd;
ssize_t ret;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return -1;
- ret = read(fd, buf, PROCPS_BUFSIZE-1);
- ((char *)buf)[ret > 0 ? ret : 0] = 0;
- close(fd);
+ ret = open_read_close(filename, buf, PROCPS_BUFSIZE-1);
+ ((char *)buf)[ret > 0 ? ret : 0] = '\0';
return ret;
}
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+
+#include "libbb.h"
+
+ssize_t safe_read(int fd, void *buf, size_t count)
+{
+ ssize_t n;
+
+ do {
+ n = read(fd, buf, count);
+ } while (n < 0 && errno == EINTR);
+
+ return n;
+}
+
+/*
+ * Read all of the supplied buffer from a file.
+ * This does multiple reads as necessary.
+ * Returns the amount read, or -1 on an error.
+ * A short read is returned on an end of file.
+ */
+ssize_t full_read(int fd, void *buf, size_t len)
+{
+ ssize_t cc;
+ ssize_t total;
+
+ total = 0;
+
+ while (len) {
+ cc = safe_read(fd, buf, len);
+
+ if (cc < 0)
+ return cc; /* read() returns -1 on failure. */
+
+ if (cc == 0)
+ break;
+
+ buf = ((char *)buf) + cc;
+ total += cc;
+ len -= cc;
+ }
+
+ return total;
+}
+
+// Die with an error message if we can't read the entire buffer.
+void xread(int fd, void *buf, size_t count)
+{
+ if (count) {
+ ssize_t size = full_read(fd, buf, count);
+ if (size != count)
+ bb_error_msg_and_die("short read");
+ }
+}
+
+// Die with an error message if we can't read one character.
+unsigned char xread_char(int fd)
+{
+ char tmp;
+
+ xread(fd, &tmp, 1);
+
+ return tmp;
+}
+
+// Read one line a-la fgets. Works only on seekable streams
+char *reads(int fd, char *buffer, size_t size)
+{
+ char *p;
+
+ if (size < 2)
+ return NULL;
+ size = full_read(fd, buffer, size-1);
+ if ((ssize_t)size <= 0)
+ return NULL;
+
+ buffer[size] = '\0';
+ p = strchr(buffer, '\n');
+ if (p) {
+ off_t offset;
+ *p++ = '\0';
+ offset = (p-buffer) - size;
+ // set fd position the right after the \n
+ if (offset && lseek(fd, offset, SEEK_CUR) == (off_t)-1)
+ return NULL;
+ }
+ return buffer;
+}
+
+ssize_t read_close(int fd, void *buf, size_t size)
+{
+ int e;
+ size = full_read(fd, buf, size);
+ e = errno;
+ close(fd);
+ errno = e;
+ return size;
+}
+
+ssize_t open_read_close(const char *filename, void *buf, size_t size)
+{
+ int fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return fd;
+ return read_close(fd, buf, size);
+}
+
+void *xmalloc_open_read_close(const char *filename, size_t *sizep)
+{
+ char *buf;
+ size_t size = sizep ? *sizep : INT_MAX;
+ int fd = xopen(filename, O_RDONLY);
+ off_t len = xlseek(fd, 0, SEEK_END);
+ xlseek(fd, 0, SEEK_SET);
+
+ if (len > size)
+ bb_error_msg_and_die("file '%s' is too big", filename);
+ size = len;
+ buf = xmalloc(size+1);
+ size = read_close(fd, buf, size);
+ if ((ssize_t)size < 0)
+ bb_perror_msg_and_die("'%s'", filename);
+ buf[size] = '\0';
+ if (sizep) *sizep = size;
+ return buf;
+}
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include "libbb.h"
-
-
-
-ssize_t safe_read(int fd, void *buf, size_t count)
-{
- ssize_t n;
-
- do {
- n = read(fd, buf, count);
- } while (n < 0 && errno == EINTR);
-
- return n;
-}
if (ENABLE_DEBUG && (flags & O_CREAT))
bb_error_msg_and_die("xopen() with O_CREAT");
- return xopen3(pathname, flags, 0777);
+ return xopen3(pathname, flags, 0666);
}
// Die if we can't open a new file and return an fd.
return ret;
}
-// Die with an error message if we can't read the entire buffer.
-void xread(int fd, void *buf, size_t count)
-{
- if (count) {
- ssize_t size = full_read(fd, buf, count);
- if (size != count)
- bb_error_msg_and_die("short read");
- }
-}
-
// Die with an error message if we can't write the entire buffer.
void xwrite(int fd, void *buf, size_t count)
{
}
// Die with an error message if we can't lseek to the right spot.
-void xlseek(int fd, off_t offset, int whence)
+off_t xlseek(int fd, off_t offset, int whence)
{
- if (offset != lseek(fd, offset, whence))
- bb_error_msg_and_die("lseek");
-}
-
-// Die with an error message if we can't read one character.
-unsigned char xread_char(int fd)
-{
- char tmp;
-
- xread(fd, &tmp, 1);
-
- return tmp;
+ off_t off = lseek(fd, offset, whence);
+ if (off == (off_t)-1)
+ bb_perror_msg_and_die("lseek");
+ return off;
}
// Die with supplied error message if this FILE * has ferror set.
// If we can read from the current location, it's bigger.
- if (lseek(fd, pos, 0)>=0 && safe_read(fd, &temp, 1)==1) {
+ if (lseek(fd, pos, SEEK_SET)>=0 && safe_read(fd, &temp, 1)==1) {
if (bottom == top) bottom = top = (top+1) * 2;
else bottom = pos;
fclose(passwd);
}
} else {
- bb_error_msg("Can't find '%s' in '%s'", login, filename);
+ bb_error_msg("can't find '%s' in '%s'", login, filename);
}
free(buffer);
}
close(logfd);
#if ENABLE_DEBUG_CROND_OPTION
} else {
- bb_perror_msg("Can't open log file");
+ bb_perror_msg("can't open log file");
#endif
}
}
line->cl_MailFlag = 1;
fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", user,
line->cl_Shell);
- line->cl_MailPos = lseek(mailFd, 0, 1);
+ line->cl_MailPos = lseek(mailFd, 0, SEEK_CUR);
} else {
crondlog("\024unable to create mail file user %s file %s, output to /dev/null\n", user, mailFile);
}
}
EditFile(caller, tmp);
remove(tmp);
- lseek(fd, 0L, 0);
+ lseek(fd, 0L, SEEK_SET);
repFd = fd;
}
option = REPLACE;
sprintf(full_name_inc, "%s%d", full_name, i);
rdev = (major << 8) + minor + (i * increment - start);
if (mknod(full_name_inc, mode, rdev) == -1) {
- bb_perror_msg("line %d: could not create node %s", linenum, full_name_inc);
+ bb_perror_msg("line %d: cannot create node %s", linenum, full_name_inc);
ret = EXIT_FAILURE;
}
else if (chown(full_name_inc, uid, gid) == -1) {
} else {
rdev = (major << 8) + minor;
if (mknod(full_name, mode, rdev) == -1) {
- bb_perror_msg("line %d: could not create node %s", linenum, full_name);
+ bb_perror_msg("line %d: cannot create node %s", linenum, full_name);
ret = EXIT_FAILURE;
}
else if (chown(full_name, uid, gid) == -1) {
static int readfile_z(char *buf, int sz, const char* fname)
{
- int fd;
- fd = xopen(fname, O_RDONLY);
- // We are not checking for short reads (valid only because
- // we are reading /proc files)
- sz = read(fd, buf, sz-1);
- close(fd);
+ sz = open_read_close(fname, buf, sz-1);
if (sz < 0) {
buf[0] = '\0';
return 1;
s_stat *last = NULL;
s_stat *s;
char *cur, *prev;
- int fd;
if (argc != 2)
bb_show_usage();
- fd = xopen("/proc/version", O_RDONLY);
- if (read(fd, buf, sizeof(buf)) > 0)
- is26 = (strstr(buf, "Linux version 2.4.")==NULL);
- close(fd);
+ if (open_read_close("/proc/version", buf, sizeof(buf)) > 0)
+ is26 = (strstr(buf, " 2.4.")==NULL);
// Can use argv[1] directly, but this will mess up
// parameters as seen by e.g. ps. Making a copy...
m_addr = create_module(m_name, m_size);
if (m_addr == -1) switch (errno) {
case EEXIST:
- bb_error_msg("A module named %s already exists", m_name);
+ bb_error_msg("a module named %s already exists", m_name);
goto out;
case ENOMEM:
- bb_error_msg("Can't allocate kernel memory for module; needed %lu bytes",
+ bb_error_msg("can't allocate kernel memory for module; needed %lu bytes",
m_size);
goto out;
default:
check_tainted();
#if defined(CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT)
{
- char line[4096];
-
- while (fgets(line, sizeof(line), file)) {
+ char *line;
+ while ((line = xmalloc_fgets(file)) != NULL) {
char *tok;
tok = strtok(line, " \t");
tok = "";
printf(" %s", tok);
}
- printf("\n");
+ puts("");
+ free(line);
}
fclose(file);
}
return 1;
}
-/* Jump through hoops to simulate how fgets() grabs just one line at a
- * time... Don't use any stdio since modprobe gets called from a kernel
- * thread and stdio junk can overflow the limited stack...
- */
-static char *reads ( int fd, char *buffer, size_t len )
-{
- int n = read ( fd, buffer, len );
-
- if ( n > 0 ) {
- char *p;
-
- buffer [len-1] = 0;
- p = strchr ( buffer, '\n' );
-
- if ( p ) {
- off_t offset;
-
- offset = lseek ( fd, 0L, SEEK_CUR ); // Get the current file descriptor offset
- lseek ( fd, offset-n + (p-buffer) + 1, SEEK_SET ); // Set the file descriptor offset to right after the \n
-
- p[1] = 0;
- }
- return buffer;
- }
-
- else
- return 0;
-}
-
/*
* This function appends an option to a list
*/
depend = build_dep ( );
if ( !depend )
- bb_error_msg_and_die ( "could not parse modules.dep" );
+ bb_error_msg_and_die ( "cannot parse modules.dep" );
if (remove_opt) {
do {
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);
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);
}
}
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;
}
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) };
static void do_info(const char *file, const char *name, void (*proc)(int, const char *))
{
- char buffer[8192];
int lnr = 0;
FILE *procinfo;
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);
}
++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;
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);
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);
}
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);
}
}
}
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;
}
{
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++;
}
}
}
- bb_error_msg("Could not add option 0x%02x", code);
+ bb_error_msg("cannot add option 0x%02x", code);
return 0;
}
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");
}
} 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 */
if(curr->pid > 0 && curr->pid != mypid) {
if (kill(curr->pid, sig) != 0) {
bb_perror_msg(
- "Could not kill pid '%d'", curr->pid);
+ "cannot kill pid '%d'", curr->pid);
success = 0;
}
}
if(!fuser_file_to_dev_inode(
argv[fni[i]], &dev, &inode)) {
if (ENABLE_FEATURE_CLEAN_UP) free(inodes);
- bb_perror_msg_and_die("Could not open '%s'", argv[fni[i]]);
+ bb_perror_msg_and_die("cannot open '%s'", argv[fni[i]]);
}
fuser_add_inode(inodes, dev, inode);
}
memcpy(top + n, p, sizeof(procps_status_t));
}
if (ntop == 0) {
- bb_error_msg_and_die("Can't find process info in /proc");
+ bb_error_msg_and_die("can't find process info in /proc");
}
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
if (!prev_hist_count) {
case IOWRITE | IOCAT:
if ((u = open(cp, 1)) >= 0) {
- lseek(u, (long) 0, 2);
+ lseek(u, (long) 0, SEEK_END);
break;
}
case IOWRITE:
/* This line appears to be active when running scripts from command line */
if ((isatty(e.iop->argp->afile) == 0)
&& (e.iop == &iostack[0]
- || lseek(e.iop->argp->afile, 0L, 1) != -1)) {
+ || lseek(e.iop->argp->afile, 0L, SEEK_CUR) != -1)) {
if (++bufid == AFID_NOBUF) /* counter rollover check, AFID_NOBUF = 11111111 */
bufid = AFID_ID; /* AFID_ID = 0 */
if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) {
if (i)
- lseek(ap->afile, ap->afpos, 0);
+ lseek(ap->afile, ap->afpos, SEEK_SET);
i = safe_read(ap->afile, bp->buf, sizeof(bp->buf));
if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) {
if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 )
- bb_perror_msg_and_die ( "Could not access RTC" );
+ bb_perror_msg_and_die ( "cannot access RTC" );
}
memset ( &tm, 0, sizeof( struct tm ));
if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 )
- bb_perror_msg_and_die ( "Could not read time from RTC" );
+ bb_perror_msg_and_die ( "cannot read time from RTC" );
tm.tm_isdst = -1; /* not known */
close ( rtc );
if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) {
if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 )
- bb_perror_msg_and_die ( "Could not access RTC" );
+ bb_perror_msg_and_die ( "cannot access RTC" );
}
tm = *( utc ? gmtime ( &t ) : localtime ( &t ));
tm.tm_isdst = 0;
if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 )
- bb_perror_msg_and_die ( "Could not set the RTC time" );
+ bb_perror_msg_and_die ( "cannot set the RTC time" );
close ( rtc );
}
if (!delete) {
strcat(path, "/dev");
- fd = open(path, O_RDONLY);
- len = read(fd, temp + 1, 64);
+ len = open_read_close(path, temp + 1, 64);
*temp++ = 0;
- close(fd);
if (len < 1) return;
}
int readprofile_main(int argc, char **argv)
{
FILE *map;
- int proFd;
const char *mapFile, *proFile, *mult=0;
- unsigned long len=0, indx=1;
+ unsigned long indx=1;
+ size_t len;
uint64_t add0=0;
unsigned int step;
unsigned int *buf, total, fn_len;
/*
* Use an fd for the profiling buffer, to skip stdio overhead
*/
-
- proFd = xopen(proFile,O_RDONLY);
-
- if (((int)(len=lseek(proFd,0,SEEK_END)) < 0)
- || (lseek(proFd,0,SEEK_SET) < 0))
- bb_perror_msg_and_die(proFile);
-
- buf = xmalloc(len);
-
- if (read(proFd,buf,len) != len)
- bb_perror_msg_and_die(proFile);
-
- close(proFd);
-
+ len = INT_MAX;
+ buf = xmalloc_open_read_close(proFile, &len);
if (!optNative) {
int entries = len/sizeof(*buf);
int big = 0,small = 0,i;
small++;
}
if (big > small) {
- bb_error_msg("Assuming reversed byte order. "
- "Use -n to force native byte order.");
+ bb_error_msg("assuming reversed byte order, "
+ "use -n to force native byte order");
for (p = buf; p < buf+entries; p++)
for (i = 0; i < sizeof(*buf)/2; i++) {
unsigned char *b = (unsigned char *) p;