1 1.1 christos /* Process handling for Windows 2 1.1 christos Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 3 1.1 christos 2006 Free Software Foundation, Inc. 4 1.1 christos This file is part of GNU Make. 5 1.1 christos 6 1.1 christos GNU Make is free software; you can redistribute it and/or modify it under the 7 1.1 christos terms of the GNU General Public License as published by the Free Software 8 1.1 christos Foundation; either version 2, or (at your option) any later version. 9 1.1 christos 10 1.1 christos GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 11 1.1 christos WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 1.1 christos A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 1.1 christos 14 1.1 christos You should have received a copy of the GNU General Public License along with 15 1.1 christos GNU Make; see the file COPYING. If not, write to the Free Software 16 1.1 christos Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 17 1.1 christos 18 1.1 christos #include <stddef.h> 19 1.1 christos #include <stdlib.h> 20 1.1 christos #include <string.h> 21 1.1 christos #include <windows.h> 22 1.1 christos #include "proc.h" 23 1.1 christos 24 1.1 christos 25 1.1 christos /* 26 1.1 christos * Description: Convert a NULL string terminated UNIX environment block to 27 1.1 christos * an environment block suitable for a windows32 system call 28 1.1 christos * 29 1.1 christos * Returns: TRUE= success, FALSE=fail 30 1.1 christos * 31 1.1 christos * Notes/Dependencies: the environment block is sorted in case-insensitive 32 1.1 christos * order, is double-null terminated, and is a char *, not a char ** 33 1.1 christos */ 34 1.1 christos int _cdecl compare(const void *a1, const void *a2) 35 1.1 christos { 36 1.1 christos return _stricoll(*((char**)a1),*((char**)a2)); 37 1.1 christos } 38 1.1 christos bool_t 39 1.1 christos arr2envblk(char **arr, char **envblk_out) 40 1.1 christos { 41 1.1 christos char **tmp; 42 1.1 christos int size_needed; 43 1.1 christos int arrcnt; 44 1.1 christos char *ptr; 45 1.1 christos 46 1.1 christos arrcnt = 0; 47 1.1 christos while (arr[arrcnt]) { 48 1.1 christos arrcnt++; 49 1.1 christos } 50 1.1 christos 51 1.1 christos tmp = (char**) calloc(arrcnt + 1, sizeof(char *)); 52 1.1 christos if (!tmp) { 53 1.1 christos return FALSE; 54 1.1 christos } 55 1.1 christos 56 1.1 christos arrcnt = 0; 57 1.1 christos size_needed = 0; 58 1.1 christos while (arr[arrcnt]) { 59 1.1 christos tmp[arrcnt] = arr[arrcnt]; 60 1.1 christos size_needed += strlen(arr[arrcnt]) + 1; 61 1.1 christos arrcnt++; 62 1.1 christos } 63 1.1 christos size_needed++; 64 1.1 christos 65 1.1 christos qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare); 66 1.1 christos 67 1.1 christos ptr = *envblk_out = calloc(size_needed, 1); 68 1.1 christos if (!ptr) { 69 1.1 christos free(tmp); 70 1.1 christos return FALSE; 71 1.1 christos } 72 1.1 christos 73 1.1 christos arrcnt = 0; 74 1.1 christos while (tmp[arrcnt]) { 75 1.1 christos strcpy(ptr, tmp[arrcnt]); 76 1.1 christos ptr += strlen(tmp[arrcnt]) + 1; 77 1.1 christos arrcnt++; 78 1.1 christos } 79 1.1 christos 80 1.1 christos free(tmp); 81 1.1 christos return TRUE; 82 1.1 christos } 83