|
|
d37adb |
/********************************************************/
|
|
|
d37adb |
/* ntapi: Native API core library */
|
|
|
d37adb |
/* Copyright (C) 2013--2016 Z. Gilboa */
|
|
|
d37adb |
/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
|
|
|
d37adb |
/********************************************************/
|
|
|
d37adb |
|
|
|
d37adb |
#include <psxtypes/psxtypes.h>
|
|
|
d37adb |
#include <ntcon/ntcon.h>
|
|
|
d37adb |
#include <ntapi/ntapi.h>
|
|
|
d37adb |
#include "ntapi_impl.h"
|
|
|
d37adb |
|
|
|
d37adb |
static int32_t __ntapi_tt_open_utf8(
|
|
|
d37adb |
void ** hfile,
|
|
|
d37adb |
void * hat,
|
|
|
d37adb |
const char * arg,
|
|
|
d37adb |
uint32_t options,
|
|
|
d37adb |
int fprivate,
|
|
|
d37adb |
wchar16_t * buffer,
|
|
|
d37adb |
uint32_t buflen)
|
|
|
d37adb |
{
|
|
|
d37adb |
int32_t status;
|
|
|
d37adb |
nt_oa oa;
|
|
|
d37adb |
nt_iosb iosb;
|
|
|
d37adb |
nt_unicode_string path;
|
|
|
d37adb |
nt_unicode_conversion_params_utf8_to_utf16 params = {0,0,0,0,0,0,0,0,0};
|
|
|
d37adb |
wchar16_t * wch;
|
|
|
d37adb |
size_t nbytes;
|
|
|
d37adb |
|
|
|
d37adb |
/* utf-8 --> utf-16 */
|
|
|
d37adb |
params.src = (const unsigned char *)arg;
|
|
|
d37adb |
params.src_size_in_bytes = __ntapi->tt_string_null_offset_multibyte(arg);
|
|
|
d37adb |
params.dst = buffer;
|
|
|
d37adb |
params.dst_size_in_bytes = buflen;
|
|
|
d37adb |
|
|
|
d37adb |
if ((status = __ntapi->uc_convert_unicode_stream_utf8_to_utf16(¶ms)))
|
|
|
d37adb |
return status;
|
|
|
d37adb |
|
|
|
d37adb |
/* convenience */
|
|
|
d37adb |
for (wch=buffer, nbytes=params.bytes_written; nbytes; ) {
|
|
|
d37adb |
if (*wch == '/')
|
|
|
d37adb |
*wch = '\\';
|
|
|
d37adb |
|
|
|
d37adb |
nbytes -= sizeof(wchar16_t);
|
|
|
d37adb |
wch++;
|
|
|
d37adb |
}
|
|
|
d37adb |
|
|
|
d37adb |
/* path */
|
|
|
d37adb |
path.maxlen = 0;
|
|
|
d37adb |
path.strlen = (uint16_t)params.bytes_written;
|
|
|
d37adb |
path.buffer = buffer;
|
|
|
d37adb |
|
|
|
d37adb |
/* oa */
|
|
|
d37adb |
oa.len = sizeof(nt_oa);
|
|
|
d37adb |
oa.root_dir = (buffer[0]=='\\') ? 0 : hat;
|
|
|
d37adb |
oa.obj_name = &pat;;
|
|
|
d37adb |
oa.obj_attr = fprivate ? 0 : NT_OBJ_INHERIT;
|
|
|
d37adb |
oa.sec_desc = 0;
|
|
|
d37adb |
oa.sec_qos = 0;
|
|
|
d37adb |
|
|
|
d37adb |
/* open */
|
|
|
d37adb |
return __ntapi->zw_open_file(
|
|
|
d37adb |
hfile,
|
|
|
d37adb |
NT_SEC_SYNCHRONIZE | NT_FILE_READ_ATTRIBUTES | NT_FILE_READ_DATA,
|
|
|
d37adb |
&oa,&iosb,
|
|
|
d37adb |
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE | NT_FILE_SHARE_DELETE,
|
|
|
d37adb |
options | NT_FILE_SYNCHRONOUS_IO_ALERT);
|
|
|
d37adb |
}
|
|
|
d37adb |
|
|
|
d37adb |
int32_t __ntapi_tt_open_file_utf8(
|
|
|
d37adb |
void ** hfile,
|
|
|
d37adb |
void * hat,
|
|
|
d37adb |
const char * arg,
|
|
|
d37adb |
int fprivate,
|
|
|
d37adb |
wchar16_t * buffer,
|
|
|
d37adb |
uint32_t buflen)
|
|
|
d37adb |
{
|
|
|
d37adb |
return __ntapi_tt_open_utf8(
|
|
|
d37adb |
hfile,hat,arg,
|
|
|
d37adb |
NT_FILE_NON_DIRECTORY_FILE,
|
|
|
d37adb |
fprivate,buffer,buflen);
|
|
|
d37adb |
}
|
|
|
d37adb |
|
|
|
d37adb |
int32_t __ntapi_tt_open_dir_utf8(
|
|
|
d37adb |
void ** hfile,
|
|
|
d37adb |
void * hat,
|
|
|
d37adb |
const char * arg,
|
|
|
d37adb |
int fprivate,
|
|
|
d37adb |
wchar16_t * buffer,
|
|
|
d37adb |
uint32_t buflen)
|
|
|
d37adb |
{
|
|
|
d37adb |
return __ntapi_tt_open_utf8(
|
|
|
d37adb |
hfile,hat,arg,
|
|
|
d37adb |
NT_FILE_DIRECTORY_FILE,
|
|
|
d37adb |
fprivate,buffer,buflen);
|
|
|
d37adb |
}
|