#include #include #include #include #include #include #include #define USAGE "usage: lss [-aAmMcCsSh] [-f fmt] file....\n" main(int argc, char **argv) { struct stat stat_buf; int fmts=0, i, j, c, errflg = 0; extern char *optarg; extern int optind; char fmt[50] = ""; char *time_fmt = NULL; char *buff = NULL; size_t buff_size; while ((c = getopt(argc, argv, "haAmMcCsSf:")) != EOF) { if (index("aAmMcCsS", c) != 0) { if (fmts < (sizeof(fmt)-1)) fmt[fmts++] = (char) c; fmt[fmts] = (char) 0; } else if ((char) c == 'f') { time_fmt=optarg; } else if ((char) c == 'h') { printf(USAGE); printf("Options:"\ " -h Display this help\n"\ " -a Access time in seconds\n"\ " -A Access time in human format\n"\ " -m Modify time in seconds\n"\ " -M Modify time in human format\n"\ " -c Inode Change time in seconds\n"\ " -C Inode Change time in human format\n"\ " -f Specify format for human readable times\n"\ " -s Size in bytes\n"\ " -S Space used in blocks\n"\ ); exit(0); } else { errflg++; } } if (argc < 2) { fprintf(stderr, "No Files given\n"); errflg++; } if (errflg) { fprintf(stderr, USAGE); exit(1); } if (time_fmt == NULL) { time_fmt = "%Y-%m-%d %T"; } /* Guess Size for buff */ buff_size = strlen(time_fmt)*8 + 80; while (buff = (char *) malloc(buff_size)) { /* Check that format will fit into only half the space */ if (strftime(buff, buff_size/2, time_fmt, localtime((time_t*)&buff_size))) break ; free(buff); buff_size += buff_size; } for (i=optind; i