]> granicus.if.org Git - postgresql/blob - src/timezone/pgtz.c
Fix timezone data path for Unix and win32.
[postgresql] / src / timezone / pgtz.c
1 /*-------------------------------------------------------------------------
2  *
3  * pgtz.c
4  *        Timezone Library Integration Functions
5  *
6  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  *        $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.6 2004/05/01 22:07:03 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #include "pgtz.h"
15 #include "tzfile.h"
16
17
18 static char tzdir[MAXPGPATH];
19 static int      done_tzdir = 0;
20 char *
21 pg_TZDIR(void)
22 {
23         char       *p;
24
25         if (done_tzdir)
26                 return tzdir;
27
28 #ifndef WIN32
29         StrNCpy(tzdir, PGDATADIR, MAXPGPATH);
30 #else
31         if (GetModuleFileName(NULL, tzdir, MAXPGPATH) == 0)
32                 return NULL;
33 #endif
34
35         canonicalize_path(tzdir);
36 #ifdef WIN32
37         /* trim off binary name, then go up a directory */
38         if ((p = last_path_separator(tzdir)) == NULL)
39                 return NULL;
40         else
41                 *p = '\0';
42         strcat(tzdir, "/../share/timezone");
43 #endif
44         strcat(tzdir, "/timezone");
45
46
47         done_tzdir = 1;
48         return tzdir;
49 }