Skip to content

Commit bdab50b

Browse files
committed
Try to get temp dir from TMPDIR before defaulting to /tmp
1 parent 50441cf commit bdab50b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/postpic.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ typedef struct {
8484
unsigned int cd;
8585
} PPColor;
8686

87+
char * tmpdir = "/tmp";
88+
8789
#define CS_UNKNOWN colorspaces[0]
8890
#define CS_RGB colorspaces[1]
8991
#define CS_RGBA colorspaces[2]
@@ -508,7 +510,7 @@ Datum image_index(PG_FUNCTION_ARGS)
508510
CatchException(&ex);
509511

510512
//So sad, it doesn't work if I don't write the img :((
511-
sprintf(rimg->filename, "/tmp/ppm%d_%s.jpg", tile, minfo.title );
513+
sprintf(rimg->filename, "%s/ppm%d_%s.jpg", tmpdir, tile, minfo.title );
512514
WriteImage(&iinfo, rimg);
513515
CatchException(&ex);
514516
if(!rimg) {
@@ -879,6 +881,9 @@ void _PG_init()
879881
{
880882
Oid csOid, pOid;
881883
int i;
884+
char * tde;
885+
886+
/* Read colorspace Oids */
882887
pOid = GetSysCacheOid(NAMESPACENAME,
883888
CStringGetDatum("public"), 0, 0, 0);
884889
csOid = GetSysCacheOid(TYPENAMENSP,
@@ -889,4 +894,8 @@ void _PG_init()
889894
colorspaces[i].oid = GetSysCacheOid(ENUMTYPOIDNAME, csOid,
890895
CStringGetDatum(colorspaces[i].name), 0, 0);
891896
}
897+
898+
/* Initialize tempdir from TMPDIR, if available */
899+
tde = getenv("TMPDIR");
900+
if(tde) tmpdir = tde;
892901
}

0 commit comments

Comments
 (0)