VirtualBox

source: kBuild/trunk/src/gmake/w32/subproc/misc.c@ 53

Last change on this file since 53 was 53, checked in by bird, 21 years ago

Initial revision

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1#include <stddef.h>
2#include <stdlib.h>
3#include <string.h>
4#include <windows.h>
5#include "proc.h"
6
7
8/*
9 * Description: Convert a NULL string terminated UNIX environment block to
10 * an environment block suitable for a windows32 system call
11 *
12 * Returns: TRUE= success, FALSE=fail
13 *
14 * Notes/Dependencies: the environment block is sorted in case-insensitive
15 * order, is double-null terminated, and is a char *, not a char **
16 */
17int _cdecl compare(const void *a1, const void *a2)
18{
19 return _stricoll(*((char**)a1),*((char**)a2));
20}
21bool_t
22arr2envblk(char **arr, char **envblk_out)
23{
24 char **tmp;
25 int size_needed;
26 int arrcnt;
27 char *ptr;
28
29 arrcnt = 0;
30 while (arr[arrcnt]) {
31 arrcnt++;
32 }
33
34 tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
35 if (!tmp) {
36 return FALSE;
37 }
38
39 arrcnt = 0;
40 size_needed = 0;
41 while (arr[arrcnt]) {
42 tmp[arrcnt] = arr[arrcnt];
43 size_needed += strlen(arr[arrcnt]) + 1;
44 arrcnt++;
45 }
46 size_needed++;
47
48 qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
49
50 ptr = *envblk_out = calloc(size_needed, 1);
51 if (!ptr) {
52 free(tmp);
53 return FALSE;
54 }
55
56 arrcnt = 0;
57 while (tmp[arrcnt]) {
58 strcpy(ptr, tmp[arrcnt]);
59 ptr += strlen(tmp[arrcnt]) + 1;
60 arrcnt++;
61 }
62
63 free(tmp);
64 return TRUE;
65}
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