Update copyrights for 2010.
[make.git] / w32 / subproc / misc.c
blob298db483b06acccb354fc45ff043411295a3aa48
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 <stddef.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <windows.h>
22 #include "proc.h"
26 * Description: Convert a NULL string terminated UNIX environment block to
27 * an environment block suitable for a windows32 system call
29 * Returns: TRUE= success, FALSE=fail
31 * Notes/Dependencies: the environment block is sorted in case-insensitive
32 * order, is double-null terminated, and is a char *, not a char **
34 int _cdecl compare(const void *a1, const void *a2)
36 return _stricoll(*((char**)a1),*((char**)a2));
38 bool_t
39 arr2envblk(char **arr, char **envblk_out)
41 char **tmp;
42 int size_needed;
43 int arrcnt;
44 char *ptr;
46 arrcnt = 0;
47 while (arr[arrcnt]) {
48 arrcnt++;
51 tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
52 if (!tmp) {
53 return FALSE;
56 arrcnt = 0;
57 size_needed = 0;
58 while (arr[arrcnt]) {
59 tmp[arrcnt] = arr[arrcnt];
60 size_needed += strlen(arr[arrcnt]) + 1;
61 arrcnt++;
63 size_needed++;
65 qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
67 ptr = *envblk_out = calloc(size_needed, 1);
68 if (!ptr) {
69 free(tmp);
70 return FALSE;
73 arrcnt = 0;
74 while (tmp[arrcnt]) {
75 strcpy(ptr, tmp[arrcnt]);
76 ptr += strlen(tmp[arrcnt]) + 1;
77 arrcnt++;
80 free(tmp);
81 return TRUE;