From 01ba9cde63214397843c6f45e0abcacb685218c3 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 10 Jul 2009 23:57:38 +0100 Subject: [PATCH] Prototypes for venus/test Add additonal headers, prototypes, and ANSIfy function definitions in venus/test Reviewed-on: http://gerrit.openafs.org/48 Verified-by: Russ Allbery Reviewed-by: Russ Allbery --- src/venus/test/fulltest.c | 292 +++++++++++++++++++++------------ src/venus/test/getinitparams.c | 9 +- src/venus/test/idtest.c | 6 +- src/venus/test/owntest.c | 7 +- 4 files changed, 201 insertions(+), 113 deletions(-) diff --git a/src/venus/test/fulltest.c b/src/venus/test/fulltest.c index f9475ce4c..dda9d9a64 100644 --- a/src/venus/test/fulltest.c +++ b/src/venus/test/fulltest.c @@ -16,11 +16,12 @@ #include #include #include +#include +#include #include -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char **argv) { char *dirName; char tempName[1024]; @@ -29,7 +30,6 @@ main(argc, argv) int fd1; int code; #ifndef HAVE_GETCWD - extern char *getwd(); #define getcwd(x,y) getwd(x) #endif @@ -38,42 +38,64 @@ main(argc, argv) return printf("usage: fulltest \n"); dirName = argv[1]; mkdir(dirName, 0777); - if (chdir(dirName) < 0) - {perror("chdir");return;} + if (chdir(dirName) < 0) { + perror("chdir"); + return -1; + } if (getcwd(tempName, 1024) == 0) { - return printf("Could not get working dir.\n"); + printf("Could not get working dir.\n"); + return -1; } /* now create some files */ fd1 = open("hi", O_CREAT | O_TRUNC | O_RDWR, 0666); - if (fd1 < 0) - {perror("open1");return;} - if (close(fd1) < 0) - {perror("close1");return;} - if (access("hi", 2) < 0) - return printf("New file can not be written (access)\n"); - if (chmod("hi", 0741) < 0) - {perror("chmod1");return;} - if (stat("hi", &tstat) < 0) - {perror("stat1");return;} - if ((tstat.st_mode & 0777) != 0741) - return printf("chmod failed to set mode properly\n"); - + if (fd1 < 0) { + perror("open1"); + return -1; + } + if (close(fd1) < 0) { + perror("close1"); + return -1; + } + if (access("hi", 2) < 0) { + printf("New file can not be written (access)\n"); + return -1; + } + if (chmod("hi", 0741) < 0) { + perror("chmod1"); + return -1; + } + if (stat("hi", &tstat) < 0) { + perror("stat1"); + return -1; + } + if ((tstat.st_mode & 0777) != 0741) { + printf("chmod failed to set mode properly\n"); + return -1; + } fd1 = open("hi", O_RDWR); - if (fd1 < 0) - {perror("open2");return;} - if (fchmod(fd1, 0654) < 0) - {perror("fchmod");return;} - if (fstat(fd1, &tstat) < 0) - {perror("fstat1");return;} - if ((tstat.st_mode & 0777) != 0654) - return printf("fchmod failed to set mode properly\n"); + if (fd1 < 0) { + perror("open2"); + return -1; + } + if (fchmod(fd1, 0654) < 0) { + perror("fchmod"); + return -1; + } + if (fstat(fd1, &tstat) < 0) { + perror("fstat1"); + return -1; + } + if ((tstat.st_mode & 0777) != 0654) { + printf("fchmod failed to set mode properly\n"); + return -1; + } #if 0 /* These appear to be defunct routines; * I don't know what, if anything, replaced them */ if (osi_ExclusiveLockNoBlock(fd1) < 0) - {perror("flock1");return;} + {perror("flock1");return -1;} if (osi_UnLock(fd1) < 0) - {perror("flock/unlock");return;} + {perror("flock/unlock");return -1;} #endif /* How about shared lock portability? */ @@ -85,86 +107,132 @@ main(argc, argv) fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) - {perror("fcntl1: RDLCK");return;} + if (fcntl(fd1, F_SETLK, &fl) == -1) { + perror("fcntl1: RDLCK"); + return -1; + } fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) - {perror("fcntl2: UNLCK");return;} + if (fcntl(fd1, F_SETLK, &fl) == -1) { + perror("fcntl2: UNLCK"); + return -1; + } fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) - {perror("fcntl3: WRLCK");return;} + if (fcntl(fd1, F_SETLK, &fl) == -1) { + perror("fcntl3: WRLCK"); + return -1; + } fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; - if (fcntl(fd1, F_SETLK, &fl) == -1) - {perror("fcntl4: UNLCK");return;} + if (fcntl(fd1, F_SETLK, &fl) == -1) { + perror("fcntl4: UNLCK"); + return -1; + } } - if (fsync(fd1) < 0) - {perror("fsync");return;} - if (write(fd1, "hi\n", 3) != 3) - {perror("write");return;} - if (ftruncate(fd1, 2) < 0) - {perror("ftruncate");return;} - if (close(fd1) < 0) - {perror("close2");return;} + if (fsync(fd1) < 0) { + perror("fsync"); + return -1; + } + if (write(fd1, "hi\n", 3) != 3) { + perror("write"); + return -1; + } + if (ftruncate(fd1, 2) < 0) { + perror("ftruncate"); + return -1; + } + if (close(fd1) < 0) { + perror("close2"); + return -1; + } fd1 = open("hi", O_RDONLY); - if (fd1 < 0) - {perror("open3");return;} - if (read(fd1, tempName, 100) != 2) - {perror("read2");return;} - if (close(fd1) < 0) - {perror("close3");return;} - - if (link("hi", "bye") < 0) - {perror("link");return;} - if (stat("bye", &tstat) < 0) - {perror("link/stat");return;} - - if (unlink("bye") < 0) - {perror("unlink");return;} - - if (symlink("hi", "bye") < 0) - {perror("symlink");return;} - if (readlink("bye", tempName, 100) != 2) - {perror("readlink");return;} - if (strncmp(tempName, "hi", 2) != 0) - return printf("readlink contents"); - if (mkdir("tdir", 0777) < 0) - {perror("mkdir");return;} + if (fd1 < 0) { + perror("open3"); + return -1; + } + if (read(fd1, tempName, 100) != 2) { + perror("read2"); + return -1; + } + if (close(fd1) < 0) { + perror("close3"); + return -1; + } + + if (link("hi", "bye") < 0) { + perror("link"); + return -1; + } + if (stat("bye", &tstat) < 0) { + perror("link/stat"); + return -1; + } + + if (unlink("bye") < 0) { + perror("unlink"); + return -1; + } + + if (symlink("hi", "bye") < 0) { + perror("symlink"); + return -1; + } + if (readlink("bye", tempName, 100) != 2) { + perror("readlink"); + return -1; + } + if (strncmp(tempName, "hi", 2) != 0) { + printf("readlink contents"); + return -1; + } + if (mkdir("tdir", 0777) < 0) { + perror("mkdir"); + return -1; + } fd1 = open("tdir/fdsa", O_CREAT | O_TRUNC, 0777); close(fd1); - if (rmdir("tdir") == 0) - return printf("removed non-empty dir\n"); - if (unlink("tdir/fdsa") < 0) - {perror("unlink tdir contents");return;} - if (rmdir("tdir") < 0) - {perror("rmdir");return;} + if (rmdir("tdir") == 0) { + printf("removed non-empty dir\n"); + return -1; + } + if (unlink("tdir/fdsa") < 0) { + perror("unlink tdir contents"); + return -1; + } + if (rmdir("tdir") < 0) { + perror("rmdir"); + return -1; + } fd1 = open(".", O_RDONLY); - if (fd1 < 0) - {perror("open dot");return;} + if (fd1 < 0) { + perror("open dot"); + return -1; + } if (read(fd1, tempName, 20) < 20) perror("read dir"); close(fd1); fd1 = open("rotest", O_RDWR | O_CREAT, 0444); - if (fd1 < 0) - {perror("open ronly");return;} + if (fd1 < 0) { + perror("open ronly"); + return -1; + } fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */ code = write(fd1, "test", 4); if (code != 4) { @@ -172,38 +240,60 @@ main(argc, argv) exit(1); } code = close(fd1); - if (code) - {perror("close ronly");return;} + if (code) { + perror("close ronly"); + return -1; + } code = stat("rotest", &tstat); - if (code < 0) - {perror("stat ronly");return;} + if (code < 0) { + perror("stat ronly"); + return -1; + } if (tstat.st_size != 4) { printf("rotest short close\n"); exit(1); } - if (unlink("rotest") < 0) - {perror("rotest unlink");return;} + if (unlink("rotest") < 0) { + perror("rotest unlink"); + return -1; + } - if (rename("hi", "bye") < 0) - {perror("rename1");return;} - if (stat("bye", &tstat) < 0) - {perror("rename target invisible\n");return;} - if (stat("hi", &tstat) == 0) - return printf("rename source still there\n"); + if (rename("hi", "bye") < 0) { + perror("rename1"); + return -1; + } + if (stat("bye", &tstat) < 0) { + perror("rename target invisible\n"); + return -1; + } + if (stat("hi", &tstat) == 0) { + printf("rename source still there\n"); + return -1; + } #ifndef AFS_AIX_ENV /* No truncate(2) on aix so the following are excluded */ - if (truncate("bye", 1) < 0) - {perror("truncate");return;} - if (stat("bye", &tstat) < 0) - {perror("truncate zapped");return;} - if (tstat.st_size != 1) - return printf("truncate failed\n"); + if (truncate("bye", 1) < 0) { + perror("truncate"); + return -1; + } + if (stat("bye", &tstat) < 0) { + perror("truncate zapped"); + return -1; + } + if (tstat.st_size != 1) { + printf("truncate failed\n"); + return -1; + } #endif - if (utimes("bye", tvp) < 0) - {perror("utimes");return;} - if (unlink("bye") < 0) - {perror("unlink bye");return;} + if (utimes("bye", tvp) < 0) { + perror("utimes"); + return -1; + } + if (unlink("bye") < 0) { + perror("unlink bye"); + return -1; + } /* now finish up */ chdir(".."); diff --git a/src/venus/test/getinitparams.c b/src/venus/test/getinitparams.c index d96baf462..133f422fb 100644 --- a/src/venus/test/getinitparams.c +++ b/src/venus/test/getinitparams.c @@ -13,11 +13,13 @@ #include #include +#include #include #include #include #include #include +#include #ifdef AFS_AIX41_ENV #include #endif @@ -37,7 +39,6 @@ GetInitParamsCmd(struct cmd_syndesc *as, void *arock) struct cm_initparams cm_initParams; struct ViceIoctl blob; int code; - int len; char *file = 0; int fd = 0; @@ -90,10 +91,8 @@ GetInitParamsCmd(struct cmd_syndesc *as, void *arock) exit(0); } - -main(ac, av) - int ac; - char **av; +int +main(int ac, char **av) { int code; struct cmd_syndesc *ts; diff --git a/src/venus/test/idtest.c b/src/venus/test/idtest.c index cb691199a..d84133a7f 100644 --- a/src/venus/test/idtest.c +++ b/src/venus/test/idtest.c @@ -10,9 +10,11 @@ #include #include #include +#include +#include - -main(argc, argv) +int +main(int argc, char **argv) { int uid; diff --git a/src/venus/test/owntest.c b/src/venus/test/owntest.c index 0bc08a7dd..e577cbc5f 100644 --- a/src/venus/test/owntest.c +++ b/src/venus/test/owntest.c @@ -21,11 +21,8 @@ #include #include -extern int errno; - -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char **argv) { struct timeval tv[2]; struct stat tstat; -- 2.39.5