Changeset 3138 in kBuild for vendor/gnumake/current/w32/subproc/misc.c
- Timestamp:
- Mar 12, 2018 7:32:29 PM (7 years ago)
- File:
-
- 1 edited
-
vendor/gnumake/current/w32/subproc/misc.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/w32/subproc/misc.c
r2596 r3138 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 * an environment block suitable for a windows32 system call27 * 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 * order, is double-null terminated, and is a char *, not a char **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 return _stricoll(*((char**)a1),*((char**)a2));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 char **tmp;43 int size_needed;44 int arrcnt;45 char *ptr;41 char **tmp; 42 int size_needed; 43 int arrcnt; 44 char *ptr; 46 45 47 arrcnt = 0;48 while (arr[arrcnt]) {49 arrcnt++;50 }46 arrcnt = 0; 47 while (arr[arrcnt]) { 48 arrcnt++; 49 } 51 50 52 tmp = (char**) calloc(arrcnt + 1, sizeof(char *));53 if (!tmp) {54 return FALSE;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 qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);66 qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare); 67 67 68 ptr = *envblk_out = calloc(size_needed, 1);69 if (!ptr) {70 free(tmp);71 return FALSE;72 }68 ptr = *envblk_out = calloc(size_needed, 1); 69 if (!ptr) { 70 free(tmp); 71 return FALSE; 72 } 73 73 74 arrcnt = 0;75 while (tmp[arrcnt]) {76 strcpy(ptr, tmp[arrcnt]);77 ptr += strlen(tmp[arrcnt]) + 1;78 arrcnt++;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 free(tmp);82 return TRUE;81 free(tmp); 82 return TRUE; 83 83 }
Note:
See TracChangeset
for help on using the changeset viewer.

