Changeset 3140 for trunk/src/kmk/w32/subproc/misc.c
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/w32/subproc/misc.c
r2591 r3140 1 1 /* Process handling for Windows 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 3 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 2 Copyright (C) 1996-2016 Free Software Foundation, Inc. 4 3 This file is part of GNU Make. 5 4 … … 26 25 /* 27 26 * Description: Convert a NULL string terminated UNIX environment block to 28 * 27 * an environment block suitable for a windows32 system call 29 28 * 30 29 * Returns: TRUE= success, FALSE=fail 31 30 * 32 31 * Notes/Dependencies: the environment block is sorted in case-insensitive 33 * 32 * order, is double-null terminated, and is a char *, not a char ** 34 33 */ 35 34 int _cdecl compare(const void *a1, const void *a2) 36 35 { 37 36 return _stricoll(*((char**)a1),*((char**)a2)); 38 37 } 39 38 bool_t 40 arr2envblk(char **arr, char **envblk_out )39 arr2envblk(char **arr, char **envblk_out, int *envsize_needed) 41 40 { 42 43 44 45 41 char **tmp; 42 int size_needed; 43 int arrcnt; 44 char *ptr; 46 45 47 48 49 50 46 arrcnt = 0; 47 while (arr[arrcnt]) { 48 arrcnt++; 49 } 51 50 52 53 54 55 51 tmp = (char**) calloc(arrcnt + 1, sizeof(char *)); 52 if (!tmp) { 53 return FALSE; 54 } 56 55 57 arrcnt = 0; 58 size_needed = 0; 59 while (arr[arrcnt]) { 60 tmp[arrcnt] = arr[arrcnt]; 61 size_needed += strlen(arr[arrcnt]) + 1; 62 arrcnt++; 63 } 64 size_needed++; 56 arrcnt = 0; 57 size_needed = *envsize_needed = 0; 58 while (arr[arrcnt]) { 59 tmp[arrcnt] = arr[arrcnt]; 60 size_needed += strlen(arr[arrcnt]) + 1; 61 arrcnt++; 62 } 63 size_needed++; 64 *envsize_needed = size_needed; 65 65 66 66 qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare); 67 67 68 69 70 71 72 68 ptr = *envblk_out = calloc(size_needed, 1); 69 if (!ptr) { 70 free(tmp); 71 return FALSE; 72 } 73 73 74 75 76 77 78 79 74 arrcnt = 0; 75 while (tmp[arrcnt]) { 76 strcpy(ptr, tmp[arrcnt]); 77 ptr += strlen(tmp[arrcnt]) + 1; 78 arrcnt++; 79 } 80 80 81 82 81 free(tmp); 82 return TRUE; 83 83 }
Note:
See TracChangeset
for help on using the changeset viewer.