VirtualBox

source: kBuild/trunk/src/kmk/w32/subproc/misc.c@ 2591

Last change on this file since 2591 was 2591, checked in by bird, 13 years ago

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette