VirtualBox

source: kBuild/vendor/gnumake/current/w32/subproc/misc.c

Last change on this file was 3138, checked in by bird, 7 years ago

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

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

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