finished the inital fio routines
This commit is contained in:
parent
073348b5d4
commit
815dc8c1cd
170
ase/configure
vendored
170
ase/configure
vendored
@ -1494,6 +1494,8 @@ Optional Features:
|
||||
--disable-libtool-lock avoid locking (might break parallel builds)
|
||||
--enable-wchar use wchar_t a default charater type when enabled
|
||||
(default. yes)
|
||||
--enable-syscall use the syscall() function to call system calls
|
||||
(default. no)
|
||||
--enable-debug build the library in the debug mode (default. no)
|
||||
--enable-cxx build the library for C++ if a C++ compiler is
|
||||
available (default. yes)
|
||||
@ -4857,7 +4859,7 @@ ia64-*-hpux*)
|
||||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 4860 "configure"' > conftest.$ac_ext
|
||||
echo '#line 4862 "configure"' > conftest.$ac_ext
|
||||
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
@ -7442,11 +7444,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7445: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7447: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7449: \$? = $ac_status" >&5
|
||||
echo "$as_me:7451: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
@ -7732,11 +7734,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7735: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7737: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7739: \$? = $ac_status" >&5
|
||||
echo "$as_me:7741: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
@ -7836,11 +7838,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7839: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7841: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7843: \$? = $ac_status" >&5
|
||||
echo "$as_me:7845: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@ -10213,7 +10215,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 10216 "configure"
|
||||
#line 10218 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@ -10313,7 +10315,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 10316 "configure"
|
||||
#line 10318 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@ -12714,11 +12716,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:12717: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:12719: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:12721: \$? = $ac_status" >&5
|
||||
echo "$as_me:12723: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
@ -12818,11 +12820,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:12821: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:12823: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:12825: \$? = $ac_status" >&5
|
||||
echo "$as_me:12827: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@ -14416,11 +14418,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:14419: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:14421: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:14423: \$? = $ac_status" >&5
|
||||
echo "$as_me:14425: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
@ -14520,11 +14522,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:14523: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:14525: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:14527: \$? = $ac_status" >&5
|
||||
echo "$as_me:14529: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@ -16740,11 +16742,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:16743: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:16745: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:16747: \$? = $ac_status" >&5
|
||||
echo "$as_me:16749: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
@ -17030,11 +17032,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:17033: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:17035: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:17037: \$? = $ac_status" >&5
|
||||
echo "$as_me:17039: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
@ -17134,11 +17136,11 @@ else
|
||||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:17137: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:17139: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:17141: \$? = $ac_status" >&5
|
||||
echo "$as_me:17143: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
@ -20344,6 +20346,9 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
|
||||
CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE"
|
||||
|
||||
LIBM=
|
||||
case $host in
|
||||
*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
|
||||
@ -20730,7 +20735,8 @@ fi
|
||||
|
||||
|
||||
|
||||
for ac_header in stddef.h wchar.h wctype.h
|
||||
|
||||
for ac_header in stddef.h wchar.h wctype.h sys/syscall.h
|
||||
do
|
||||
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
|
||||
@ -21226,6 +21232,104 @@ fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for ac_func in open64 lseek64 stat64 fstat64 lstat64
|
||||
do
|
||||
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||
echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
|
||||
if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
|
||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
/* confdefs.h. */
|
||||
_ACEOF
|
||||
cat confdefs.h >>conftest.$ac_ext
|
||||
cat >>conftest.$ac_ext <<_ACEOF
|
||||
/* end confdefs.h. */
|
||||
/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
|
||||
For example, HP-UX 11i <limits.h> declares gettimeofday. */
|
||||
#define $ac_func innocuous_$ac_func
|
||||
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char $ac_func (); below.
|
||||
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
|
||||
<limits.h> exists even on freestanding compilers. */
|
||||
|
||||
#ifdef __STDC__
|
||||
# include <limits.h>
|
||||
#else
|
||||
# include <assert.h>
|
||||
#endif
|
||||
|
||||
#undef $ac_func
|
||||
|
||||
/* Override any GCC internal prototype to avoid an error.
|
||||
Use char because int might match the return type of a GCC
|
||||
builtin and then its argument prototype would still apply. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
char $ac_func ();
|
||||
/* The GNU C library defines this for functions which it implements
|
||||
to always fail with ENOSYS. Some functions are actually named
|
||||
something starting with __ and the normal name is an alias. */
|
||||
#if defined __stub_$ac_func || defined __stub___$ac_func
|
||||
choke me
|
||||
#endif
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return $ac_func ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
rm -f conftest.$ac_objext conftest$ac_exeext
|
||||
if { (ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
|
||||
(eval "$ac_link") 2>conftest.er1
|
||||
ac_status=$?
|
||||
grep -v '^ *+' conftest.er1 >conftest.err
|
||||
rm -f conftest.er1
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } && {
|
||||
test -z "$ac_c_werror_flag" ||
|
||||
test ! -s conftest.err
|
||||
} && test -s conftest$ac_exeext &&
|
||||
$as_test_x conftest$ac_exeext; then
|
||||
eval "$as_ac_var=yes"
|
||||
else
|
||||
echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
eval "$as_ac_var=no"
|
||||
fi
|
||||
|
||||
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi
|
||||
ac_res=`eval echo '${'$as_ac_var'}'`
|
||||
{ echo "$as_me:$LINENO: result: $ac_res" >&5
|
||||
echo "${ECHO_T}$ac_res" >&6; }
|
||||
if test `eval echo '${'$as_ac_var'}'` = yes; then
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
{ echo "$as_me:$LINENO: checking for char" >&5
|
||||
echo $ECHO_N "checking for char... $ECHO_C" >&6; }
|
||||
if test "${ac_cv_type_char+set}" = set; then
|
||||
@ -27654,7 +27758,7 @@ else
|
||||
fi
|
||||
|
||||
test "${ac_cv_sizeof_wchar_t}" = "0" && enable_wchar_is=no
|
||||
if test "$enable_wchar_is" = "yes"
|
||||
if test "${enable_wchar_is}" = "yes"
|
||||
then
|
||||
|
||||
cat >>confdefs.h <<\_ACEOF
|
||||
@ -27669,6 +27773,22 @@ _ACEOF
|
||||
|
||||
fi
|
||||
|
||||
# Check whether --enable-syscall was given.
|
||||
if test "${enable_syscall+set}" = set; then
|
||||
enableval=$enable_syscall; enable_syscall_is=$enableval
|
||||
else
|
||||
enable_syscall_is=no
|
||||
fi
|
||||
|
||||
if test "${enable_syscall_is}" = "yes"
|
||||
then
|
||||
|
||||
cat >>confdefs.h <<\_ACEOF
|
||||
#define ASE_USE_SYSCALL
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
|
||||
# Check whether --enable-debug was given.
|
||||
if test "${enable_debug+set}" = set; then
|
||||
enableval=$enable_debug; enable_debug_is=$enableval
|
||||
|
@ -65,13 +65,17 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl make visible the 64bit interface to the file system
|
||||
CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
|
||||
CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE"
|
||||
|
||||
dnl Checks for the math library (is -lm needed?)
|
||||
AC_CHECK_LIBM
|
||||
AC_SUBST(LIBM, $LIBM)
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([stddef.h wchar.h wctype.h])
|
||||
AC_CHECK_HEADERS([stddef.h wchar.h wctype.h sys/syscall.h])
|
||||
|
||||
dnl Checks data types
|
||||
AC_CHECK_TYPE([wchar_t],
|
||||
@ -84,6 +88,7 @@ dnl check functions
|
||||
AC_CHECK_FUNCS([uselocale])
|
||||
AC_CHECK_FUNCS([mbrlen mbrtowc wcrtomb])
|
||||
AC_CHECK_FUNCS([mbsnrtowcs mbsrtowcs wcsnrtombs wcsrtombs])
|
||||
AC_CHECK_FUNCS([open64 lseek64 stat64 fstat64 lstat64])
|
||||
|
||||
dnl Checks the size of primitive data types
|
||||
AC_CHECK_SIZEOF(char)
|
||||
@ -135,13 +140,21 @@ AC_ARG_ENABLE([wchar], [AC_HELP_STRING([--enable-wchar],
|
||||
[use wchar_t a default charater type when enabled (default. yes)])],
|
||||
enable_wchar_is=$enableval,enable_wchar_is=yes)
|
||||
test "${ac_cv_sizeof_wchar_t}" = "0" && enable_wchar_is=no
|
||||
if test "$enable_wchar_is" = "yes"
|
||||
if test "${enable_wchar_is}" = "yes"
|
||||
then
|
||||
AC_DEFINE([ASE_CHAR_IS_WCHAR],[],[char is wchar])
|
||||
else
|
||||
AC_DEFINE([ASE_CHAR_IS_MCHAR],[],[char is mchar])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([syscall], [AC_HELP_STRING([--enable-syscall],
|
||||
[use the syscall() function to call system calls (default. no)])],
|
||||
enable_syscall_is=$enableval,enable_syscall_is=no)
|
||||
if test "${enable_syscall_is}" = "yes"
|
||||
then
|
||||
AC_DEFINE([ASE_USE_SYSCALL],[],[use the syscall() function])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([debug], [AC_HELP_STRING([--enable-debug],
|
||||
[build the library in the debug mode (default. no)])],
|
||||
enable_debug_is=$enableval,enable_debug_is=no)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 419 2008-10-13 11:32:58Z baconevi $
|
||||
* $Id: awk.h 455 2008-11-26 09:05:00Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -661,6 +661,10 @@ void* ase_awk_getextension (
|
||||
);
|
||||
/******/
|
||||
|
||||
ase_ccls_t* ase_awk_getccls (
|
||||
ase_awk_t* awk
|
||||
);
|
||||
|
||||
/*
|
||||
* set the character classfier
|
||||
*/
|
||||
@ -671,6 +675,10 @@ void ase_awk_setccls (
|
||||
ase_ccls_t* ccls
|
||||
);
|
||||
|
||||
ase_awk_prmfns_t* ase_awk_getprmfns (
|
||||
ase_awk_t* awk
|
||||
);
|
||||
|
||||
/*
|
||||
* set primitive functions
|
||||
*/
|
||||
@ -1046,4 +1054,36 @@ void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct ase_ns_awk_t
|
||||
{
|
||||
ase_awk_t* (*open) (ase_mmgr_t*, ase_size_t ext);
|
||||
int (*close) (ase_awk_t*);
|
||||
|
||||
ase_mmgr_t* (*getmmgr) (ase_awk_t*);
|
||||
void (*setmmgr) (ase_awk_t*, ase_mmgr_t*);
|
||||
void* (*getextension) (ase_awk_t*);
|
||||
|
||||
ase_ccls_t* (*getccls) (ase_awk_t*);
|
||||
void (*setccls) (ase_awk_t*, ase_ccls_t*);
|
||||
|
||||
ase_awk_prmfns_t* (*getprmfns) (ase_awk_t*);
|
||||
void (*setprmfns) (ase_awk_t*, ase_awk_prmfns_t*);
|
||||
|
||||
int (*parse) (ase_awk_t*, ase_awk_srcios_t*);
|
||||
};
|
||||
|
||||
#define ase_ns_awk_d \
|
||||
{ \
|
||||
ase_awk_open, \
|
||||
ase_awk_close, \
|
||||
ase_awk_getmmgr, \
|
||||
ase_awk_setmmgr, \
|
||||
ase_awk_getextension, \
|
||||
ase_awk_getccls, \
|
||||
ase_awk_setccls, \
|
||||
ase_awk_getprmfns, \
|
||||
ase_awk_setprmfns, \
|
||||
ase_awk_parse \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
110
ase/include/ase/cmn/fio.h
Normal file
110
ase/include/ase/cmn/fio.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _ASE_CMN_FIO_H_
|
||||
#define _ASE_CMN_FIO_H_
|
||||
|
||||
#include <ase/types.h>
|
||||
#include <ase/macros.h>
|
||||
|
||||
enum ase_fio_open_flag_t
|
||||
{
|
||||
/* treat the file name pointer as a handle pointer */
|
||||
ASE_FIO_HANDLE = (1 << 0),
|
||||
|
||||
ASE_FIO_READ = (1 << 1),
|
||||
ASE_FIO_WRITE = (1 << 2),
|
||||
ASE_FIO_CREATE = (1 << 3),
|
||||
ASE_FIO_TRUNCATE = (1 << 4),
|
||||
ASE_FIO_EXCLUSIVE = (1 << 5),
|
||||
ASE_FIO_APPEND = (1 << 6),
|
||||
ASE_FIO_SYNC = (1 << 7),
|
||||
|
||||
/* for ms windows only */
|
||||
ASE_FIO_NOSHRD = (1 << 16),
|
||||
ASE_FIO_NOSHWR = (1 << 17),
|
||||
};
|
||||
|
||||
/* seek origin */
|
||||
enum ase_fio_seek_origin_t
|
||||
{
|
||||
ASE_FIO_BEGIN = 0,
|
||||
ASE_FIO_CURRENT = 1,
|
||||
ASE_FIO_END = 2
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
/* <winnt.h> typedef PVOID HANDLE; */
|
||||
typedef void* aes_fio_hnd_t;
|
||||
#else
|
||||
typedef int ase_fio_hnd_t;
|
||||
#endif
|
||||
|
||||
/* file offset */
|
||||
typedef ase_int64_t ase_fio_off_t;
|
||||
typedef enum ase_fio_seek_origin_t ase_fio_ori_t;
|
||||
|
||||
typedef struct ase_fio_t ase_fio_t;
|
||||
|
||||
struct ase_fio_t
|
||||
{
|
||||
ase_mmgr_t* mmgr;
|
||||
ase_fio_hnd_t handle;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ase_fio_t* ase_fio_open (
|
||||
ase_mmgr_t* mmgr,
|
||||
ase_size_t ext,
|
||||
const ase_char_t* path,
|
||||
int flags,
|
||||
int mode
|
||||
);
|
||||
|
||||
void ase_fio_close (
|
||||
ase_fio_t* fio
|
||||
);
|
||||
|
||||
ase_fio_t* ase_fio_init (
|
||||
ase_fio_t* fio,
|
||||
ase_mmgr_t* mmgr,
|
||||
const ase_char_t* path,
|
||||
int flags,
|
||||
int mode
|
||||
);
|
||||
|
||||
void ase_fio_fini (
|
||||
ase_fio_t* fio
|
||||
);
|
||||
|
||||
ase_fio_hnd_t ase_fio_gethandle (
|
||||
ase_fio_t* fio
|
||||
);
|
||||
|
||||
ase_fio_off_t ase_fio_seek (
|
||||
ase_fio_t* fio,
|
||||
ase_fio_off_t offset,
|
||||
ase_fio_ori_t origin
|
||||
);
|
||||
|
||||
ase_ssize_t ase_fio_read (
|
||||
ase_fio_t* fio,
|
||||
void* buf,
|
||||
ase_size_t size
|
||||
);
|
||||
|
||||
ase_ssize_t ase_fio_write (
|
||||
ase_fio_t* fio,
|
||||
const void* buf,
|
||||
ase_size_t size
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
|
||||
pkginclude_HEADERS = mem.h chr.h str.h lda.h map.h rex.h sll.h dll.h opt.h tio.h
|
||||
pkginclude_HEADERS = mem.h chr.h str.h lda.h map.h rex.h sll.h dll.h opt.h fio.h tio.h
|
||||
|
||||
pkgincludedir= $(includedir)/ase/cmn
|
||||
|
||||
|
@ -178,7 +178,7 @@ sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
pkginclude_HEADERS = mem.h chr.h str.h lda.h map.h rex.h sll.h dll.h opt.h tio.h
|
||||
pkginclude_HEADERS = mem.h chr.h str.h lda.h map.h rex.h sll.h dll.h opt.h fio.h tio.h
|
||||
CLEANFILES = *dist
|
||||
all: all-am
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str.h 430 2008-10-17 11:43:20Z baconevi $
|
||||
* $Id: str.h 455 2008-11-26 09:05:00Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -393,7 +393,7 @@ ase_size_t ase_mbstowcs (
|
||||
|
||||
/****f* ase.cmn.str/ase_mbsntowcsn
|
||||
* NAME
|
||||
* ase_mbsntowcsn - conver a multibyte string to a wide character string
|
||||
* ase_mbsntowcsn - convert a multibyte string to a wide character string
|
||||
*
|
||||
* RETURN
|
||||
* The ase_mbstowcs() function returns the number of bytes handled.
|
||||
@ -408,6 +408,24 @@ ase_size_t ase_mbsntowcsn (
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* ase.cmn.str/ase_wcstombs
|
||||
* NAME
|
||||
* ase_wcstombs - convert a wide character string to a multibyte string.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The ase_wcstombs() function converts a null-terminated wide character
|
||||
* string to a multibyte string and stores it into the buffer pointed to
|
||||
* by mbs. The pointer to a variable holding the buffer length should be
|
||||
* passed to the function as the third parameter. After conversion, it holds
|
||||
* the length of the multibyte string excluding the terminating-null.
|
||||
* It may not null-terminate the resulting multibyte string if the buffer
|
||||
* is not large enough.
|
||||
*
|
||||
* RETURN
|
||||
* The ase_wcstombs() function returns the number of wide characters handled.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
ase_size_t ase_wcstombs (
|
||||
const ase_wchar_t* wcs,
|
||||
ase_mchar_t* mbs,
|
||||
@ -431,6 +449,26 @@ ase_size_t ase_wcsntombsn (
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* ase.cmn.str/ase_wcstombs_strict
|
||||
* NAME
|
||||
* ase_wcstombs_strict - convert a wide character string to a multibyte string.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The ase_wcstombs_strict() function performs the same as the ase_wcsmbs()
|
||||
* function except that it returns an error if it can't fully convert the
|
||||
* input string and/or the buffer is not large enough.
|
||||
*
|
||||
* RETURN
|
||||
* The ase_wcstombs_strict() function returns 0 on success and -1 on failure.
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int ase_wcstombs_strict (
|
||||
const ase_wchar_t* wcs,
|
||||
ase_mchar_t* mbs,
|
||||
ase_size_t mbslen
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -63,6 +63,9 @@
|
||||
/* sizeof(__int8) */
|
||||
#undef ASE_SIZEOF___INT8
|
||||
|
||||
/* use the syscall() function */
|
||||
#undef ASE_USE_SYSCALL
|
||||
|
||||
/* package version */
|
||||
#undef ASE_VERSION
|
||||
|
||||
@ -78,9 +81,18 @@
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `fstat64' function. */
|
||||
#undef HAVE_FSTAT64
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `lseek64' function. */
|
||||
#undef HAVE_LSEEK64
|
||||
|
||||
/* Define to 1 if you have the `lstat64' function. */
|
||||
#undef HAVE_LSTAT64
|
||||
|
||||
/* Define to 1 if you have the `mbrlen' function. */
|
||||
#undef HAVE_MBRLEN
|
||||
|
||||
@ -96,6 +108,12 @@
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `open64' function. */
|
||||
#undef HAVE_OPEN64
|
||||
|
||||
/* Define to 1 if you have the `stat64' function. */
|
||||
#undef HAVE_STAT64
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#undef HAVE_STDDEF_H
|
||||
|
||||
@ -114,6 +132,9 @@
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
||||
#undef HAVE_SYS_SYSCALL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: macros.h 399 2008-09-29 10:26:26Z baconevi $
|
||||
* $Id: macros.h 455 2008-11-26 09:05:00Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -147,6 +147,20 @@
|
||||
(ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0))
|
||||
#endif
|
||||
|
||||
/****d* ase/ASE_FNS
|
||||
* NAME
|
||||
* ASE_FNS - define an ASE function name space
|
||||
* DESCRIPTION
|
||||
* The ASE_FNS macro enables you to simulate a function name space for the
|
||||
* types designed properly.
|
||||
* EXAMPLE
|
||||
* ASE_FNS (awk, AWK);
|
||||
* ase_awk_t* awk = AWK.open (....);
|
||||
* AWK.close (awk);
|
||||
******
|
||||
*/
|
||||
#define ASE_NS(type,name) struct ase_ns_##type##_t name = ase_ns_##type##_d
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define ASE_BEGIN_NAMESPACE(x) namespace x {
|
||||
#define ASE_END_NAMESPACE(x) }
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c 415 2008-10-10 11:16:31Z baconevi $
|
||||
* $Id: awk.c 455 2008-11-26 09:05:00Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -343,6 +343,11 @@ void ase_awk_setccls (ase_awk_t* awk, ase_ccls_t* ccls)
|
||||
awk->ccls = ccls;
|
||||
}
|
||||
|
||||
ase_awk_prmfns_t* ase_awk_getprmfns (ase_awk_t* awk)
|
||||
{
|
||||
return awk->prmfns;
|
||||
}
|
||||
|
||||
void ase_awk_setprmfns (ase_awk_t* awk, ase_awk_prmfns_t* prmfns)
|
||||
{
|
||||
ASE_ASSERT (prmfns->pow != ASE_NULL);
|
||||
|
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user