Blame src/argv/ntapi_tt_array_utf8.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 <pemagine/pemagine.h>
dd89bb
#include <ntapi/nt_argv.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_array_copy_utf8(
dd89bb
	__out	int *			argc,
dd89bb
	__in	const char **		argv,
dd89bb
	__in	const char **		envp,
dd89bb
	__in	const char *		image_name	__optional,
dd89bb
	__in	const char *		interpreter	__optional,
dd89bb
	__in	const char *		optarg		__optional,
dd89bb
	__in	void *			base,
dd89bb
	__out	void *			buffer,
dd89bb
	__in	size_t			buflen,
dd89bb
	__out	size_t *		blklen)
dd89bb
{
dd89bb
	const char **	parg;
dd89bb
	const char *	arg;
dd89bb
	const char *	dummy;
dd89bb
	char *		ch;
dd89bb
	ptrdiff_t	diff;
dd89bb
	ptrdiff_t	ptrs;
dd89bb
	size_t		needed;
dd89bb
dd89bb
	/* fallback */
dd89bb
	dummy = 0;
dd89bb
	argv = argv ? argv : &dummy;
dd89bb
	envp = envp ? envp : &dummy;
dd89bb
dd89bb
	/* ptrs, needed */
dd89bb
	ptrs   = 0;
dd89bb
	needed = 0;
dd89bb
dd89bb
	if (image_name) {
dd89bb
		ptrs++;
dd89bb
		needed += sizeof(char *)
dd89bb
			+ __ntapi->tt_string_null_offset_multibyte(image_name)
dd89bb
			+ sizeof(char);
dd89bb
	}
dd89bb
dd89bb
	for (parg=argv; *parg; parg++)
dd89bb
		needed += sizeof(char *)
dd89bb
			+ __ntapi->tt_string_null_offset_multibyte(*parg)
dd89bb
			+ sizeof(char);
dd89bb
dd89bb
	ptrs += (parg - argv);
dd89bb
	*argc = (int)ptrs;
dd89bb
dd89bb
	for (parg=envp; *parg; parg++)
dd89bb
		needed += sizeof(char *)
dd89bb
			+ __ntapi->tt_string_null_offset_multibyte(*parg)
dd89bb
			+ sizeof(char);
dd89bb
dd89bb
	ptrs += (parg - envp);
dd89bb
dd89bb
	ptrs    += 2;
dd89bb
	needed  += 2*sizeof(char *);
dd89bb
	blklen  = blklen ? blklen : &needed;
dd89bb
	*blklen = needed;
dd89bb
dd89bb
	if (buflen < needed)
dd89bb
		return NT_STATUS_BUFFER_TOO_SMALL;
dd89bb
dd89bb
	/* init */
dd89bb
	parg = (const char **)buffer;
dd89bb
	ch  = (char *)(parg+ptrs);
dd89bb
	diff = (ptrdiff_t)base;
dd89bb
dd89bb
	/* image_name */
dd89bb
	if (image_name) {
dd89bb
		*parg++ = ch-diff;
dd89bb
		for (arg=image_name; *arg; arg++,ch++)
dd89bb
			*ch = *arg;
dd89bb
		*ch++ = '\0';
dd89bb
	}
dd89bb
dd89bb
	/* argv */
dd89bb
	for (; *argv; argv++) {
dd89bb
		*parg++=ch-diff;
dd89bb
		for (arg=*argv; *arg; arg++,ch++)
dd89bb
			*ch = *arg;
dd89bb
		*ch++ = '\0';
dd89bb
	}
dd89bb
dd89bb
	*parg++ = 0;
dd89bb
dd89bb
	/* envp */
dd89bb
	for (; *envp; envp++) {
dd89bb
		*parg++=ch-diff;
dd89bb
		for (arg=*envp; *arg; arg++,ch++)
dd89bb
			*ch = *arg;
dd89bb
		*ch++ = '\0';
dd89bb
	}
dd89bb
dd89bb
	*parg++ = 0;
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}
dd89bb
dd89bb
int32_t __stdcall __ntapi_tt_array_convert_utf8_to_utf16(
dd89bb
	__in		char **		arrv,
dd89bb
	__in		wchar16_t **	arra,
dd89bb
	__in		void *		base,
dd89bb
	__in		wchar16_t *	buffer,
dd89bb
	__in		size_t		buffer_len,
dd89bb
	__out		size_t *	bytes_written)
dd89bb
{
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}