aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stat.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 00:12:09 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 00:12:09 +0000
commit5d148e2646874a6f460402f2dd70ea2fb6be08dd (patch)
treefae60c2d7ca0d917f73f6a87554657c09a0ddb7b /coreutils/stat.c
parentfcdb00f7359488d197ac3361dfbc49ccdead8b87 (diff)
downloadbusybox-w32-5d148e2646874a6f460402f2dd70ea2fb6be08dd.tar.gz
busybox-w32-5d148e2646874a6f460402f2dd70ea2fb6be08dd.tar.bz2
busybox-w32-5d148e2646874a6f460402f2dd70ea2fb6be08dd.zip
httpd: fix cgi-bin/index.cgi support, add example of it,
stat: fix end-of-line if format is specified (wasn't printing it), fix %z (time) format to match coreutils 6.3
Diffstat (limited to 'coreutils/stat.c')
-rw-r--r--coreutils/stat.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c
index b9fd42f4a..31dd6624e 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -44,10 +44,16 @@ static char const *file_type(struct stat const *st)
44 44
45static char const *human_time(time_t t) 45static char const *human_time(time_t t)
46{ 46{
47 /* Old
47 static char *str; 48 static char *str;
48 str = ctime(&t); 49 str = ctime(&t);
49 str[strlen(str)-1] = '\0'; 50 str[strlen(str)-1] = '\0';
50 return str; 51 return str;
52 */
53 /* coreutils 6.3 compat: */
54 static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")];
55 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
56 return buf;
51} 57}
52 58
53/* Return the type of the specified file system. 59/* Return the type of the specified file system.
@@ -311,41 +317,41 @@ static void print_it(char const *masterformat, char const *filename,
311 /* create a working copy of the format string */ 317 /* create a working copy of the format string */
312 char *format = xstrdup(masterformat); 318 char *format = xstrdup(masterformat);
313 319
314 /* Add 2 to accommodate our conversion of the stat `%s' format string 320 /* Add 2 to accomodate our conversion of the stat '%s' format string
315 * to the printf `%llu' one. */ 321 * to the printf '%llu' one. */
316 size_t n_alloc = strlen(format) + 2 + 1; 322 size_t n_alloc = strlen(format) + 2 + 1;
317 char *dest = xmalloc(n_alloc); 323 char *dest = xmalloc(n_alloc);
318 324
319 b = format; 325 b = format;
320 while (b) { 326 while (b) {
327 size_t len;
321 char *p = strchr(b, '%'); 328 char *p = strchr(b, '%');
322 if (p != NULL) { 329 if (!p) {
323 size_t len; 330 /* coreutils 6.3 always print <cr> at the end */
324 *p++ = '\0'; 331 /*fputs(b, stdout);*/
325 fputs(b, stdout); 332 puts(b);
326 333 break;
327 len = strspn(p, "#-+.I 0123456789"); 334 }
328 dest[0] = '%'; 335 *p++ = '\0';
329 memcpy(dest + 1, p, len); 336 fputs(b, stdout);
330 dest[1 + len] = 0; 337
331 p += len; 338 len = strspn(p, "#-+.I 0123456789");
332 339 dest[0] = '%';
333 b = p + 1; 340 memcpy(dest + 1, p, len);
334 switch (*p) { 341 dest[1 + len] = 0;
335 case '\0': 342 p += len;
336 b = NULL; 343
337 /* fall through */ 344 b = p + 1;
338 case '%': 345 switch (*p) {
339 putchar('%'); 346 case '\0':
340 break;
341 default:
342 print_func(dest, n_alloc, *p, filename, data);
343 break;
344 }
345
346 } else {
347 fputs(b, stdout);
348 b = NULL; 347 b = NULL;
348 /* fall through */
349 case '%':
350 putchar('%');
351 break;
352 default:
353 print_func(dest, n_alloc, *p, filename, data);
354 break;
349 } 355 }
350 } 356 }
351 357
@@ -372,7 +378,7 @@ static int do_statfs(char const *filename, char const *format)
372 " ID: %-8i Namelen: %-7l Type: %T\n" 378 " ID: %-8i Namelen: %-7l Type: %T\n"
373 "Block size: %-10s\n" 379 "Block size: %-10s\n"
374 "Blocks: Total: %-10b Free: %-10f Available: %a\n" 380 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
375 "Inodes: Total: %-10c Free: %d\n"); 381 "Inodes: Total: %-10c Free: %d");
376 print_it(format, filename, print_statfs, &statfsbuf); 382 print_it(format, filename, print_statfs, &statfsbuf);
377#else 383#else
378 384
@@ -420,7 +426,7 @@ static int do_stat(char const *filename, char const *format)
420#ifdef CONFIG_FEATURE_STAT_FORMAT 426#ifdef CONFIG_FEATURE_STAT_FORMAT
421 if (format == NULL) { 427 if (format == NULL) {
422 if (flags & OPT_TERSE) { 428 if (flags & OPT_TERSE) {
423 format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"; 429 format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
424 } else { 430 } else {
425 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { 431 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
426 format = 432 format =
@@ -517,7 +523,7 @@ int stat_main(int argc, char **argv)
517 int (*statfunc)(char const *, char const *) = do_stat; 523 int (*statfunc)(char const *, char const *) = do_stat;
518 524
519 flags = getopt32(argc, argv, "ftL" 525 flags = getopt32(argc, argv, "ftL"
520 USE_FEATURE_STAT_FORMAT("c:", &format) 526 USE_FEATURE_STAT_FORMAT("c:", &format)
521 ); 527 );
522 528
523 if (flags & 1) /* -f */ 529 if (flags & 1) /* -f */