static void ___kmp_env_blk_parse_unix( kmp_env_blk_t * block, // M: Env block to fill. char * * env // I: Unix environment to parse. ) { char * bulk = NULL; kmp_env_var_t * vars = NULL; int count = 0; int size = 0; // Size of bulk. // Count number of variables and length of required bulk. { count = 0; size = 0; while ( env[ count ] != NULL ) { size += KMP_STRLEN( env[ count ] ) + 1; ++ count; }; // while } // Allocate memory. bulk = (char *) allocate( size ); vars = (kmp_env_var_t *) allocate( count * sizeof( kmp_env_var_t ) ); // Loop thru all the vars. { char * var; // Pointer to beginning of var. char * name; // Pointer to name of variable. char * value; // Pointer to value. int len; // Length of variable. int i; var = bulk; for ( i = 0; i < count; ++ i ) { // Copy variable to bulk. len = KMP_STRLEN( env[ i ] ); KMP_MEMCPY_S( var, size, env[ i ], len + 1 ); // Save found variable in vars array. __kmp_str_split( var, '=', & name, & value ); vars[ i ].name = name; vars[ i ].value = value; // Move pointer. var += len + 1; }; // for } // Fill out result. block->bulk = bulk; block->vars = vars; block->count = count; }; // ___kmp_env_blk_parse_unix
static void ___kmp_env_blk_parse_windows( kmp_env_blk_t *block, // M: Env block to fill. char const *env // I: Pointer to Windows* OS (DOS) environment block. ) { char *bulk = NULL; kmp_env_var_t *vars = NULL; int count = 0; // Number of used elements in vars array. int size = 0; // Size of bulk. char *name; // Pointer to name of variable. char *value; // Pointer to value. if (env != NULL) { // Loop thru all the vars in environment block. Count variables, find size // of block. { char const *var; // Pointer to beginning of var. int len; // Length of variable. count = 0; var = env; // The first variable starts and beginning of environment block. len = KMP_STRLEN(var); while (len != 0) { ++count; size = size + len + 1; var = var + len + 1; // Move pointer to the beginning of the next variable. len = KMP_STRLEN(var); } size = size + 1; // Total size of env block, including terminating zero byte. } // Copy original block to bulk, we will modify bulk, not original block. bulk = (char *)allocate(size); KMP_MEMCPY_S(bulk, size, env, size); // Allocate vars array. vars = (kmp_env_var_t *)allocate(count * sizeof(kmp_env_var_t)); // Loop thru all the vars, now in bulk. { char *var; // Pointer to beginning of var. int len; // Length of variable. count = 0; var = bulk; len = KMP_STRLEN(var); while (len != 0) { // Save variable in vars array. __kmp_str_split(var, '=', &name, &value); vars[count].name = name; vars[count].value = value; ++count; // Get the next var. var = var + len + 1; len = KMP_STRLEN(var); } } } // Fill out result. block->bulk = bulk; block->vars = vars; block->count = count; }