src/hg/lib/hgRelate.c 1.26

1.26 2010/02/17 08:53:20 markd
allow defaulting to TMPDIR directory
Index: src/hg/lib/hgRelate.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/hgRelate.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -b -B -U 4 -r1.25 -r1.26
--- src/hg/lib/hgRelate.c	11 Oct 2008 20:17:35 -0000	1.25
+++ src/hg/lib/hgRelate.c	17 Feb 2010 08:53:20 -0000	1.26
@@ -169,32 +169,43 @@
 sqlDisconnect(pConn);
 }
 
 static void getTabFile(char *tmpDir, char *tableName, char path[PATH_LEN])
-/* generate path to tab file */
+/* generate path to tab file.  If tmpDir is NULL, use TMPDIR environment, or
+ * "/var/tmp".  tmpDir NULL also include pid in file name */
 {
-safef(path, PATH_LEN, "%s/%s.tab", tmpDir, tableName);
+boolean inclPid = (tmpDir == NULL);
+if (tmpDir == NULL)
+    tmpDir = getenv("TMPDIR");
+if (tmpDir == NULL)
+    tmpDir = "/var/tmp";
+if (inclPid)
+    safef(path, PATH_LEN, "%s/%s.tab", tmpDir, tableName);
+else
+    safef(path, PATH_LEN, "%s/%s.%d.tab", tmpDir, tableName, getpid());
 }
 
 FILE *hgCreateTabFile(char *tmpDir, char *tableName)
-/* Open a tab file with name corresponding to tableName in tmpDir. */
+/* Open a tab file with name corresponding to tableName in tmpDir.  If tmpDir is NULL,
+ * use TMPDIR environment, or "/var/tmp" */
 {
 char path[PATH_LEN];
 getTabFile(tmpDir, tableName, path);
 return mustOpen(path, "w");
 }
 
 int hgUnlinkTabFile(char *tmpDir, char *tableName)
-/* Unlink tab file */
+/* Unlink tab file.   If tmpDir is NULL, use TMPDIR environment, or "/var/tmp" */
 {
 char path[PATH_LEN];
 getTabFile(tmpDir, tableName, path);
 return unlink(path);
 }
 
 void hgLoadTabFile(struct sqlConnection *conn, char *tmpDir, char *tableName,
                    FILE **tabFh)
-/* Load tab delimited file corresponding to tableName. close fh if not NULL */
+/* Load tab delimited file corresponding to tableName. close fh if not NULL.
+ * If tmpDir is NULL, use TMPDIR environment, or "/var/tmp"*/
 {
 char path[PATH_LEN];
 getTabFile(tmpDir, tableName, path);
 carefulClose(tabFh);
@@ -202,9 +213,10 @@
 }
 
 void hgLoadNamedTabFile(struct sqlConnection *conn, char *tmpDir, char *tableName,
                         char *fileName, FILE **tabFh)
-/* Load named tab delimited file corresponding to tableName. close fh if not NULL */
+/* Load named tab delimited file corresponding to tableName. close fh if not
+ * NULL If tmpDir is NULL, use TMPDIR environment, or "/var/tmp"*/
 {
 char path[PATH_LEN];
 getTabFile(tmpDir, fileName, path);
 carefulClose(tabFh);
@@ -213,18 +225,19 @@
 
 void hgLoadTabFileOpts(struct sqlConnection *conn, char *tmpDir, char *tableName,
                        unsigned options, FILE **tabFh)
 /* Load tab delimited file corresponding to tableName. close tabFh if not NULL
- * Options are those supported by sqlLoadTabFile */
+ * If tmpDir is NULL, use TMPDIR environment, or "/var/tmp". Options are those
+ * supported by sqlLoadTabFile */
 {
 char path[PATH_LEN];
 getTabFile(tmpDir, tableName, path);
 carefulClose(tabFh);
 sqlLoadTabFile(conn, path, tableName, options);
 }
 
 void hgRemoveTabFile(char *tmpDir, char *tableName)
-/* Remove file. */
+/* Remove file.* If tmpDir is NULL, use TMPDIR environment, or "/var/tmp" */
 {
 char path[PATH_LEN];
 getTabFile(tmpDir, tableName, path);
 if (remove(path) == -1)