diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 59 |
1 files changed, 44 insertions, 15 deletions
@@ -77,6 +77,30 @@ extern void usage(const char *usage) | |||
77 | exit FALSE; | 77 | exit FALSE; |
78 | } | 78 | } |
79 | 79 | ||
80 | extern void errorMsg(char *s, ...) | ||
81 | { | ||
82 | va_list p; | ||
83 | |||
84 | va_start(p, s); | ||
85 | fflush(stdout); | ||
86 | fprintf(stderr, "\n"); | ||
87 | vfprintf(stderr, s, p); | ||
88 | fprintf(stderr, "\n"); | ||
89 | va_end(p); | ||
90 | } | ||
91 | |||
92 | extern void fatalError(char *s, ...) | ||
93 | { | ||
94 | va_list p; | ||
95 | |||
96 | va_start(p, s); | ||
97 | fflush(stdout); | ||
98 | fprintf(stderr, "\n"); | ||
99 | vfprintf(stderr, s, p); | ||
100 | fprintf(stderr, "\n"); | ||
101 | va_end(p); | ||
102 | exit( FALSE); | ||
103 | } | ||
80 | 104 | ||
81 | #if defined (BB_INIT) || defined (BB_PS) | 105 | #if defined (BB_INIT) || defined (BB_PS) |
82 | 106 | ||
@@ -110,21 +134,31 @@ int get_kernel_revision() | |||
110 | * Return TRUE if a fileName is a directory. | 134 | * Return TRUE if a fileName is a directory. |
111 | * Nonexistant files return FALSE. | 135 | * Nonexistant files return FALSE. |
112 | */ | 136 | */ |
113 | int isDirectory(const char *fileName, const int followLinks) | 137 | int isDirectory(const char *fileName, const int followLinks, struct stat *statBuf) |
114 | { | 138 | { |
115 | struct stat statBuf; | ||
116 | int status; | 139 | int status; |
140 | int didMalloc = 0; | ||
141 | |||
142 | if (statBuf == NULL) { | ||
143 | statBuf = (struct stat *)xmalloc(sizeof(struct stat)); | ||
144 | ++didMalloc; | ||
145 | } | ||
117 | 146 | ||
118 | if (followLinks == TRUE) | 147 | if (followLinks == TRUE) |
119 | status = stat(fileName, &statBuf); | 148 | status = stat(fileName, statBuf); |
120 | else | 149 | else |
121 | status = lstat(fileName, &statBuf); | 150 | status = lstat(fileName, statBuf); |
122 | 151 | ||
123 | if (status < 0) | 152 | if (status < 0 || !(S_ISDIR(statBuf->st_mode))) { |
124 | return FALSE; | 153 | status = FALSE; |
125 | if (S_ISDIR(statBuf.st_mode)) | 154 | } |
126 | return TRUE; | 155 | else status = TRUE; |
127 | return FALSE; | 156 | |
157 | if (didMalloc) { | ||
158 | free(statBuf); | ||
159 | statBuf = NULL; | ||
160 | } | ||
161 | return status; | ||
128 | } | 162 | } |
129 | #endif | 163 | #endif |
130 | 164 | ||
@@ -1189,16 +1223,11 @@ extern void *xmalloc(size_t size) | |||
1189 | void *cp = malloc(size); | 1223 | void *cp = malloc(size); |
1190 | 1224 | ||
1191 | if (cp == NULL) { | 1225 | if (cp == NULL) { |
1192 | error("out of memory"); | 1226 | errorMsg("out of memory"); |
1193 | } | 1227 | } |
1194 | return cp; | 1228 | return cp; |
1195 | } | 1229 | } |
1196 | 1230 | ||
1197 | extern void error(char *msg) | ||
1198 | { | ||
1199 | fprintf(stderr, "\n%s\n", msg); | ||
1200 | exit(1); | ||
1201 | } | ||
1202 | #endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */ | 1231 | #endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */ |
1203 | 1232 | ||
1204 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) | 1233 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) |