[Libsysio-commit] HEAD: libsysio/tests test_getcwd.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2008-04-22 21:44:44
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16060/tests Modified Files: test_getcwd.c Log Message: Modified to honor the "-v", for "verify" the path, option now. This option will cause the test to chdir to the specified directory, print the path, chdir(..), print the path, chdir(..)... Until reaching root. Index: test_getcwd.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_getcwd.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- test_getcwd.c 28 Mar 2007 21:27:12 -0000 1.8 +++ test_getcwd.c 22 Apr 2008 21:44:40 -0000 1.9 @@ -65,12 +65,17 @@ /* * Test getcwd() * - * Usage: test_cwd [<working-dir>...] + * Usage: test_cwd [-v] [<working-dir>...] * * Without any path arguments, the program reads from standard-in, dealing with * each line as an absolute or relative path until EOF. + * + * The -v option tells it to chdir back up tot he root and print the + * working directory at each point. */ +static int verify = 0; /* verify path? */ + static int doit(const char *path); static void usage(void); @@ -85,9 +90,12 @@ main(int argc, char *const argv[]) /* * Parse command line arguments. */ - while ((i = getopt(argc, argv, "")) != -1) + while ((i = getopt(argc, argv, "v")) != -1) switch (i) { + case 'v': + verify = 1; + break; default: usage(); } @@ -147,11 +155,20 @@ static int doit(const char *path) { char *buf; + struct stat stbufs[2], *st1, *st2; + unsigned count; if (SYSIO_INTERFACE_NAME(chdir)(path) != 0) { perror(path); return -1; } + st1 = &stbufs[0]; + if (SYSIO_INTERFACE_NAME(stat)(".", st1) != 0) { + perror("."); + return -1; + } + count = 0; + do { buf = SYSIO_INTERFACE_NAME(getcwd)(NULL, 0); if (!buf) { perror(path); @@ -159,6 +176,19 @@ doit(const char *path) } (void )printf("%s\n", buf); free(buf); + if (SYSIO_INTERFACE_NAME(chdir)("..") != 0) { + perror(".."); + return -1; + } + count++; + st2 = st1; + st1 = &stbufs[count & 1]; + if (SYSIO_INTERFACE_NAME(stat)(".", st1) != 0) { + perror("."); + return -1; + } + } while (verify && + (st1->st_dev != st2->st_dev || st1->st_ino != st2->st_ino)); return 0; } @@ -168,7 +198,7 @@ usage() (void )fprintf(stderr, "Usage: test_getcwd " - " [<path> ...\n]"); + " [<path> [...]]\n"); exit(1); } |