Ensure variables defined in $(call ...) have global scope
[make.git] / w32 / subproc / misc.c
blob6759c1770d2be6b27c93c8028679d4176ca767e8
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.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation; either version 3 of the License, or (at your option) any later
9 version.
11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include <config.h>
19 #include <stddef.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <windows.h>
23 #include "proc.h"
27 * Description: Convert a NULL string terminated UNIX environment block to
28 * an environment block suitable for a windows32 system call
30 * Returns: TRUE= success, FALSE=fail
32 * Notes/Dependencies: the environment block is sorted in case-insensitive
33 * order, is double-null terminated, and is a char *, not a char **
35 int _cdecl compare(const void *a1, const void *a2)
37 return _stricoll(*((char**)a1),*((char**)a2));
39 bool_t
40 arr2envblk(char **arr, char **envblk_out)
42 char **tmp;
43 int size_needed;
44 int arrcnt;
45 char *ptr;
47 arrcnt = 0;
48 while (arr[arrcnt]) {
49 arrcnt++;
52 tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
53 if (!tmp) {
54 return FALSE;
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++;
64 size_needed++;
66 qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
68 ptr = *envblk_out = calloc(size_needed, 1);
69 if (!ptr) {
70 free(tmp);
71 return FALSE;
74 arrcnt = 0;
75 while (tmp[arrcnt]) {
76 strcpy(ptr, tmp[arrcnt]);
77 ptr += strlen(tmp[arrcnt]) + 1;
78 arrcnt++;
81 free(tmp);
82 return TRUE;