Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/w32/subproc/misc.c

    r2591 r3140  
    11/* 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.
     2Copyright (C) 1996-2016 Free Software Foundation, Inc.
    43This file is part of GNU Make.
    54
     
    2625/*
    2726 * Description:  Convert a NULL string terminated UNIX environment block to
    28  *              an environment block suitable for a windows32 system call
     27 *              an environment block suitable for a windows32 system call
    2928 *
    3029 * Returns:  TRUE= success, FALSE=fail
    3130 *
    3231 * Notes/Dependencies:  the environment block is sorted in case-insensitive
    33  *      order, is double-null terminated, and is a char *, not a char **
     32 *      order, is double-null terminated, and is a char *, not a char **
    3433 */
    3534int _cdecl compare(const void *a1, const void *a2)
    3635{
    37         return _stricoll(*((char**)a1),*((char**)a2));
     36        return _stricoll(*((char**)a1),*((char**)a2));
    3837}
    3938bool_t
    40 arr2envblk(char **arr, char **envblk_out)
     39arr2envblk(char **arr, char **envblk_out, int *envsize_needed)
    4140{
    42         char **tmp;
    43         int size_needed;
    44         int arrcnt;
    45         char *ptr;
     41        char **tmp;
     42        int size_needed;
     43        int arrcnt;
     44        char *ptr;
    4645
    47         arrcnt = 0;
    48         while (arr[arrcnt]) {
    49                 arrcnt++;
    50         }
     46        arrcnt = 0;
     47        while (arr[arrcnt]) {
     48                arrcnt++;
     49        }
    5150
    52         tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
    53         if (!tmp) {
    54                 return FALSE;
    55         }
     51        tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
     52        if (!tmp) {
     53                return FALSE;
     54        }
    5655
    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++;
     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;
    6565
    66         qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
     66        qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
    6767
    68         ptr = *envblk_out = calloc(size_needed, 1);
    69         if (!ptr) {
    70                 free(tmp);
    71                 return FALSE;
    72         }
     68        ptr = *envblk_out = calloc(size_needed, 1);
     69        if (!ptr) {
     70                free(tmp);
     71                return FALSE;
     72        }
    7373
    74         arrcnt = 0;
    75         while (tmp[arrcnt]) {
    76                 strcpy(ptr, tmp[arrcnt]);
    77                 ptr += strlen(tmp[arrcnt]) + 1;
    78                 arrcnt++;
    79         }
     74        arrcnt = 0;
     75        while (tmp[arrcnt]) {
     76                strcpy(ptr, tmp[arrcnt]);
     77                ptr += strlen(tmp[arrcnt]) + 1;
     78                arrcnt++;
     79        }
    8080
    81         free(tmp);
    82         return TRUE;
     81        free(tmp);
     82        return TRUE;
    8383}
Note: See TracChangeset for help on using the changeset viewer.