Blame src/argv/ntapi_tt_env_vars.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_get_env_var_meta_utf16(
dd89bb
	__in	wchar16_t *		env_var_name,
dd89bb
	__in	wchar16_t **		envp,
dd89bb
	__out	nt_env_var_meta_utf16 *	env_var_meta)
dd89bb
{
dd89bb
	int		idx;
dd89bb
	wchar16_t *	wch;
dd89bb
f7b999
	#define EQUAL_SIGN 0x3D
dd89bb
f7b999
	/* init */
f7b999
	env_var_meta->name       = 0;
f7b999
	env_var_meta->value      = 0;
f7b999
	env_var_meta->envp_index = 0;
f7b999
	env_var_meta->flags      = 0;
dd89bb
f7b999
	/* lookup */
f7b999
	for (idx=0; envp[idx] && !env_var_meta->value; idx++) {
dd89bb
		wch = envp[idx];
dd89bb
f7b999
		while (*wch && (*wch != EQUAL_SIGN))
dd89bb
			wch++;
dd89bb
dd89bb
		if (*wch != EQUAL_SIGN)
dd89bb
			return NT_STATUS_ILLEGAL_CHARACTER;
dd89bb
f7b999
		if (!(__ntapi->tt_strncmp_utf16(
f7b999
				envp[idx],
f7b999
				env_var_name,
f7b999
				wch - envp[idx]))) {
dd89bb
			wch++;
f7b999
			env_var_meta->name       = envp[idx];
f7b999
			env_var_meta->value      = wch;
dd89bb
			env_var_meta->envp_index = idx;
dd89bb
		}
dd89bb
	}
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}