diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-07-15 11:24:46 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-07-15 11:24:46 +0000 |
commit | 56fcd3fede0e1c4489a3c108d95fd1ff38dfa1a5 (patch) | |
tree | f21ec6dd55e434aff16e698b0286153465775d62 /gcc/ada/adaint.c | |
parent | c2ce85c4e04bda844aa35dfdf41e69e585d97b2e (diff) | |
download | gcc-56fcd3fede0e1c4489a3c108d95fd1ff38dfa1a5.tar.gz |
2009-07-15 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 149655
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@149682 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/adaint.c')
-rw-r--r-- | gcc/ada/adaint.c | 131 |
1 files changed, 67 insertions, 64 deletions
diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c index fd7b1b31ff9..7452f626a5d 100644 --- a/gcc/ada/adaint.c +++ b/gcc/ada/adaint.c @@ -188,6 +188,7 @@ struct vstring #endif #if defined (_WIN32) + #include <dir.h> #include <windows.h> #include <accctrl.h> @@ -1655,10 +1656,14 @@ __gnat_stat (char *name, STRUCT_STAT *statbuf) { #ifdef __MINGW32__ /* Under Windows the directory name for the stat function must not be - terminated by a directory separator except if just after a drive name. */ + terminated by a directory separator except if just after a drive name + or with UNC path without directory (only the name of the shared + resource), for example: \\computer\share\ */ + TCHAR wname [GNAT_MAX_PATH_LEN + 2]; - int name_len; + int name_len, k; TCHAR last_char; + int dirsep_count = 0; S2WSC (wname, name, GNAT_MAX_PATH_LEN + 2); name_len = _tcslen (wname); @@ -1675,9 +1680,17 @@ __gnat_stat (char *name, STRUCT_STAT *statbuf) last_char = wname[name_len - 1]; } + /* Count back-slashes. */ + + for (k=0; k<name_len; k++) + if (wname[k] == _T('\\') || wname[k] == _T('/')) + dirsep_count++; + /* Only a drive letter followed by ':', we must add a directory separator for the stat routine to work properly. */ - if (name_len == 2 && wname[1] == _T(':')) + if ((name_len == 2 && wname[1] == _T(':')) + || (name_len > 3 && wname[0] == _T('\\') && wname[1] == _T('\\') + && dirsep_count == 3)) _tcscat (wname, _T("\\")); return _tstat (wname, (struct _stat *)statbuf); @@ -1897,9 +1910,9 @@ __gnat_set_OWNER_ACL DWORD AccessMode, DWORD AccessPermissions) { - ACL* pOldDACL = NULL; - ACL* pNewDACL = NULL; - SECURITY_DESCRIPTOR* pSD = NULL; + PACL pOldDACL = NULL; + PACL pNewDACL = NULL; + PSECURITY_DESCRIPTOR pSD = NULL; EXPLICIT_ACCESS ea; TCHAR username [100]; DWORD unsize = 100; @@ -2304,70 +2317,58 @@ extern void (*Unlock_Task) (void); #endif -typedef struct _process_list -{ - HANDLE h; - struct _process_list *next; -} Process_List; - -static Process_List *PLIST = NULL; - -static int plist_length = 0; +static HANDLE *HANDLES_LIST = NULL; +static int *PID_LIST = NULL, plist_length = 0, plist_max_length = 0; static void add_handle (HANDLE h) { - Process_List *pl; - - pl = (Process_List *) xmalloc (sizeof (Process_List)); /* -------------------- critical section -------------------- */ (*Lock_Task) (); - pl->h = h; - pl->next = PLIST; - PLIST = pl; + if (plist_length == plist_max_length) + { + plist_max_length += 1000; + HANDLES_LIST = + xrealloc (HANDLES_LIST, sizeof (HANDLE) * plist_max_length); + PID_LIST = + xrealloc (PID_LIST, sizeof (int) * plist_max_length); + } + + HANDLES_LIST[plist_length] = h; + PID_LIST[plist_length] = GetProcessId (h); ++plist_length; (*Unlock_Task) (); /* -------------------- critical section -------------------- */ } -static void -remove_handle (HANDLE h) +void +__gnat_win32_remove_handle (HANDLE h, int pid) { - Process_List *pl; - Process_List *prev = NULL; + int j; /* -------------------- critical section -------------------- */ (*Lock_Task) (); - pl = PLIST; - while (pl) + for (j = 0; j < plist_length; j++) { - if (pl->h == h) + if ((HANDLES_LIST[j] == h) || (PID_LIST[j] == pid)) { - if (pl == PLIST) - PLIST = pl->next; - else - prev->next = pl->next; - free (pl); + CloseHandle (h); + --plist_length; + HANDLES_LIST[j] = HANDLES_LIST[plist_length]; + PID_LIST[j] = PID_LIST[plist_length]; break; } - else - { - prev = pl; - pl = pl->next; - } } - --plist_length; - (*Unlock_Task) (); /* -------------------- critical section -------------------- */ } -static int +static HANDLE win32_no_block_spawn (char *command, char *args[]) { BOOL result; @@ -2432,23 +2433,21 @@ win32_no_block_spawn (char *command, char *args[]) if (result == TRUE) { - add_handle (PI.hProcess); CloseHandle (PI.hThread); - return (int) PI.hProcess; + return PI.hProcess; } else - return -1; + return NULL; } static int win32_wait (int *status) { - DWORD exitcode; + DWORD exitcode, pid; HANDLE *hl; HANDLE h; DWORD res; int k; - Process_List *pl; int hl_len; if (plist_length == 0) @@ -2466,27 +2465,22 @@ win32_wait (int *status) hl = (HANDLE *) xmalloc (sizeof (HANDLE) * hl_len); - pl = PLIST; - while (pl) - { - hl[k++] = pl->h; - pl = pl->next; - } + memmove (hl, HANDLES_LIST, sizeof (HANDLE) * hl_len); (*Unlock_Task) (); /* -------------------- critical section -------------------- */ res = WaitForMultipleObjects (hl_len, hl, FALSE, INFINITE); h = hl[res - WAIT_OBJECT_0]; - free (hl); - - remove_handle (h); GetExitCodeProcess (h, &exitcode); - CloseHandle (h); + pid = GetProcessId (h); + __gnat_win32_remove_handle (h, -1); + + free (hl); *status = (int) exitcode; - return (int) h; + return (int) pid; } #endif @@ -2494,7 +2488,6 @@ win32_wait (int *status) int __gnat_portable_no_block_spawn (char *args[]) { - int pid = 0; #if defined (__vxworks) || defined (__nucleus__) || defined (RTX) return -1; @@ -2514,11 +2507,20 @@ __gnat_portable_no_block_spawn (char *args[]) #elif defined (_WIN32) - pid = win32_no_block_spawn (args[0], args); - return pid; + HANDLE h = NULL; + + h = win32_no_block_spawn (args[0], args); + if (h != NULL) + { + add_handle (h); + return GetProcessId (h); + } + else + return -1; #else - pid = fork (); + + int pid = fork (); if (pid == 0) { @@ -2531,9 +2533,9 @@ __gnat_portable_no_block_spawn (char *args[]) #endif } -#endif - return pid; + + #endif } int @@ -3244,7 +3246,8 @@ __gnat_to_canonical_file_list_init char * __gnat_to_canonical_file_list_next (void) { - return (char *) ""; + static char *empty = ""; + return empty; } void |