1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*********************************************************************\
* Copyright (c) 2003 by Radim Kolar (hsn@cybermail.net) *
* Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu) *
* *
* You may copy or modify this file in any manner you wish, provided *
* that this notice is always included, and that you hold the author *
* harmless for any loss or damage resulting from the installation or *
* use of this software. *
\*********************************************************************/
#include "tweak.h"
#include "client_def.h"
#include "c_extern.h"
#include "bsd_extern.h"
#include "co_extern.h"
#include "merge.h"
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "my-string.h"
static void stat_file (const char *fname)
{
struct stat sb;
struct tm *ftime;
char buf[35];
if(util_stat(fname,&sb))
{
printf("%s: stat error\n",fname);
} else
{
if(S_ISREG(sb.st_mode))
printf("File");
else
if(S_ISDIR(sb.st_mode))
printf("Directory");
ftime=localtime(&sb.st_mtime);
strftime(buf,35,"%Y-%m-%d %H:%M:%S",ftime);
#ifdef NATIVE_LARGEFILES
#define SFORM "%llu"
#else
#define SFORM "%lu"
#endif
printf(": %s Size: "SFORM" Time: %s\n",fname,sb.st_size,buf);
}
}
int main (int argc, char ** argv)
{
char n[1024];
int prompt;
char **av, *av2[2];
env_client();
if(argc>1)
{
for( optind=1; argc>optind ; optind++)
{
if(!(av = glob(argv[optind])))
{
av = av2;
av2[0] = argv[optind];
av2[1] = 0;
}
while(*av)
stat_file(*av++);
}
} else {
prompt = isatty(0);
while(1) {
if(prompt) {
fputs("fstat: ",stdout);
fflush(stdout);
}
if(!getsl(n,1024)) break;
if(!*n) break;
if(!(av = glob(n))) {
av = av2;
av2[0] = n;
av2[1] = 0;
}
while(*av)
stat_file(*av++);
}
}
client_done();
exit(EX_OK);
}
|