Blame src/argv/ntapi_tt_env_vars.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
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
a40312
int32_t __stdcall __ntapi_tt_get_env_var_meta_utf8(
a40312
	__in	char *			env_var_name,
a40312
	__in	char **			envp,
a40312
	__out	nt_env_var_meta_utf8 *	env_var_meta)
a40312
{
a40312
	char **		penv;
a40312
	char *		ch;
a40312
a40312
	/* lookup */
a40312
	for (penv=envp; *penv; penv++) {
a40312
		for (ch=penv[0]; *ch && (*ch != '='); )
a40312
			ch++;
a40312
a40312
		if (*ch != '=')
a40312
			return NT_STATUS_INVALID_USER_BUFFER;
a40312
a40312
		if ((ch > *penv) && !(__ntapi->tt_strncmp_multibyte(
a40312
				*penv,
a40312
				env_var_name,
a40312
				ch - *penv))) {
a40312
			/* match */
a40312
			env_var_meta->name       = *penv;
a40312
			env_var_meta->value      = ++ch;
a40312
			env_var_meta->envp_index = penv - envp;
a40312
			env_var_meta->flags      = 0;
a40312
a40312
			return NT_STATUS_SUCCESS;
a40312
		}
a40312
	}
a40312
a40312
	return NT_STATUS_NOT_FOUND;
a40312
}
a40312
a40312
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
{
ed1da2
	wchar16_t **	penv;
dd89bb
	wchar16_t *	wch;
dd89bb
f7b999
	/* lookup */
ed1da2
	for (penv=envp; *penv; penv++) {
ed1da2
		for (wch=penv[0]; *wch && (*wch != '='); )
dd89bb
			wch++;
dd89bb
ed1da2
		if (*wch != '=')
ed1da2
			return NT_STATUS_INVALID_USER_BUFFER;
dd89bb
ed1da2
		if ((wch > *penv) && !(__ntapi->tt_strncmp_utf16(
ed1da2
				*penv,
f7b999
				env_var_name,
ed1da2
				wch - *penv))) {
ed1da2
			/* match */
ed1da2
			env_var_meta->name       = *penv;
ed1da2
			env_var_meta->value      = ++wch;
ed1da2
			env_var_meta->envp_index = penv - envp;
ed1da2
			env_var_meta->flags      = 0;
ed1da2
ed1da2
ed1da2
			return NT_STATUS_SUCCESS;
dd89bb
		}
dd89bb
	}
dd89bb
ed1da2
	return NT_STATUS_NOT_FOUND;
dd89bb
}