Skip to content

Commit

Permalink
Exerc 8_5 test handling fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsm-lisper committed Aug 28, 2024
1 parent 7127159 commit 79eb5f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 9 additions & 1 deletion chapter_8.unix_interface/8_5.finfo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ void dirwalk (char *dir, void (*fcn)(char *))
void finfo (char *name)
{
struct stat stbuf;
char *ftype, fbits[4] = "---", fmode[10] = "---------", mtime[64];
char *ftype, fbits[4] = "---", fmode[10] = "---------";
# ifdef FULL_VER
char mtime[64];
# endif

if (stat(name, &stbuf) == -1) {
fprintf(stderr, "finfo: can't access %s\n", name);
Expand Down Expand Up @@ -73,11 +76,16 @@ void finfo (char *name)
if (stbuf.st_mode & S_IWOTH) fmode[7] = 'w';
if (stbuf.st_mode & S_IXOTH) fmode[8] = 'x';

# ifdef FULL_VER
strftime(mtime, sizeof(mtime), "%Y/%m/%d %H:%M:%S", localtime(&stbuf.st_mtim.tv_sec));

printf("%4s %4d:%4d %3s %9s %s %8ld %2lu %s\n",
ftype, stbuf.st_uid, stbuf.st_gid, fbits, fmode, mtime,
stbuf.st_size, stbuf.st_nlink, name);
# else
printf("%4s %3s %9s %8ld %2lu %s\n",
ftype, fbits, fmode, stbuf.st_size, stbuf.st_nlink, name);
# endif
}

/* print file name */
Expand Down
2 changes: 1 addition & 1 deletion chapter_8.unix_interface/8_5.finfo/tests/1_file.tout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FILE 1000:1000 --- rw-r--r-- 2024/08/28 15:39:07 40 1 tests/testdir/Makefile
FILE --- rw-r--r-- 40 1 tests/testdir/Makefile
14 changes: 7 additions & 7 deletions chapter_8.unix_interface/8_5.finfo/tests/2_directory.tout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FILE 1000:1000 --- rw-r--r-- 2024/08/28 15:39:07 1506 1 tests/testdir//dirent.c
FILE 1000:1000 --- rw-r--r-- 2024/08/28 15:48:28 2741 1 tests/testdir//main.c
FILE 1000:1000 --- rw-r--r-- 2024/08/28 15:39:07 40 1 tests/testdir//Makefile
FILE 1000:1000 --- rw-r--r-- 2024/08/28 15:48:28 2741 1 tests/testdir//mainlink.c
FILE 1000:1000 --- rw-r--r-- 2024/08/28 15:45:37 0 1 tests/testdir//maindir/another_file
DIR 1000:1000 --- rwxr-xr-x 2024/08/28 15:45:37 24 1 tests/testdir//maindir
DIR 1000:1000 --- rwxr-xr-x 2024/08/28 15:40:17 78 1 tests/testdir/
FILE --- rw-r--r-- 1506 1 tests/testdir//dirent.c
FILE --- rw-r--r-- 2741 1 tests/testdir//main.c
FILE --- rw-r--r-- 40 1 tests/testdir//Makefile
FILE --- rw-r--r-- 2741 1 tests/testdir//mainlink.c
FILE --- rw-r--r-- 0 1 tests/testdir//maindir/another_file
DIR --- rwxr-xr-x 24 1 tests/testdir//maindir
DIR --- rwxr-xr-x 78 1 tests/testdir/

0 comments on commit 79eb5f7

Please sign in to comment.