summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorErik Andersen2000-02-11 21:55:04 +0000
committerErik Andersen2000-02-11 21:55:04 +0000
commit9ffdaa647ee57263247e047e6c67c5a7fa1f2a6c (patch)
tree3485e1645439990642fcb941d579deb10f8a17a7 /utility.c
parent5e1b2ca1161cba481ccf4873427389f59dbc23e0 (diff)
downloadbusybox-9ffdaa647ee57263247e047e6c67c5a7fa1f2a6c.zip
busybox-9ffdaa647ee57263247e047e6c67c5a7fa1f2a6c.tar.gz
Updates
-Erik
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c59
1 files changed, 44 insertions, 15 deletions
diff --git a/utility.c b/utility.c
index 00a1c69..5bfed81 100644
--- a/utility.c
+++ b/utility.c
@@ -77,6 +77,30 @@ extern void usage(const char *usage)
exit FALSE;
}
+extern void errorMsg(char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ fflush(stdout);
+ fprintf(stderr, "\n");
+ vfprintf(stderr, s, p);
+ fprintf(stderr, "\n");
+ va_end(p);
+}
+
+extern void fatalError(char *s, ...)
+{
+ va_list p;
+
+ va_start(p, s);
+ fflush(stdout);
+ fprintf(stderr, "\n");
+ vfprintf(stderr, s, p);
+ fprintf(stderr, "\n");
+ va_end(p);
+ exit( FALSE);
+}
#if defined (BB_INIT) || defined (BB_PS)
@@ -110,21 +134,31 @@ int get_kernel_revision()
* Return TRUE if a fileName is a directory.
* Nonexistant files return FALSE.
*/
-int isDirectory(const char *fileName, const int followLinks)
+int isDirectory(const char *fileName, const int followLinks, struct stat *statBuf)
{
- struct stat statBuf;
int status;
+ int didMalloc = 0;
+
+ if (statBuf == NULL) {
+ statBuf = (struct stat *)xmalloc(sizeof(struct stat));
+ ++didMalloc;
+ }
if (followLinks == TRUE)
- status = stat(fileName, &statBuf);
+ status = stat(fileName, statBuf);
else
- status = lstat(fileName, &statBuf);
+ status = lstat(fileName, statBuf);
- if (status < 0)
- return FALSE;
- if (S_ISDIR(statBuf.st_mode))
- return TRUE;
- return FALSE;
+ if (status < 0 || !(S_ISDIR(statBuf->st_mode))) {
+ status = FALSE;
+ }
+ else status = TRUE;
+
+ if (didMalloc) {
+ free(statBuf);
+ statBuf = NULL;
+ }
+ return status;
}
#endif
@@ -1189,16 +1223,11 @@ extern void *xmalloc(size_t size)
void *cp = malloc(size);
if (cp == NULL) {
- error("out of memory");
+ errorMsg("out of memory");
}
return cp;
}
-extern void error(char *msg)
-{
- fprintf(stderr, "\n%s\n", msg);
- exit(1);
-}
#endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)