summaryrefslogtreecommitdiffhomepage
path: root/src/argv/ntapi_tt_env_vars.c
blob: 9c62eb5ad77f7b15545bd24d5f93476709db873e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"

int32_t __stdcall __ntapi_tt_get_env_var_meta_utf16(
	__in	wchar16_t *		env_var_name,
	__in	wchar16_t **		envp,
	__out	nt_env_var_meta_utf16 *	env_var_meta)
{
	int		idx;
	wchar16_t *	wch;

	#define EQUAL_SIGN 0x3D

	/* init */
	env_var_meta->name       = 0;
	env_var_meta->value      = 0;
	env_var_meta->envp_index = 0;
	env_var_meta->flags      = 0;

	/* lookup */
	for (idx=0; envp[idx] && !env_var_meta->value; idx++) {
		wch = envp[idx];

		while (*wch && (*wch != EQUAL_SIGN))
			wch++;

		if (*wch != EQUAL_SIGN)
			return NT_STATUS_ILLEGAL_CHARACTER;

		if (!(__ntapi->tt_strncmp_utf16(
				envp[idx],
				env_var_name,
				wch - envp[idx]))) {
			wch++;
			env_var_meta->name       = envp[idx];
			env_var_meta->value      = wch;
			env_var_meta->envp_index = idx;
		}
	}

	return NT_STATUS_SUCCESS;
}