summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-11-09 01:51:02 +0000
committerEric Andersen <andersen@codepoet.org>1999-11-09 01:51:02 +0000
commit3d8dbe1ca0358ab00b6b505dcc797f17ffd9148f (patch)
tree2491a18ffcb35e3f89be34795950293f44c1cfcb /utility.c
parent50d6360771be509737bb55b2cc5bc5e25f2a4fea (diff)
downloadbusybox-w32-3d8dbe1ca0358ab00b6b505dcc797f17ffd9148f.tar.gz
busybox-w32-3d8dbe1ca0358ab00b6b505dcc797f17ffd9148f.tar.bz2
busybox-w32-3d8dbe1ca0358ab00b6b505dcc797f17ffd9148f.zip
Stuf
Diffstat (limited to '')
-rw-r--r--utility.c93
1 files changed, 38 insertions, 55 deletions
diff --git a/utility.c b/utility.c
index 59ac36197..cdf027a02 100644
--- a/utility.c
+++ b/utility.c
@@ -236,7 +236,30 @@ copyFile( const char *srcName, const char *destName,
236 236
237 237
238 238
239#ifdef BB_TAR 239#if defined BB_TAR || defined BB_LS
240
241#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
242#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
243
244/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
245static const mode_t SBIT[] = {
246 0, 0, S_ISUID,
247 0, 0, S_ISGID,
248 0, 0, S_ISVTX
249};
250
251/* The 9 mode bits to test */
252static const mode_t MBIT[] = {
253 S_IRUSR, S_IWUSR, S_IXUSR,
254 S_IRGRP, S_IWGRP, S_IXGRP,
255 S_IROTH, S_IWOTH, S_IXOTH
256};
257
258#define MODE1 "rwxrwxrwx"
259#define MODE0 "---------"
260#define SMODE1 "..s..s..t"
261#define SMODE0 "..S..S..T"
262
240/* 263/*
241 * Return the standard ls-like mode string from a file mode. 264 * Return the standard ls-like mode string from a file mode.
242 * This is static and so is overwritten on each call. 265 * This is static and so is overwritten on each call.
@@ -245,64 +268,25 @@ const char *modeString(int mode)
245{ 268{
246 static char buf[12]; 269 static char buf[12];
247 270
248 strcpy(buf, "----------"); 271 int i;
249 272 buf[0] = TYPECHAR(mode);
250 /* 273 for (i=0; i<9; i++) {
251 * Fill in the file type. 274 if (mode & SBIT[i])
252 */ 275 buf[i+1] = (mode & MBIT[i])?
253 if (S_ISDIR(mode)) 276 SMODE1[i] : SMODE0[i];
254 buf[0] = 'd'; 277 else
255 if (S_ISCHR(mode)) 278 buf[i+1] = (mode & MBIT[i])?
256 buf[0] = 'c'; 279 MODE1[i] : MODE0[i];
257 if (S_ISBLK(mode)) 280 }
258 buf[0] = 'b';
259 if (S_ISFIFO(mode))
260 buf[0] = 'p';
261 if (S_ISLNK(mode))
262 buf[0] = 'l';
263 if (S_ISSOCK(mode))
264 buf[0] = 's';
265 /*
266 * Now fill in the normal file permissions.
267 */
268 if (mode & S_IRUSR)
269 buf[1] = 'r';
270 if (mode & S_IWUSR)
271 buf[2] = 'w';
272 if (mode & S_IXUSR)
273 buf[3] = 'x';
274 if (mode & S_IRGRP)
275 buf[4] = 'r';
276 if (mode & S_IWGRP)
277 buf[5] = 'w';
278 if (mode & S_IXGRP)
279 buf[6] = 'x';
280 if (mode & S_IROTH)
281 buf[7] = 'r';
282 if (mode & S_IWOTH)
283 buf[8] = 'w';
284 if (mode & S_IXOTH)
285 buf[9] = 'x';
286
287 /*
288 * Finally fill in magic stuff like suid and sticky text.
289 */
290 if (mode & S_ISUID)
291 buf[3] = ((mode & S_IXUSR) ? 's' : 'S');
292 if (mode & S_ISGID)
293 buf[6] = ((mode & S_IXGRP) ? 's' : 'S');
294 if (mode & S_ISVTX)
295 buf[9] = ((mode & S_IXOTH) ? 't' : 'T');
296
297 return buf; 281 return buf;
298} 282}
283#endif
299 284
300 285
286#ifdef BB_TAR
301/* 287/*
302 * Get the time string to be used for a file. 288 * Return the standard ls-like time string from a time_t
303 * This is down to the minute for new files, but only the date for old files. 289 * This is static and so is overwritten on each call.
304 * The string is returned from a static buffer, and so is overwritten for
305 * each call.
306 */ 290 */
307const char *timeString(time_t timeVal) 291const char *timeString(time_t timeVal)
308{ 292{
@@ -325,7 +309,6 @@ const char *timeString(time_t timeVal)
325 return buf; 309 return buf;
326} 310}
327 311
328
329/* 312/*
330 * Write all of the supplied buffer out to a file. 313 * Write all of the supplied buffer out to a file.
331 * This does multiple writes as necessary. 314 * This does multiple writes as necessary.