summaryrefslogtreecommitdiff
path: root/Build/source/texk/dviljk/dvi2xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dviljk/dvi2xx.c')
-rw-r--r--Build/source/texk/dviljk/dvi2xx.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/Build/source/texk/dviljk/dvi2xx.c b/Build/source/texk/dviljk/dvi2xx.c
index 91206b7dbe5..a19c5f2de01 100644
--- a/Build/source/texk/dviljk/dvi2xx.c
+++ b/Build/source/texk/dviljk/dvi2xx.c
@@ -121,6 +121,25 @@ VisChar(unsigned char c)
}
#endif
+#ifdef WIN32
+static int is_dir(const char *buff)
+{
+ HANDLE h;
+ WIN32_FIND_DATA w32fd;
+
+ if(((h = FindFirstFile(buff, &w32fd))
+ != INVALID_HANDLE_VALUE) &&
+ (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ FindClose(h);
+ return (1);
+ }
+ else {
+ FindClose(h);
+ return (0);
+ }
+}
+#endif
+
/**********************************************************************/
/******************************* main *******************************/
@@ -4019,19 +4038,36 @@ void DoSpecial(char *str, int n)
We need to create the temporary directory only once per
run; it will be deleted in AllDone(). */
if ( tmp_dir[0] == '\0' ) {
- const char * base_dir;
+ const char * base_dir, * base_base;
+#ifdef WIN32
+# define def_tmp "c:/tmp"
+ if ( (base_dir = getenv("TMPDIR")) == NULL &&
+ (base_dir = getenv("TMP")) == NULL &&
+ (base_dir = getenv("TEMP")) == NULL ) {
+#else
+# define def_tmp "/tmp"
if ( (base_dir = getenv("TMPDIR")) == NULL ) {
- base_dir = "/tmp";
+#endif
+ base_dir = def_tmp;
} else if ( strlen(base_dir) > STRSIZE - sizeof("/dviljkXXXXXX/include.pcl") ) {
- Warning ("TMPDIR %s is too long, using /tmp instead", base_dir);
- base_dir = "/tmp";
+ Warning ("TMPDIR %s is too long, using " def_tmp " instead", base_dir);
+ base_dir = def_tmp;
}
/* FIXME: Actually, we would need a function to sanitize base_dir here.
There may still be constructs like /.. or similar. [03 Jul 07 -js] */
- if ( base_dir[0] == '/' && base_dir[1] == '\0' ) {
- Warning ("Feeling naughty, do we? / is no temporary directory, dude");
- base_dir = "/tmp";
+ base_base = base_dir;
+#ifdef WIN32
+ if ( isalnum(base_dir[0]) && base_dir[1] == ':' )
+ base_base += 2;
+#endif
+ if ( IS_DIR_SEP_CH(base_base[0]) && base_base[1] == '\0' ) {
+ Warning ("Feeling naughty, do we? %s is no temporary directory, dude", base_dir);
+ base_dir = def_tmp;
}
+#ifdef WIN32
+ if ( !is_dir(base_dir) )
+ mkdir(base_dir, 0700);
+#endif
strcpy (tmp_dir, base_dir);
strcat (tmp_dir, "/dviljkXXXXXX");
if ( mkdtemp(tmp_dir) == NULL ) {