diff options
| author | Richard M. Stallman | 1996-06-07 23:07:00 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-06-07 23:07:00 +0000 |
| commit | 9d1778b1b7b22972ac6005874db999402b1846ee (patch) | |
| tree | 57b3cd042f0640802e9e9682af772732bc1da07a /src | |
| parent | b4ec679c1eac8651d65824960831d5048321d07a (diff) | |
| download | emacs-9d1778b1b7b22972ac6005874db999402b1846ee.tar.gz emacs-9d1778b1b7b22972ac6005874db999402b1846ee.zip | |
(sys_mktemp): Complete rewrite.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 46 |
1 files changed, 45 insertions, 1 deletions
| @@ -988,10 +988,54 @@ sys_mkdir (const char * path) | |||
| 988 | return _mkdir (map_win32_filename (path, NULL)); | 988 | return _mkdir (map_win32_filename (path, NULL)); |
| 989 | } | 989 | } |
| 990 | 990 | ||
| 991 | /* Because of long name mapping issues, we need to implement this | ||
| 992 | ourselves. Also, MSVC's _mktemp returns NULL when it can't generate | ||
| 993 | a unique name, instead of setting the input template to an empty | ||
| 994 | string. | ||
| 995 | |||
| 996 | Standard algorithm seems to be use pid or tid with a letter on the | ||
| 997 | front (in place of the 6 X's) and cycle through the letters to find a | ||
| 998 | unique name. We extend that to allow any reasonable character as the | ||
| 999 | first of the 6 X's. */ | ||
| 991 | char * | 1000 | char * |
| 992 | sys_mktemp (char * template) | 1001 | sys_mktemp (char * template) |
| 993 | { | 1002 | { |
| 994 | return (char *) map_win32_filename ((const char *) _mktemp (template), NULL); | 1003 | char * p; |
| 1004 | int i; | ||
| 1005 | unsigned uid = GetCurrentThreadId (); | ||
| 1006 | static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#"; | ||
| 1007 | |||
| 1008 | if (template == NULL) | ||
| 1009 | return NULL; | ||
| 1010 | p = template + strlen (template); | ||
| 1011 | i = 5; | ||
| 1012 | /* replace up to the last 5 X's with uid in decimal */ | ||
| 1013 | while (--p >= template && p[0] == 'X' && --i >= 0) | ||
| 1014 | { | ||
| 1015 | p[0] = '0' + uid % 10; | ||
| 1016 | uid /= 10; | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | if (i < 0 && p[0] == 'X') | ||
| 1020 | { | ||
| 1021 | i = 0; | ||
| 1022 | do | ||
| 1023 | { | ||
| 1024 | int save_errno = errno; | ||
| 1025 | p[0] = first_char[i]; | ||
| 1026 | if (sys_access (template, 0) < 0) | ||
| 1027 | { | ||
| 1028 | errno = save_errno; | ||
| 1029 | return template; | ||
| 1030 | } | ||
| 1031 | } | ||
| 1032 | while (++i < sizeof (first_char)); | ||
| 1033 | } | ||
| 1034 | |||
| 1035 | /* Template is badly formed or else we can't generate a unique name, | ||
| 1036 | so return empty string */ | ||
| 1037 | template[0] = 0; | ||
| 1038 | return template; | ||
| 995 | } | 1039 | } |
| 996 | 1040 | ||
| 997 | int | 1041 | int |