- patch from Denis Vlasenko to add and use bb_xopen3()
This commit is contained in:
parent
4f3d2deaa4
commit
c2cb0f32b4
@ -1228,7 +1228,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
inFileNum = STDIN_FILENO;
|
inFileNum = STDIN_FILENO;
|
||||||
outFileNum = STDOUT_FILENO;
|
outFileNum = STDOUT_FILENO;
|
||||||
} else {
|
} else {
|
||||||
inFileNum = bb_xopen(argv[i], O_RDONLY);
|
inFileNum = bb_xopen3(argv[i], O_RDONLY, 0);
|
||||||
if (fstat(inFileNum, &statBuf) < 0)
|
if (fstat(inFileNum, &statBuf) < 0)
|
||||||
bb_perror_msg_and_die("%s", argv[i]);
|
bb_perror_msg_and_die("%s", argv[i]);
|
||||||
time_stamp = statBuf.st_ctime;
|
time_stamp = statBuf.st_ctime;
|
||||||
|
@ -5,20 +5,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2000,2001 Matt Kraai
|
* Copyright (C) 2000,2001 Matt Kraai
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -119,9 +106,7 @@ int dd_main(int argc, char **argv)
|
|||||||
oflag |= O_TRUNC;
|
oflag |= O_TRUNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ofd = open(outfile, oflag, 0666)) < 0) {
|
ofd = bb_xopen3(outfile, oflag, 0666);
|
||||||
bb_perror_msg_and_die("%s", outfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seek && trunc_flag) {
|
if (seek && trunc_flag) {
|
||||||
if (ftruncate(ofd, seek * bs) < 0) {
|
if (ftruncate(ofd, seek * bs) < 0) {
|
||||||
|
@ -440,6 +440,7 @@ extern struct spwd *pwd_to_spwd(const struct passwd *pw);
|
|||||||
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
|
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
|
||||||
|
|
||||||
extern int bb_xopen(const char *pathname, int flags);
|
extern int bb_xopen(const char *pathname, int flags);
|
||||||
|
extern int bb_xopen3(const char *pathname, int flags, int mode);
|
||||||
extern ssize_t bb_xread(int fd, void *buf, size_t count);
|
extern ssize_t bb_xread(int fd, void *buf, size_t count);
|
||||||
extern void bb_xread_all(int fd, void *buf, size_t count);
|
extern void bb_xread_all(int fd, void *buf, size_t count);
|
||||||
extern unsigned char bb_xread_char(int fd);
|
extern unsigned char bb_xread_char(int fd);
|
||||||
|
@ -68,7 +68,7 @@ $(LIBBB_MOBJ0):$(LIBBB_MSRC0)
|
|||||||
|
|
||||||
LIBBB_MSRC1:=$(srcdir)/xfuncs.c
|
LIBBB_MSRC1:=$(srcdir)/xfuncs.c
|
||||||
LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \
|
LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \
|
||||||
xfopen.o xopen.o xread.o xread_all.o xread_char.o \
|
xfopen.o xopen.o xopen3.o xread.o xread_all.o xread_char.o \
|
||||||
xferror.o xferror_stdout.o xfflush_stdout.o strlen.o
|
xferror.o xferror_stdout.o xfflush_stdout.o strlen.o
|
||||||
LIBBB_MOBJ1:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ1))
|
LIBBB_MOBJ1:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ1))
|
||||||
$(LIBBB_MOBJ1):$(LIBBB_MSRC1)
|
$(LIBBB_MOBJ1):$(LIBBB_MSRC1)
|
||||||
|
@ -99,11 +99,18 @@ FILE *bb_xfopen(const char *path, const char *mode)
|
|||||||
|
|
||||||
#ifdef L_xopen
|
#ifdef L_xopen
|
||||||
int bb_xopen(const char *pathname, int flags)
|
int bb_xopen(const char *pathname, int flags)
|
||||||
|
{
|
||||||
|
return bb_xopen3(pathname, flags, 0777);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef L_xopen3
|
||||||
|
int bb_xopen3(const char *pathname, int flags, int mode)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = open(pathname, flags, 0777);
|
ret = open(pathname, flags, mode);
|
||||||
if (ret == -1) {
|
if (ret < 0) {
|
||||||
bb_perror_msg_and_die("%s", pathname);
|
bb_perror_msg_and_die("%s", pathname);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -116,7 +123,7 @@ ssize_t bb_xread(int fd, void *buf, size_t count)
|
|||||||
ssize_t size;
|
ssize_t size;
|
||||||
|
|
||||||
size = read(fd, buf, count);
|
size = read(fd, buf, count);
|
||||||
if (size == -1) {
|
if (size < 0) {
|
||||||
bb_perror_msg_and_die(bb_msg_read_error);
|
bb_perror_msg_and_die(bb_msg_read_error);
|
||||||
}
|
}
|
||||||
return(size);
|
return(size);
|
||||||
|
@ -179,20 +179,16 @@ crontab_main(int ac, char **av)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
|
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
|
||||||
if ((fd = open(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600)) >= 0) {
|
fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
|
||||||
chown(tmp, getuid(), getgid());
|
chown(tmp, getuid(), getgid());
|
||||||
if ((fi = fopen(pas->pw_name, "r"))) {
|
if ((fi = fopen(pas->pw_name, "r"))) {
|
||||||
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
|
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
|
||||||
write(fd, buf, n);
|
write(fd, buf, n);
|
||||||
}
|
|
||||||
EditFile(caller, tmp);
|
|
||||||
remove(tmp);
|
|
||||||
lseek(fd, 0L, 0);
|
|
||||||
repFd = fd;
|
|
||||||
} else {
|
|
||||||
bb_error_msg_and_die("unable to create %s", tmp);
|
|
||||||
}
|
}
|
||||||
|
EditFile(caller, tmp);
|
||||||
|
remove(tmp);
|
||||||
|
lseek(fd, 0L, 0);
|
||||||
|
repFd = fd;
|
||||||
}
|
}
|
||||||
option = REPLACE;
|
option = REPLACE;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
@ -289,11 +285,8 @@ GetReplaceStream(const char *user, const char *file)
|
|||||||
if (ChangeUser(user, 0) < 0)
|
if (ChangeUser(user, 0) < 0)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
fd = open(file, O_RDONLY);
|
bb_default_error_retval = 0;
|
||||||
if (fd < 0) {
|
fd = bb_xopen3(file, O_RDONLY, 0);
|
||||||
bb_error_msg("unable to open %s", file);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
write(filedes[1], buf, 1);
|
write(filedes[1], buf, 1);
|
||||||
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||||
|
@ -101,8 +101,7 @@ int mt_main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(file, mode, 0)) < 0)
|
fd = bb_xopen3(file, mode, 0);
|
||||||
bb_perror_msg_and_die("%s", file);
|
|
||||||
|
|
||||||
switch (code->value) {
|
switch (code->value) {
|
||||||
case MTTELL:
|
case MTTELL:
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
* Filename: xmodem.c
|
* Filename: xmodem.c
|
||||||
* Version: $Id: rx.c,v 1.2 2004/03/15 08:28:46 andersen Exp $
|
* Version: $Id: rx.c,v 1.2 2004/03/15 08:28:46 andersen Exp $
|
||||||
@ -289,13 +290,8 @@ int rx_main(int argc, char **argv)
|
|||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
|
||||||
fn = argv[1];
|
fn = argv[1];
|
||||||
ttyfd = open("/dev/tty", O_RDWR);
|
ttyfd = bb_xopen3("/dev/tty", O_RDWR, 0);
|
||||||
if (ttyfd < 0)
|
filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
||||||
bb_error_msg_and_die("%s: open on /dev/tty failed: %m\n", argv[0]);
|
|
||||||
|
|
||||||
filefd = open(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
||||||
if (filefd < 0)
|
|
||||||
bb_error_msg_and_die("%s: open on %s failed: %m\n", argv[0], fn);
|
|
||||||
|
|
||||||
if (tcgetattr(ttyfd, &tty) < 0)
|
if (tcgetattr(ttyfd, &tty) < 0)
|
||||||
bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]);
|
bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]);
|
||||||
|
@ -55,20 +55,7 @@
|
|||||||
* Restructured (and partly rewritten) by:
|
* Restructured (and partly rewritten) by:
|
||||||
* Björn Ekwall <bj0rn@blox.se> February 1999
|
* Björn Ekwall <bj0rn@blox.se> February 1999
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -4297,9 +4284,7 @@ int insmod_ng_main( int argc, char **argv)
|
|||||||
strcat(options, " ");
|
strcat(options, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(filename, O_RDONLY, 0)) < 0) {
|
fd = bb_xopen3(filename, O_RDONLY, 0);
|
||||||
bb_perror_msg_and_die("cannot open module `%s'", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
fstat(fd, &st);
|
fstat(fd, &st);
|
||||||
len = st.st_size;
|
len = st.st_size;
|
||||||
|
@ -123,7 +123,8 @@ int vconfig_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Don't bother closing the filedes. It will be closed on cleanup. */
|
/* Don't bother closing the filedes. It will be closed on cleanup. */
|
||||||
bb_xopen(conf_file_name, O_RDONLY); /* Will die if 802.1q is not present */
|
/* Will die if 802.1q is not present */
|
||||||
|
bb_xopen3(conf_file_name, O_RDONLY, 0);
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
|
memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ static inline int get_size(const char *file)
|
|||||||
int fd;
|
int fd;
|
||||||
long size;
|
long size;
|
||||||
|
|
||||||
fd = bb_xopen(file, O_RDWR);
|
fd = bb_xopen3(file, O_RDWR, 0);
|
||||||
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
|
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return (size * 512);
|
return (size * 512);
|
||||||
@ -820,7 +820,7 @@ goodbye:
|
|||||||
tmp += dirsize;
|
tmp += dirsize;
|
||||||
*(short *) tmp = 2;
|
*(short *) tmp = 2;
|
||||||
strcpy(tmp + 2, ".badblocks");
|
strcpy(tmp + 2, ".badblocks");
|
||||||
DEV = bb_xopen(device_name, O_RDWR);
|
DEV = bb_xopen3(device_name, O_RDWR, 0);
|
||||||
if (fstat(DEV, &statbuf) < 0)
|
if (fstat(DEV, &statbuf) < 0)
|
||||||
bb_error_msg_and_die("unable to stat %s", device_name);
|
bb_error_msg_and_die("unable to stat %s", device_name);
|
||||||
if (!S_ISBLK(statbuf.st_mode))
|
if (!S_ISBLK(statbuf.st_mode))
|
||||||
|
@ -258,7 +258,7 @@ static inline long get_size(const char *file)
|
|||||||
int fd;
|
int fd;
|
||||||
long size;
|
long size;
|
||||||
|
|
||||||
fd = bb_xopen(file, O_RDONLY);
|
fd = bb_xopen3(file, O_RDONLY, 0);
|
||||||
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
|
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
|
||||||
size /= pagesize / 512;
|
size /= pagesize / 512;
|
||||||
} else {
|
} else {
|
||||||
@ -341,7 +341,7 @@ int mkswap_main(int argc, char **argv)
|
|||||||
PAGES * goodpages);
|
PAGES * goodpages);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEV = bb_xopen(device_name, O_RDWR);
|
DEV = bb_xopen3(device_name, O_RDWR, 0);
|
||||||
if (fstat(DEV, &statbuf) < 0)
|
if (fstat(DEV, &statbuf) < 0)
|
||||||
bb_perror_msg_and_die("%s", device_name);
|
bb_perror_msg_and_die("%s", device_name);
|
||||||
if (!S_ISBLK(statbuf.st_mode))
|
if (!S_ISBLK(statbuf.st_mode))
|
||||||
|
Loading…
Reference in New Issue
Block a user