aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-09-27 04:09:22 +0000
committerMatt Kraai <kraai@debian.org>2000-09-27 04:09:22 +0000
commitc0321f9bc67e0a90dbd12f4d7b39d6991c9899cd (patch)
tree119d96c575fe50db7026ee96d476006823dd0f4b /utility.c
parente7c1af1e0dc1440483d7f195f15eb0df5cf70a04 (diff)
downloadbusybox-c0321f9bc67e0a90dbd12f4d7b39d6991c9899cd.tar.gz
Rewrote head to perservere when it can't open a file, and share code
with cat.
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/utility.c b/utility.c
index df2515c2b..03d649757 100644
--- a/utility.c
+++ b/utility.c
@@ -1634,12 +1634,14 @@ extern void print_file(FILE *file)
extern int print_file_by_name(char *filename)
{
FILE *file;
- file = fopen(filename, "r");
- if (file == NULL) {
+ if ((file = wfopen(filename, "r")) == NULL)
+ return FALSE;
+ print_file(file);
+ if (errno) {
errorMsg("%s: %s\n", filename, strerror(errno));
+ errno = 0;
return FALSE;
}
- print_file(file);
return TRUE;
}
#endif /* BB_CAT */
@@ -1719,6 +1721,18 @@ void xregcomp(regex_t *preg, const char *regex, int cflags)
}
#endif
+#if defined BB_CAT || defined BB_HEAD
+FILE *wfopen(const char *path, const char *mode)
+{
+ FILE *fp;
+ if ((fp = fopen(path, mode)) == NULL) {
+ errorMsg("%s: %s\n", path, strerror(errno));
+ errno = 0;
+ }
+ return fp;
+}
+#endif
+
#if defined BB_HOSTNAME || defined BB_LOADACM || defined BB_MORE || defined BB_SED || defined BB_SH || defined BB_UNIQ || defined BB_WC
FILE *xfopen(const char *path, const char *mode)
{