finished the inital fio routines
This commit is contained in:
278
ase/lib/cmn/fio.c
Normal file
278
ase/lib/cmn/fio.c
Normal file
@ -0,0 +1,278 @@
|
||||
/*
|
||||
* $Id: fio.c,v 1.23 2006/06/30 04:18:47 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/cmn/fio.h>
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#if defined(ASE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
ase_fio_t* ase_fio_open (
|
||||
ase_mmgr_t* mmgr, ase_size_t ext,
|
||||
const ase_char_t* path, int flags, int mode)
|
||||
{
|
||||
ase_fio_t* fio;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
fio = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_fio_t) + ext);
|
||||
if (fio == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_fio_init (fio, mmgr, path, flags, mode) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, fio);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return fio;
|
||||
}
|
||||
|
||||
void ase_fio_close (ase_fio_t* fio)
|
||||
{
|
||||
ase_fio_fini (fio);
|
||||
ASE_MMGR_FREE (fio->mmgr, fio);
|
||||
}
|
||||
|
||||
ase_fio_t* ase_fio_init (
|
||||
ase_fio_t* fio, ase_mmgr_t* mmgr,
|
||||
const ase_char_t* path, int flags, int mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD desired_access = 0;
|
||||
DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
DWORD creation_disposition = 0;
|
||||
DWORD attributes = FILE_ATTRIBUTE_NORMAL;
|
||||
DWORD file_type;
|
||||
#else
|
||||
int desired_access = 0;
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
const ase_mchar_t* path_mb;
|
||||
#else
|
||||
ase_mchar_t path_mb[PATH_MAX + 1];
|
||||
#endif /* ASE_CHAR_IS_MCHAR */
|
||||
#endif /* _WIN32 */
|
||||
ase_fio_hnd_t handle;
|
||||
|
||||
ASE_MEMSET (fio, 0, ASE_SIZEOF(*fio));
|
||||
fio->mmgr = mmgr;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (flags & ASE_FIO_HANDLE)
|
||||
{
|
||||
handle = *(ase_fio_hnd_t*)path;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flags & ASE_FIO_READ) desired_access |= GENERIC_READ;
|
||||
if (flags & ASE_FIO_WRITE) desired_access |= GENERIC_WRITE;
|
||||
if (flags & ASE_FIO_APPEND)
|
||||
{
|
||||
/* this is not officialy documented for CreateFile.
|
||||
* ZwCreateFile (kernel) seems to document it */
|
||||
desired_access |= FILE_APPEND_DATA;
|
||||
}
|
||||
|
||||
if (flags & ASE_FIO_CREATE)
|
||||
{
|
||||
creation_disposition =
|
||||
(flags & ASE_FIO_EXCLUSIVE)? CREATE_NEW:
|
||||
(flags & ASE_FIO_TRUNCATE)? CREATE_ALWAYS: OPEN_ALWAYS;
|
||||
}
|
||||
else if (flags & ASE_FIO_TRUNCATE)
|
||||
{
|
||||
creation_disposition = TRUNCATE_EXISTING;
|
||||
}
|
||||
else creation_disposition = OPEN_EXISTING;
|
||||
|
||||
if (flags & ASE_FIO_NOSHRD) share_mode &= ~FILE_SHARE_READ;
|
||||
if (flags & ASE_FIO_NOSHWR) share_mode &= ~FILE_SHARE_WRITE;
|
||||
|
||||
if (flags & ASE_FIO_SYNC) attributes |= FILE_FLAG_WRITE_THROUGH;
|
||||
|
||||
/* TODO: handle mode... set attribuets */
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = CreateFile (path,
|
||||
desired_access, share_mode, ASE_NULL,
|
||||
creation_disposition, attributes, 0);
|
||||
}
|
||||
|
||||
if (handle == INVALID_HANDLE) return ASE_NULL;
|
||||
|
||||
file_type = GetFileType(handle);
|
||||
if (file_type == FILE_TYPE_UNKNOWN)
|
||||
{
|
||||
CloseHandle (handle);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
/* TODO: a lot more */
|
||||
#else
|
||||
|
||||
if (flags & ASE_FIO_HANDLE)
|
||||
{
|
||||
handle = *(ase_fio_hnd_t*)path;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
path_mb = path;
|
||||
#else
|
||||
if (ase_wcstombs_strict (path,
|
||||
path_mb, ASE_COUNTOF(path_mb)) == -1) return ASE_NULL;
|
||||
#endif
|
||||
|
||||
if (flags & ASE_FIO_READ) desired_access = O_RDONLY;
|
||||
if (flags & ASE_FIO_WRITE)
|
||||
{
|
||||
if (desired_access == 0) desired_access |= O_WRONLY;
|
||||
else desired_access = O_RDWR;
|
||||
}
|
||||
|
||||
if (flags & ASE_FIO_APPEND) desired_access |= O_APPEND;
|
||||
if (flags & ASE_FIO_CREATE) desired_access |= O_CREAT;
|
||||
if (flags & ASE_FIO_TRUNCATE) desired_access |= O_TRUNC;
|
||||
if (flags & ASE_FIO_EXCLUSIVE) desired_access |= O_EXCL;
|
||||
if (flags & ASE_FIO_SYNC) desired_access |= O_SYNC;
|
||||
|
||||
#if defined(O_LARGEFILE)
|
||||
desired_access |= O_LARGEFILE;
|
||||
#endif
|
||||
|
||||
#ifdef SYS_open
|
||||
handle = syscall (SYS_open, path_mb, desired_access, mode);
|
||||
#else
|
||||
handle = open (path_mb, desired_access, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (handle == -1) return ASE_NULL;
|
||||
|
||||
#endif
|
||||
|
||||
fio->handle = handle;
|
||||
return fio;
|
||||
}
|
||||
|
||||
void ase_fio_fini (ase_fio_t* fio)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CloseHandle (fio->handle);
|
||||
#else
|
||||
#if defined(SYS_close)
|
||||
syscall (SYS_close, fio->handle);
|
||||
#else
|
||||
close (fio->handle);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_fio_hnd_t ase_fio_gethandle (ase_fio_t* fio)
|
||||
{
|
||||
return fio->handle;
|
||||
}
|
||||
|
||||
ase_fio_off_t ase_fio_seek (
|
||||
ase_fio_t* fio, ase_fio_off_t offset, ase_fio_ori_t origin)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static int __seek_map[] =
|
||||
{
|
||||
FILE_BEGIN,
|
||||
FILE_CURRENT,
|
||||
FILE_END
|
||||
};
|
||||
LARGE_INTEGER x, y;
|
||||
|
||||
ASE_ASSERT (AES_SIZEOF(offset) <= AES_SIZEOF(x.QuadPart));
|
||||
|
||||
x.QuadPart = offset;
|
||||
if (SetFilePointerEx (
|
||||
fio->handle, x, &y, __seek_map[origin]) == FALSE) return -1;
|
||||
|
||||
return (ase_fio_off_t)y.QuadPart;
|
||||
|
||||
#else
|
||||
static int __seek_map[] =
|
||||
{
|
||||
SEEK_SET,
|
||||
SEEK_CUR,
|
||||
SEEK_END
|
||||
};
|
||||
|
||||
#if !defined(_LP64) && defined(SYS__llseek)
|
||||
loff_t tmp;
|
||||
|
||||
if (syscall (SYS__llseek, fio->handle,
|
||||
(unsigned long)(offset>>32),
|
||||
(unsigned long)(offset&0xFFFFFFFFlu),
|
||||
&tmp,
|
||||
__seek_map[origin]) == -1) return -1;
|
||||
|
||||
return tmp;
|
||||
|
||||
#elif defined(SYS_lseek)
|
||||
return syscall (SYS_lseek, fio->handle, offset, __seek_map[origin]);
|
||||
#elif !defined(_LP64) && defined(HAVE_LSEEK64)
|
||||
return lseek64 (fio->handle, offset, __seek_map[origin]);
|
||||
#else
|
||||
return lseek (fio->handle, offset, __seek_map[origin]);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_ssize_t ase_fio_read (ase_fio_t* fio, void* buf, ase_size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD count;
|
||||
if (size > ASE_TYPE_MAX(DWORD)) size = ASE_TYPE_MAX(DWORD);
|
||||
if (ReadFile(handle, buf, size, &count, ASE_NULL) == FALSE) return -1;
|
||||
return (ase_ssize_t)count;
|
||||
#else
|
||||
if (size > ASE_TYPE_MAX(size_t)) size = ASE_TYPE_MAX(size_t);
|
||||
#ifdef SYS_read
|
||||
return syscall (SYS_read, fio->handle, buf, size);
|
||||
#else
|
||||
return read (fio->handle, buf, size);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_ssize_t ase_fio_write (ase_fio_t* fio, const void* data, ase_size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD count;
|
||||
if (size > ASE_TYPE_MAX(DWORD)) size = ASE_TYPE_MAX(DWORD);
|
||||
if (WriteFile(handle, buf, &count, ASE_NULL) == FALSE) return -1;
|
||||
return (ase_ssize_t)count;
|
||||
#else
|
||||
if (size > ASE_TYPE_MAX(size_t)) size = ASE_TYPE_MAX(size_t);
|
||||
#ifdef SYS_write
|
||||
return syscall (SYS_write, fio->handle, data, size);
|
||||
#else
|
||||
return write (fio->handle, data, size);
|
||||
#endif
|
||||
#endif
|
||||
}
|
267
ase/lib/cmn/io.c
267
ase/lib/cmn/io.c
@ -1,267 +0,0 @@
|
||||
/*
|
||||
* $Id: sysapi.c,v 1.45 2007/06/20 14:54:11 baconevi Exp $
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
static int handle_map_inited = 0;
|
||||
static ase_map_t handle_map;
|
||||
#endif
|
||||
|
||||
|
||||
ase_hnd_t ase_open (const ase_char_t* path, int flags, ...)
|
||||
{
|
||||
ase_hnd_t handle;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
DWORD desired_access = 0;
|
||||
DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
DWORD creation_disposition = 0;
|
||||
DWORD attributes = FILE_ATTRIBUTE_NORMAL;
|
||||
DWORD file_type;
|
||||
|
||||
if (!handle_map_inited)
|
||||
{
|
||||
ase_map_init (&handle_map, ...);
|
||||
handle_map_inited = 1;
|
||||
}
|
||||
|
||||
if (flags & ASE_OPEN_READ) desired_access |= GENERIC_READ;
|
||||
if (flags & ASE_OPEN_WRITE) desired_access |= GENERIC_WRITE;
|
||||
|
||||
if (flags & ASE_OPEN_CREATE)
|
||||
{
|
||||
creation_disposition =
|
||||
(flags & ASE_OPEN_EXCLUSIVE)? CREATE_NEW:
|
||||
(flags & ASE_OPEN_TRUNCATE)? CREATE_ALWAYS: OPEN_ALWAYS;
|
||||
}
|
||||
else if (flags & ASE_OPEN_TRUNCATE)
|
||||
{
|
||||
creation_disposition = TRUNCATE_EXISTING;
|
||||
}
|
||||
else creation_disposition = OPEN_EXISTING;
|
||||
|
||||
/*if (flags & ASE_FIO_SYNC) attributes |= FILE_FLAG_WRITE_THROUGH; */
|
||||
/* TODO: share mode */
|
||||
|
||||
handle = CreateFile (path,
|
||||
desired_access, share_mode, ASE_NULL,
|
||||
creation_disposition, attributes, 0);
|
||||
if (handle == ASE_HND_INVALID) return ASE_HND_INVALID;
|
||||
|
||||
/* TODO: improve append */
|
||||
if (flags & ASE_OPEN_APPEND)
|
||||
{
|
||||
/*fio->flags |= ASE_OPEN_APPEND;*/
|
||||
if (ase_seek (handle, 0, ASE_SEEK_END) == -1)
|
||||
{
|
||||
CloseHandle (handle);
|
||||
return ASE_HND_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: implement nonblock...
|
||||
if (flags & ASE_OPEN_NONBLOCK) desired_access |= O_NONBLOCK;
|
||||
*/
|
||||
|
||||
file_type = GetFileType(handle);
|
||||
if (file_type == FILE_TYPE_UNKNOWN)
|
||||
{
|
||||
CloseHandle (handle);
|
||||
return ASE_HND_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
if (file_type == FILE_TYPE_CHAR)
|
||||
else if (file_type == FILE_TYPE_PIPE)
|
||||
*/
|
||||
/* TODO: a lot more */
|
||||
|
||||
#else
|
||||
int desired_access = 0;
|
||||
ase_va_list arg;
|
||||
ase_mode_t mode;
|
||||
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
const ase_mchar_t* path_mb;
|
||||
#else
|
||||
ase_mchar_t path_mb[ASE_PATH_MAX + 1];
|
||||
#endif
|
||||
|
||||
ase_va_start (arg, flags);
|
||||
if (ase_sizeof(ase_mode_t) < ase_sizeof(int))
|
||||
mode = ase_va_arg (arg, int);
|
||||
else
|
||||
mode = ase_va_arg (arg, ase_mode_t);
|
||||
ase_va_end (arg);
|
||||
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
path_mb = path;
|
||||
#else
|
||||
if (ase_wcstomcs_strict (
|
||||
path, path_mb, ase_countof(path_mb)) == -1) return -1;
|
||||
#endif
|
||||
|
||||
if (flags & ASE_OPEN_READ) desired_access = O_RDONLY;
|
||||
if (flags & ASE_OPEN_WRITE) {
|
||||
if (desired_access == 0) desired_access |= O_WRONLY;
|
||||
else desired_access = O_RDWR;
|
||||
}
|
||||
|
||||
if (flags & ASE_OPEN_APPEND) desired_access |= O_APPEND;
|
||||
if (flags & ASE_OPEN_CREATE) desired_access |= O_CREAT;
|
||||
if (flags & ASE_OPEN_TRUNCATE) desired_access |= O_TRUNC;
|
||||
if (flags & ASE_OPEN_EXCLUSIVE) desired_access |= O_EXCL;
|
||||
if (flags & ASE_OPEN_NONBLOCK) desired_access |= O_NONBLOCK;
|
||||
|
||||
handle = open (path_mb, desired_access, mode);
|
||||
#endif
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
int ase_close (ase_hnd_t handle)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (CloseHandle(handle) == FALSE) return -1;
|
||||
return 0;
|
||||
#else
|
||||
return close (handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_ssize_t ase_read (ase_hnd_t handle, void* buf, ase_size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
DWORD bytes_read;
|
||||
ase_size_t n = 0;
|
||||
ase_byte_t* p = (ase_byte_t*)buf;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (size <= ASE_TYPE_MAX(DWORD))
|
||||
{
|
||||
if (ReadFile(handle, p, size,
|
||||
&bytes_read, ASE_NULL) == FALSE) return -1;
|
||||
n += bytes_read;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ReadFile(handle, p, ASE_TYPE_MAX(DWORD),
|
||||
&bytes_read, ASE_NULL) == FALSE) return -1;
|
||||
if (bytes_read == 0) break; /* reached the end of a file */
|
||||
|
||||
p += bytes_read;
|
||||
n += bytes_read;
|
||||
size -= bytes_read;
|
||||
}
|
||||
|
||||
return (ase_ssize_t)n;
|
||||
|
||||
#else
|
||||
return read (handle, buf, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_ssize_t ase_write (ase_hnd_t handle, const void* data, ase_size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
DWORD bytes_written;
|
||||
ase_size_t n = 0;
|
||||
const ase_byte_t* p = (const ase_byte_t*)data;
|
||||
|
||||
/* TODO:...
|
||||
if (fio->flags & ASE_OPEN_APPEND)
|
||||
{
|
||||
if (ase_seek (handle, 0, ASE_SEEK_END) == -1) return -1;
|
||||
}*/
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (size <= ASE_TYPE_MAX(DWORD))
|
||||
{
|
||||
if (WriteFile(handle, p, size,
|
||||
&bytes_written, ASE_NULL) == FALSE) return -1;
|
||||
n += bytes_written;
|
||||
break;
|
||||
}
|
||||
|
||||
if (WriteFile(handle, p, ASE_TYPE_MAX(DWORD),
|
||||
&bytes_written, ASE_NULL) == FALSE) return -1;
|
||||
if (bytes_written == 0) break;
|
||||
|
||||
p += bytes_written;
|
||||
n += bytes_written;
|
||||
size -= bytes_written;
|
||||
}
|
||||
|
||||
return (ase_ssize_t)n;
|
||||
|
||||
#else
|
||||
return write (handle, data, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_off_t ase_seek (ase_hnd_t handle, ase_off_t offset, int origin)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
static int __seek_map[] =
|
||||
{
|
||||
FILE_BEGIN,
|
||||
FILE_CURRENT,
|
||||
FILE_END
|
||||
};
|
||||
LARGE_INTEGER x, y;
|
||||
|
||||
ase_assert (ase_sizeof(offset) <= ase_sizeof(x.QuadPart));
|
||||
|
||||
x.QuadPart = offset;
|
||||
if (SetFilePointerEx (
|
||||
handle, x, &y, __seek_map[origin]) == FALSE) return -1;
|
||||
|
||||
return (ase_off_t)y.QuadPart;
|
||||
|
||||
#else
|
||||
|
||||
static int __seek_map[] =
|
||||
{
|
||||
SEEK_SET,
|
||||
SEEK_CUR,
|
||||
SEEK_END
|
||||
};
|
||||
|
||||
return lseek (handle, offset, __seek_map[origin]);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int ase_htruncate (ase_hnd_t handle, ase_off_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifndef INVALID_SET_FILE_POINTER
|
||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
/* TODO: support lsDistanceToMoveHigh (high 32bits of 64bit offset) */
|
||||
if (SetFilePointer(
|
||||
handle,0,NULL,FILE_CURRENT) == INVALID_SET_FILE_POINTER ||
|
||||
SetFilePointer(
|
||||
handle,size,NULL,FILE_BEGIN) == INVALID_SET_FILE_POINTER ||
|
||||
SetEndOfFile(handle) == FALSE) return -1;
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return ftruncate (handle, size);
|
||||
#endif
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ lib_LTLIBRARIES = libasecmn.la
|
||||
libasecmn_la_SOURCES = mem.h chr.h \
|
||||
mem.c chr.c chr_cnv.c rex.c str_bas.c str_cnv.c str_dyn.c \
|
||||
lda.c map.c sll.c dll.c opt.c \
|
||||
tio.c tio_get.c tio_put.c \
|
||||
fio.c sio.c tio.c tio_get.c tio_put.c \
|
||||
misc.c
|
||||
libasecmn_la_LDFLAGS = -version-info 1:0:0
|
||||
|
||||
|
@ -53,7 +53,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libasecmn_la_LIBADD =
|
||||
am_libasecmn_la_OBJECTS = mem.lo chr.lo chr_cnv.lo rex.lo str_bas.lo \
|
||||
str_cnv.lo str_dyn.lo lda.lo map.lo sll.lo dll.lo opt.lo \
|
||||
tio.lo tio_get.lo tio_put.lo misc.lo
|
||||
fio.lo sio.lo tio.lo tio_get.lo tio_put.lo misc.lo
|
||||
libasecmn_la_OBJECTS = $(am_libasecmn_la_OBJECTS)
|
||||
libasecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -203,7 +203,7 @@ lib_LTLIBRARIES = libasecmn.la
|
||||
libasecmn_la_SOURCES = mem.h chr.h \
|
||||
mem.c chr.c chr_cnv.c rex.c str_bas.c str_cnv.c str_dyn.c \
|
||||
lda.c map.c sll.c dll.c opt.c \
|
||||
tio.c tio_get.c tio_put.c \
|
||||
fio.c sio.c tio.c tio_get.c tio_put.c \
|
||||
misc.c
|
||||
|
||||
libasecmn_la_LDFLAGS = -version-info 1:0:0
|
||||
@ -279,12 +279,14 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr_cnv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dll.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/map.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rex.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_bas.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_cnv.Plo@am__quote@
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_cnv.c 432 2008-10-20 11:22:02Z baconevi $
|
||||
* $Id: str_cnv.c 455 2008-11-26 09:05:00Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -180,7 +180,7 @@ ase_size_t ase_wcstombs (
|
||||
const ase_wchar_t* p = wcs;
|
||||
ase_size_t rem = *mbslen;
|
||||
|
||||
while (*p != ASE_T('\0') && rem > 1)
|
||||
while (*p != ASE_WT('\0') && rem > 1)
|
||||
{
|
||||
ase_size_t n = ase_wctomb (*p, mbs, rem);
|
||||
if (n == 0 || n > rem)
|
||||
@ -236,3 +236,21 @@ ase_size_t ase_wcsntombsn (
|
||||
return p - wcs;
|
||||
}
|
||||
|
||||
int ase_wcstombs_strict (
|
||||
const ase_wchar_t* wcs, ase_mchar_t* mbs, ase_size_t mbslen)
|
||||
{
|
||||
ase_size_t n;
|
||||
ase_size_t mn = mbslen;
|
||||
|
||||
n = ase_wcstombs (wcs, mbs, &mn);
|
||||
if (wcs[n] != ASE_WT('\0')) return -1; /* didn't process all */
|
||||
if (mn >= mbslen)
|
||||
{
|
||||
/* mbs not big enough to be null-terminated.
|
||||
* if it has been null-terminated properly,
|
||||
* mn should be less than mbslen. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user