src/lib/tests/pipelineTester.c 1.5

1.5 2009/12/19 00:23:21 angie
Added must{Open,Read,Write,Close}Fd and mustLseek to common.c, for operations on file descriptors. Some were already in lib/tests/pipelineTester.c - replaced those.
Index: src/lib/tests/pipelineTester.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/tests/pipelineTester.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -B -U 4 -r1.4 -r1.5
--- src/lib/tests/pipelineTester.c	4 Aug 2006 06:00:20 -0000	1.4
+++ src/lib/tests/pipelineTester.c	19 Dec 2009 00:23:21 -0000	1.5
@@ -70,24 +70,8 @@
     }
 return cnt;
 }
 
-int mustOpenFd(char *fname, boolean isWrite)
-/* open a file, returning a descriptor or aborting */
-{
-int fd = open(fname, (isWrite ? O_WRONLY|O_CREAT|O_TRUNC : O_RDONLY), 0777);
-if (fd < 0)
-    errnoAbort("open of %s failed", fname);
-return fd;
-}
-
-void mustCloseFd(int fd)
-/* close a file, abort on an error */
-{
-if (close(fd) < 0)
-    errnoAbort("close failed");
-}
-
 char *parseQuoted(char **spPtr, char *cmdArgs)
 /* parse a quoted string */
 {
 char *start = *spPtr;
@@ -204,32 +188,33 @@
 
 void pipelineTestFd(char ***cmds, unsigned options)
 /* test for file descriptor API */
 {
-int otherEndFd = mustOpenFd(otherEndFile, isWrite);
+int mode = (isWrite ? O_WRONLY|O_CREAT|O_TRUNC : O_RDONLY);
+int otherEndFd = mustOpenFd(otherEndFile, mode);
 int stderrFd = (stderrFile == NULL) ? STDERR_FILENO
-    : mustOpenFd(stderrFile, TRUE);
+    : mustOpenFd(stderrFile, O_WRONLY|O_CREAT|O_TRUNC);
 struct pipeline *pl = pipelineOpenFd(cmds, options, otherEndFd, stderrFd);
 runPipelineTest(pl);
 pipelineFree(&pl);
-mustCloseFd(otherEndFd);
+mustCloseFd(&otherEndFd);
 if (stderrFile != NULL)
-    mustCloseFd(stderrFd);
+    mustCloseFd(&stderrFd);
 }
 
 void pipelineTestMem(char ***cmds, unsigned options)
 /* test for memory buffer API */
 {
 int stderrFd = (stderrFile == NULL) ? STDERR_FILENO
-    : mustOpenFd(stderrFile, TRUE);
+    : mustOpenFd(stderrFile, O_WRONLY|O_CREAT|O_TRUNC);
 size_t otherEndBufSize = 0;
 void *otherEndBuf = loadMemData(otherEndFile, &otherEndBufSize);
 struct pipeline *pl = pipelineOpenMem(cmds, options, otherEndBuf, otherEndBufSize, stderrFd);
 runPipelineTest(pl);
 pipelineFree(&pl);
 freeMem(otherEndBuf);
 if (stderrFile != NULL)
-    mustCloseFd(stderrFd);
+    mustCloseFd(&stderrFd);
 }
 
 void pipelineTestFName(char ***cmds, unsigned options)
 /* test for file name API */