got mod-sys.c working partially
This commit is contained in:
parent
baae1c4bf6
commit
c23d902ad0
@ -167,8 +167,8 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/ar-lib \
|
|||||||
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
|
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
|
||||||
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
|
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
|
||||||
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing ac/ar-lib \
|
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing ac/ar-lib \
|
||||||
ac/compile ac/config.guess ac/config.sub ac/install-sh \
|
ac/compile ac/config.guess ac/config.sub ac/depcomp \
|
||||||
ac/ltmain.sh ac/missing
|
ac/install-sh ac/ltmain.sh ac/missing
|
||||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||||
distdir = $(PACKAGE)-$(VERSION)
|
distdir = $(PACKAGE)-$(VERSION)
|
||||||
top_distdir = $(distdir)
|
top_distdir = $(distdir)
|
||||||
|
119
hawk/configure
vendored
119
hawk/configure
vendored
@ -18711,6 +18711,18 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for ac_func in timelocal timegm localtime_r gmtime_r
|
||||||
|
do :
|
||||||
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
|
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||||
|
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
for ac_func in backtrace backtrace_symbols
|
for ac_func in backtrace backtrace_symbols
|
||||||
do :
|
do :
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
@ -18747,18 +18759,6 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for ac_func in localtime_r gmtime_r
|
|
||||||
do :
|
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
|
||||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
|
||||||
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
|
|
||||||
cat >>confdefs.h <<_ACEOF
|
|
||||||
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
|
|
||||||
_ACEOF
|
|
||||||
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for ac_func in sigaction signal
|
for ac_func in sigaction signal
|
||||||
do :
|
do :
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
@ -19811,6 +19811,101 @@ _ACEOF
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct stat" "st_birthtime" "ac_cv_member_struct_stat_st_birthtime" "$ac_includes_default"
|
||||||
|
if test "x$ac_cv_member_struct_stat_st_birthtime" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct stat" "st_mtim.tv_nsec" "ac_cv_member_struct_stat_st_mtim_tv_nsec" "$ac_includes_default"
|
||||||
|
if test "x$ac_cv_member_struct_stat_st_mtim_tv_nsec" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct stat" "st_birthtim.tv_nsec" "ac_cv_member_struct_stat_st_birthtim_tv_nsec" "$ac_includes_default"
|
||||||
|
if test "x$ac_cv_member_struct_stat_st_birthtim_tv_nsec" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct stat" "st_mtimespec.tv_nsec" "ac_cv_member_struct_stat_st_mtimespec_tv_nsec" "$ac_includes_default"
|
||||||
|
if test "x$ac_cv_member_struct_stat_st_mtimespec_tv_nsec" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct stat" "st_birthtimespec.tv_nsec" "ac_cv_member_struct_stat_st_birthtimespec_tv_nsec" "$ac_includes_default"
|
||||||
|
if test "x$ac_cv_member_struct_stat_st_birthtimespec_tv_nsec" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct tm" "tm_gmtoff" "ac_cv_member_struct_tm_tm_gmtoff" "#include <time.h>
|
||||||
|
"
|
||||||
|
if test "x$ac_cv_member_struct_tm_tm_gmtoff" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_TM_TM_GMTOFF 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct tm" "__tm_gmtoff" "ac_cv_member_struct_tm___tm_gmtoff" "#include <time.h>
|
||||||
|
"
|
||||||
|
if test "x$ac_cv_member_struct_tm___tm_gmtoff" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_TM___TM_GMTOFF 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct tm" "tm_zone" "ac_cv_member_struct_tm_tm_zone" "#include <time.h>
|
||||||
|
"
|
||||||
|
if test "x$ac_cv_member_struct_tm_tm_zone" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_TM_TM_ZONE 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
ac_fn_c_check_member "$LINENO" "struct tm" "__tm_zone" "ac_cv_member_struct_tm___tm_zone" "#include <time.h>
|
||||||
|
"
|
||||||
|
if test "x$ac_cv_member_struct_tm___tm_zone" = xyes; then :
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_STRUCT_TM___TM_ZONE 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# The cast to long int works around a bug in the HP C Compiler
|
# The cast to long int works around a bug in the HP C Compiler
|
||||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||||
|
@ -197,10 +197,10 @@ dnl [#include <stddef.h>])
|
|||||||
|
|
||||||
dnl check functions
|
dnl check functions
|
||||||
AC_CHECK_FUNCS([gettimeofday settimeofday clock_gettime clock_settime getitimer setitimer])
|
AC_CHECK_FUNCS([gettimeofday settimeofday clock_gettime clock_settime getitimer setitimer])
|
||||||
|
AC_CHECK_FUNCS([timelocal timegm localtime_r gmtime_r])
|
||||||
AC_CHECK_FUNCS([backtrace backtrace_symbols])
|
AC_CHECK_FUNCS([backtrace backtrace_symbols])
|
||||||
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
|
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
|
||||||
AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep])
|
AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep])
|
||||||
AC_CHECK_FUNCS([localtime_r gmtime_r])
|
|
||||||
AC_CHECK_FUNCS([sigaction signal])
|
AC_CHECK_FUNCS([sigaction signal])
|
||||||
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r random_r random])
|
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r random_r random])
|
||||||
AC_CHECK_FUNCS([accept4 pipe2 epoll_create epoll_create1 kqueue kqueue1])
|
AC_CHECK_FUNCS([accept4 pipe2 epoll_create epoll_create1 kqueue kqueue1])
|
||||||
@ -381,6 +381,16 @@ AC_TRY_RUN(
|
|||||||
dnl check struct members
|
dnl check struct members
|
||||||
AC_STRUCT_DIRENT_D_TYPE
|
AC_STRUCT_DIRENT_D_TYPE
|
||||||
AC_CHECK_MEMBERS([DIR.d_fd, DIR.dd_fd],,,[[#include <dirent.h>]])
|
AC_CHECK_MEMBERS([DIR.d_fd, DIR.dd_fd],,,[[#include <dirent.h>]])
|
||||||
|
AC_CHECK_MEMBERS([struct stat.st_birthtime])
|
||||||
|
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
|
||||||
|
AC_CHECK_MEMBERS([struct stat.st_birthtim.tv_nsec])
|
||||||
|
AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
|
||||||
|
AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
|
||||||
|
AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[[#include <time.h>]])
|
||||||
|
AC_CHECK_MEMBERS([struct tm.__tm_gmtoff],,,[[#include <time.h>]])
|
||||||
|
AC_CHECK_MEMBERS([struct tm.tm_zone],,,[[#include <time.h>]])
|
||||||
|
AC_CHECK_MEMBERS([struct tm.__tm_zone],,,[[#include <time.h>]])
|
||||||
|
|
||||||
|
|
||||||
dnl check the size of primitive data types
|
dnl check the size of primitive data types
|
||||||
AC_CHECK_SIZEOF(char,,[[]])
|
AC_CHECK_SIZEOF(char,,[[]])
|
||||||
|
@ -51,6 +51,7 @@ pkginclude_HEADERS = \
|
|||||||
hawk.h \
|
hawk.h \
|
||||||
hawk-chr.h \
|
hawk-chr.h \
|
||||||
hawk-cmn.h \
|
hawk-cmn.h \
|
||||||
|
hawk-dir.h \
|
||||||
hawk-ecs.h \
|
hawk-ecs.h \
|
||||||
hawk-fmt.h \
|
hawk-fmt.h \
|
||||||
hawk-gem.h \
|
hawk-gem.h \
|
||||||
@ -73,6 +74,7 @@ libhawk_la_SOURCES = \
|
|||||||
$(pkginclude_HEADERS) \
|
$(pkginclude_HEADERS) \
|
||||||
arr.c \
|
arr.c \
|
||||||
chr.c \
|
chr.c \
|
||||||
|
dir.c \
|
||||||
ecs-imp.h \
|
ecs-imp.h \
|
||||||
ecs.c \
|
ecs.c \
|
||||||
err-prv.h \
|
err-prv.h \
|
||||||
@ -162,10 +164,10 @@ if ENABLE_STATIC_MODULE
|
|||||||
libhawk_la_SOURCES += \
|
libhawk_la_SOURCES += \
|
||||||
imap-imp.h \
|
imap-imp.h \
|
||||||
mod-math.c mod-math.h \
|
mod-math.c mod-math.h \
|
||||||
mod-str.c mod-str.h
|
mod-str.c mod-str.h \
|
||||||
|
mod-sys.c mod-sys.h
|
||||||
libhawk_la_LIBADD +=
|
libhawk_la_LIBADD +=
|
||||||
|
|
||||||
## mod-sys.c mod-sys.h
|
|
||||||
### mod-dir.c mod-dir.h
|
### mod-dir.c mod-dir.h
|
||||||
|
|
||||||
if ENABLE_MOD_MYSQL
|
if ENABLE_MOD_MYSQL
|
||||||
|
@ -99,7 +99,8 @@ host_triplet = @host@
|
|||||||
@ENABLE_STATIC_MODULE_TRUE@am__append_6 = \
|
@ENABLE_STATIC_MODULE_TRUE@am__append_6 = \
|
||||||
@ENABLE_STATIC_MODULE_TRUE@ imap-imp.h \
|
@ENABLE_STATIC_MODULE_TRUE@ imap-imp.h \
|
||||||
@ENABLE_STATIC_MODULE_TRUE@ mod-math.c mod-math.h \
|
@ENABLE_STATIC_MODULE_TRUE@ mod-math.c mod-math.h \
|
||||||
@ENABLE_STATIC_MODULE_TRUE@ mod-str.c mod-str.h
|
@ENABLE_STATIC_MODULE_TRUE@ mod-str.c mod-str.h \
|
||||||
|
@ENABLE_STATIC_MODULE_TRUE@ mod-sys.c mod-sys.h
|
||||||
|
|
||||||
@ENABLE_STATIC_MODULE_TRUE@am__append_7 =
|
@ENABLE_STATIC_MODULE_TRUE@am__append_7 =
|
||||||
|
|
||||||
@ -160,34 +161,37 @@ am__DEPENDENCIES_1 =
|
|||||||
@ENABLE_LIBLTDL_FALSE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
|
@ENABLE_LIBLTDL_FALSE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
|
||||||
am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
|
am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
|
||||||
$(am__DEPENDENCIES_3)
|
$(am__DEPENDENCIES_3)
|
||||||
am__libhawk_la_SOURCES_DIST = hawk.h hawk-chr.h hawk-cmn.h hawk-ecs.h \
|
am__libhawk_la_SOURCES_DIST = hawk.h hawk-chr.h hawk-cmn.h hawk-dir.h \
|
||||||
hawk-fmt.h hawk-gem.h hawk-htb.h hawk-rbt.h hawk-pack1.h \
|
hawk-ecs.h hawk-fmt.h hawk-gem.h hawk-htb.h hawk-rbt.h \
|
||||||
hawk-utl.h hawk-std.h hawk-tre.h hawk-unpack.h arr.c chr.c \
|
hawk-pack1.h hawk-utl.h hawk-std.h hawk-tre.h hawk-unpack.h \
|
||||||
ecs-imp.h ecs.c err-prv.h err.c fmt-imp.h fmt.c fnc-prv.h \
|
arr.c chr.c dir.c ecs-imp.h ecs.c err-prv.h err.c fmt-imp.h \
|
||||||
fnc.c htb.c gem.c hawk-prv.h hawk.c mb8.c misc-prv.h misc.c \
|
fmt.c fnc-prv.h fnc.c htb.c gem.c hawk-prv.h hawk.c mb8.c \
|
||||||
parse-prv.h parse.c rbt.c rec.c rio-prv.h rio.c run-prv.h \
|
misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c rio-prv.h \
|
||||||
run.c tre-prv.h tre-ast.c tre-ast.h tre-compile.c \
|
rio.c run-prv.h run.c tre-prv.h tre-ast.c tre-ast.h \
|
||||||
tre-compile.h tre-match-bt.c tre-match-pa.c tre-match-ut.h \
|
tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \
|
||||||
tre-mem.c tre-mem.h tre-parse.c tre-parse.h tre-stack.c \
|
tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \
|
||||||
tre-stack.h tre.c tree-prv.h tree.c utf16.c utf8.c utl-sort.c \
|
tre-stack.c tre-stack.h tre.c tree-prv.h tree.c utf16.c utf8.c \
|
||||||
utl-str.c utl-sys.c utl.c val-prv.h val.c hawk-cli.h \
|
utl-sort.c utl-str.c utl-sys.c utl.c val-prv.h val.c \
|
||||||
hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h cli.c \
|
hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h \
|
||||||
fio.c mtx.c pio.c sio.c syscall.h syserr.h tio.c std-prv.h \
|
hawk-tio.h cli.c fio.c mtx.c pio.c sio.c syscall.h syserr.h \
|
||||||
std.c imap-imp.h mod-math.c mod-math.h mod-str.c mod-str.h
|
tio.c std-prv.h std.c imap-imp.h mod-math.c mod-math.h \
|
||||||
|
mod-str.c mod-str.h mod-sys.c mod-sys.h
|
||||||
am__objects_1 =
|
am__objects_1 =
|
||||||
@ENABLE_STATIC_MODULE_TRUE@am__objects_2 = libhawk_la-mod-math.lo \
|
@ENABLE_STATIC_MODULE_TRUE@am__objects_2 = libhawk_la-mod-math.lo \
|
||||||
@ENABLE_STATIC_MODULE_TRUE@ libhawk_la-mod-str.lo
|
@ENABLE_STATIC_MODULE_TRUE@ libhawk_la-mod-str.lo \
|
||||||
|
@ENABLE_STATIC_MODULE_TRUE@ libhawk_la-mod-sys.lo
|
||||||
am_libhawk_la_OBJECTS = $(am__objects_1) libhawk_la-arr.lo \
|
am_libhawk_la_OBJECTS = $(am__objects_1) libhawk_la-arr.lo \
|
||||||
libhawk_la-chr.lo libhawk_la-ecs.lo libhawk_la-err.lo \
|
libhawk_la-chr.lo libhawk_la-dir.lo libhawk_la-ecs.lo \
|
||||||
libhawk_la-fmt.lo libhawk_la-fnc.lo libhawk_la-htb.lo \
|
libhawk_la-err.lo libhawk_la-fmt.lo libhawk_la-fnc.lo \
|
||||||
libhawk_la-gem.lo libhawk_la-hawk.lo libhawk_la-mb8.lo \
|
libhawk_la-htb.lo libhawk_la-gem.lo libhawk_la-hawk.lo \
|
||||||
libhawk_la-misc.lo libhawk_la-parse.lo libhawk_la-rbt.lo \
|
libhawk_la-mb8.lo libhawk_la-misc.lo libhawk_la-parse.lo \
|
||||||
libhawk_la-rec.lo libhawk_la-rio.lo libhawk_la-run.lo \
|
libhawk_la-rbt.lo libhawk_la-rec.lo libhawk_la-rio.lo \
|
||||||
libhawk_la-tre-ast.lo libhawk_la-tre-compile.lo \
|
libhawk_la-run.lo libhawk_la-tre-ast.lo \
|
||||||
libhawk_la-tre-match-bt.lo libhawk_la-tre-match-pa.lo \
|
libhawk_la-tre-compile.lo libhawk_la-tre-match-bt.lo \
|
||||||
libhawk_la-tre-mem.lo libhawk_la-tre-parse.lo \
|
libhawk_la-tre-match-pa.lo libhawk_la-tre-mem.lo \
|
||||||
libhawk_la-tre-stack.lo libhawk_la-tre.lo libhawk_la-tree.lo \
|
libhawk_la-tre-parse.lo libhawk_la-tre-stack.lo \
|
||||||
libhawk_la-utf16.lo libhawk_la-utf8.lo libhawk_la-utl-sort.lo \
|
libhawk_la-tre.lo libhawk_la-tree.lo libhawk_la-utf16.lo \
|
||||||
|
libhawk_la-utf8.lo libhawk_la-utl-sort.lo \
|
||||||
libhawk_la-utl-str.lo libhawk_la-utl-sys.lo libhawk_la-utl.lo \
|
libhawk_la-utl-str.lo libhawk_la-utl-sys.lo libhawk_la-utl.lo \
|
||||||
libhawk_la-val.lo libhawk_la-cli.lo libhawk_la-fio.lo \
|
libhawk_la-val.lo libhawk_la-cli.lo libhawk_la-fio.lo \
|
||||||
libhawk_la-mtx.lo libhawk_la-pio.lo libhawk_la-sio.lo \
|
libhawk_la-mtx.lo libhawk_la-pio.lo libhawk_la-sio.lo \
|
||||||
@ -485,6 +489,7 @@ pkginclude_HEADERS = \
|
|||||||
hawk.h \
|
hawk.h \
|
||||||
hawk-chr.h \
|
hawk-chr.h \
|
||||||
hawk-cmn.h \
|
hawk-cmn.h \
|
||||||
|
hawk-dir.h \
|
||||||
hawk-ecs.h \
|
hawk-ecs.h \
|
||||||
hawk-fmt.h \
|
hawk-fmt.h \
|
||||||
hawk-gem.h \
|
hawk-gem.h \
|
||||||
@ -497,10 +502,10 @@ pkginclude_HEADERS = \
|
|||||||
hawk-unpack.h
|
hawk-unpack.h
|
||||||
|
|
||||||
pkglib_LTLIBRARIES = libhawk.la $(am__append_5)
|
pkglib_LTLIBRARIES = libhawk.la $(am__append_5)
|
||||||
libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c ecs-imp.h ecs.c \
|
libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c dir.c ecs-imp.h \
|
||||||
err-prv.h err.c fmt-imp.h fmt.c fnc-prv.h fnc.c htb.c gem.c \
|
ecs.c err-prv.h err.c fmt-imp.h fmt.c fnc-prv.h fnc.c htb.c \
|
||||||
hawk-prv.h hawk.c mb8.c misc-prv.h misc.c parse-prv.h parse.c \
|
gem.c hawk-prv.h hawk.c mb8.c misc-prv.h misc.c parse-prv.h \
|
||||||
rbt.c rec.c rio-prv.h rio.c run-prv.h run.c tre-prv.h \
|
parse.c rbt.c rec.c rio-prv.h rio.c run-prv.h run.c tre-prv.h \
|
||||||
tre-ast.c tre-ast.h tre-compile.c tre-compile.h tre-match-bt.c \
|
tre-ast.c tre-ast.h tre-compile.c tre-compile.h tre-match-bt.c \
|
||||||
tre-match-pa.c tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c \
|
tre-match-pa.c tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c \
|
||||||
tre-parse.h tre-stack.c tre-stack.h tre.c tree-prv.h tree.c \
|
tre-parse.h tre-stack.c tre-stack.h tre.c tree-prv.h tree.c \
|
||||||
@ -627,6 +632,7 @@ distclean-compile:
|
|||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-arr.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-arr.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-chr.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-chr.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-cli.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-cli.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-dir.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-ecs.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-ecs.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-err.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-err.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-fio.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-fio.Plo@am__quote@
|
||||||
@ -639,6 +645,7 @@ distclean-compile:
|
|||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-misc.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-misc.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-math.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-math.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-str.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-str.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-sys.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mtx.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mtx.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-parse.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-parse.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-pio.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-pio.Plo@am__quote@
|
||||||
@ -706,6 +713,13 @@ libhawk_la-chr.lo: chr.c
|
|||||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-chr.lo `test -f 'chr.c' || echo '$(srcdir)/'`chr.c
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-chr.lo `test -f 'chr.c' || echo '$(srcdir)/'`chr.c
|
||||||
|
|
||||||
|
libhawk_la-dir.lo: dir.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-dir.lo -MD -MP -MF $(DEPDIR)/libhawk_la-dir.Tpo -c -o libhawk_la-dir.lo `test -f 'dir.c' || echo '$(srcdir)/'`dir.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-dir.Tpo $(DEPDIR)/libhawk_la-dir.Plo
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dir.c' object='libhawk_la-dir.lo' libtool=yes @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-dir.lo `test -f 'dir.c' || echo '$(srcdir)/'`dir.c
|
||||||
|
|
||||||
libhawk_la-ecs.lo: ecs.c
|
libhawk_la-ecs.lo: ecs.c
|
||||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-ecs.lo -MD -MP -MF $(DEPDIR)/libhawk_la-ecs.Tpo -c -o libhawk_la-ecs.lo `test -f 'ecs.c' || echo '$(srcdir)/'`ecs.c
|
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-ecs.lo -MD -MP -MF $(DEPDIR)/libhawk_la-ecs.Tpo -c -o libhawk_la-ecs.lo `test -f 'ecs.c' || echo '$(srcdir)/'`ecs.c
|
||||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-ecs.Tpo $(DEPDIR)/libhawk_la-ecs.Plo
|
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-ecs.Tpo $(DEPDIR)/libhawk_la-ecs.Plo
|
||||||
@ -979,6 +993,13 @@ libhawk_la-mod-str.lo: mod-str.c
|
|||||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-mod-str.lo `test -f 'mod-str.c' || echo '$(srcdir)/'`mod-str.c
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-mod-str.lo `test -f 'mod-str.c' || echo '$(srcdir)/'`mod-str.c
|
||||||
|
|
||||||
|
libhawk_la-mod-sys.lo: mod-sys.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-mod-sys.lo -MD -MP -MF $(DEPDIR)/libhawk_la-mod-sys.Tpo -c -o libhawk_la-mod-sys.lo `test -f 'mod-sys.c' || echo '$(srcdir)/'`mod-sys.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-mod-sys.Tpo $(DEPDIR)/libhawk_la-mod-sys.Plo
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mod-sys.c' object='libhawk_la-mod-sys.lo' libtool=yes @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-mod-sys.lo `test -f 'mod-sys.c' || echo '$(srcdir)/'`mod-sys.c
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
|
@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
|
||||||
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
|
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
|
||||||
|
844
hawk/lib/dir.c
Normal file
844
hawk/lib/dir.c
Normal file
@ -0,0 +1,844 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <hawk-dir.h>
|
||||||
|
#include "hawk-prv.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
# include <windows.h>
|
||||||
|
#elif defined(__OS2__)
|
||||||
|
# define INCL_DOSFILEMGR
|
||||||
|
# define INCL_ERRORS
|
||||||
|
# include <os2.h>
|
||||||
|
#elif defined(__DOS__)
|
||||||
|
# include <dos.h>
|
||||||
|
# include <errno.h>
|
||||||
|
#else
|
||||||
|
# include "syscall.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define STATUS_OPENED (1 << 0)
|
||||||
|
#define STATUS_DONE (1 << 1)
|
||||||
|
#define STATUS_DONE_ERR (1 << 2)
|
||||||
|
#define STATUS_POPHEAP (1 << 3)
|
||||||
|
#define STATUS_SORT_ERR (1 << 4)
|
||||||
|
|
||||||
|
#define IS_CURDIR(x) ((x)[0] == '.' && (x)[1] == '\0')
|
||||||
|
#define IS_PREVDIR(x) ((x)[0] == '.' && (x)[1] == '.' && (x)[2] == '\0')
|
||||||
|
|
||||||
|
|
||||||
|
struct hawk_dir_t
|
||||||
|
{
|
||||||
|
hawk_gem_t* gem;
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
hawk_uecs_t wbuf;
|
||||||
|
hawk_becs_t mbuf;
|
||||||
|
|
||||||
|
hawk_arr_t* stab;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
HANDLE h;
|
||||||
|
WIN32_FIND_DATA wfd;
|
||||||
|
#elif defined(__OS2__)
|
||||||
|
HDIR h;
|
||||||
|
#if defined(FIL_STANDARDL)
|
||||||
|
FILEFINDBUF3L ffb;
|
||||||
|
#else
|
||||||
|
FILEFINDBUF3 ffb;
|
||||||
|
#endif
|
||||||
|
ULONG count;
|
||||||
|
#elif defined(__DOS__)
|
||||||
|
struct find_t f;
|
||||||
|
#else
|
||||||
|
HAWK_DIR* dp;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
int hawk_dir_init (hawk_dir_t* dir, hawk_gem_t* gem, const hawk_ooch_t* path, int flags);
|
||||||
|
void hawk_dir_fini (hawk_dir_t* dir);
|
||||||
|
|
||||||
|
static void close_dir_safely (hawk_dir_t* dir);
|
||||||
|
static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path);
|
||||||
|
static int read_ahead_and_sort (hawk_dir_t* dir, const hawk_ooch_t* path);
|
||||||
|
|
||||||
|
#include "syserr.h"
|
||||||
|
IMPLEMENT_SYSERR_TO_ERRNUM (hawk, HAWK)
|
||||||
|
|
||||||
|
hawk_dir_t* hawk_dir_open (hawk_gem_t* gem, hawk_oow_t xtnsize, const hawk_ooch_t* path, int flags)
|
||||||
|
{
|
||||||
|
hawk_dir_t* dir;
|
||||||
|
|
||||||
|
dir = hawk_gem_allocmem(gem, HAWK_SIZEOF(*dir) + xtnsize);
|
||||||
|
if (dir)
|
||||||
|
{
|
||||||
|
if (hawk_dir_init(dir, gem, path, flags) <= -1)
|
||||||
|
{
|
||||||
|
hawk_gem_freemem (gem, dir);
|
||||||
|
dir = HAWK_NULL;
|
||||||
|
}
|
||||||
|
else HAWK_MEMSET (dir + 1, 0, xtnsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hawk_dir_close (hawk_dir_t* dir)
|
||||||
|
{
|
||||||
|
hawk_dir_fini (dir);
|
||||||
|
hawk_gem_freemem (dir->gem, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* hawk_dir_getxtn (hawk_dir_t* dir)
|
||||||
|
{
|
||||||
|
return (void*)(dir + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int compare_dirent (hawk_arr_t* arr, const void* dptr1, hawk_oow_t dlen1, const void* dptr2, hawk_oow_t dlen2)
|
||||||
|
{
|
||||||
|
int n = HAWK_MEMCMP(dptr1, dptr2, ((dlen1 < dlen2)? dlen1: dlen2));
|
||||||
|
if (n == 0 && dlen1 != dlen2) n = (dlen1 > dlen2)? 1: -1;
|
||||||
|
return -n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int hawk_dir_init (hawk_dir_t* dir, hawk_gem_t* gem, const hawk_ooch_t* path, int flags)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
int path_flags;
|
||||||
|
|
||||||
|
path_flags = flags & (HAWK_DIR_MBSPATH | HAWK_DIR_WCSPATH);
|
||||||
|
if (path_flags == (HAWK_DIR_MBSPATH | HAWK_DIR_WCSPATH) || path_flags == 0)
|
||||||
|
{
|
||||||
|
/* if both are set or none are set, force it to the default */
|
||||||
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
|
flags |= HAWK_DIR_MBSPATH;
|
||||||
|
flags &= ~HAWK_DIR_WCSPATH;
|
||||||
|
#else
|
||||||
|
flags |= HAWK_DIR_WCSPATH;
|
||||||
|
flags &= ~HAWK_DIR_MBSPATH;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
HAWK_MEMSET (dir, 0, HAWK_SIZEOF(*dir));
|
||||||
|
|
||||||
|
dir->gem = gem;
|
||||||
|
dir->flags = flags;
|
||||||
|
|
||||||
|
if (hawk_uecs_init(&dir->wbuf, gem, 256) <= -1) goto oops_0;
|
||||||
|
if (hawk_becs_init(&dir->mbuf, gem, 256) <= -1) goto oops_1;
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
dir->h = INVALID_HANDLE_VALUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
n = reset_to_path(dir, path);
|
||||||
|
if (n <= -1) goto oops_2;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_SORT)
|
||||||
|
{
|
||||||
|
dir->stab = hawk_arr_open(gem, 0, 128);
|
||||||
|
if (dir->stab == HAWK_NULL) goto oops_3;
|
||||||
|
|
||||||
|
/*hawk_arr_setscale (dir->stab, 1);*/
|
||||||
|
hawk_arr_setcopier (dir->stab, HAWK_ARR_COPIER_INLINE);
|
||||||
|
hawk_arr_setcomper (dir->stab, compare_dirent);
|
||||||
|
if (read_ahead_and_sort(dir, path) <= -1) goto oops_4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
|
||||||
|
oops_4:
|
||||||
|
hawk_arr_close (dir->stab);
|
||||||
|
oops_3:
|
||||||
|
close_dir_safely (dir);
|
||||||
|
oops_2:
|
||||||
|
hawk_becs_fini (&dir->mbuf);
|
||||||
|
oops_1:
|
||||||
|
hawk_uecs_fini (&dir->wbuf);
|
||||||
|
oops_0:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_dir_safely (hawk_dir_t* dir)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
if (dir->h != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
FindClose (dir->h);
|
||||||
|
dir->h = INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
#elif defined(__OS2__)
|
||||||
|
if (dir->status & STATUS_OPENED)
|
||||||
|
{
|
||||||
|
DosFindClose (dir->h);
|
||||||
|
dir->status &= ~STATUS_OPENED;
|
||||||
|
}
|
||||||
|
#elif defined(__DOS__)
|
||||||
|
if (dir->status & STATUS_OPENED)
|
||||||
|
{
|
||||||
|
_dos_findclose (&dir->f);
|
||||||
|
dir->status &= ~STATUS_OPENED;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (dir->dp)
|
||||||
|
{
|
||||||
|
HAWK_CLOSEDIR (dir->dp);
|
||||||
|
dir->dp = HAWK_NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void hawk_dir_fini (hawk_dir_t* dir)
|
||||||
|
{
|
||||||
|
close_dir_safely (dir);
|
||||||
|
|
||||||
|
hawk_becs_fini (&dir->mbuf);
|
||||||
|
hawk_uecs_fini (&dir->wbuf);
|
||||||
|
|
||||||
|
if (dir->stab) hawk_arr_close (dir->stab);
|
||||||
|
}
|
||||||
|
|
||||||
|
static hawk_bch_t* wcs_to_mbuf (hawk_dir_t* dir, const hawk_uch_t* wcs, hawk_becs_t* mbuf)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
hawk_oow_t ml, wl;
|
||||||
|
|
||||||
|
if (hawk_gem_convutobcstr(gem, wcs, &wl, HAWK_NULL, &ml) <= -1) return HAWK_NULL;
|
||||||
|
|
||||||
|
if (hawk_becs_setlen(mbuf, ml) == (hawk_oow_t)-1)
|
||||||
|
{
|
||||||
|
dir->errnum = HAWK_DIR_ENOMEM;
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hawk_wcstombs (wcs, &wl, HAWK_BECS_PTR(mbuf), &ml);
|
||||||
|
return HAWK_BECS_PTR(mbuf);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
if (hawk_becs_ncatuchars(mbuf, wcs, hawk_count_ucstr(wcs), dir->gem->cmgr) == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
return HAWK_BECS_PTR(mbuf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static hawk_uch_t* mbs_to_wbuf (hawk_dir_t* dir, const hawk_bch_t* mbs, hawk_uecs_t* wbuf)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
hawk_oow_t ml, wl;
|
||||||
|
|
||||||
|
if (hawk_mbstowcs (mbs, &ml, HAWK_NULL, &wl) <= -1)
|
||||||
|
{
|
||||||
|
dir->errnum = HAWK_DIR_EINVAL;
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
if (hawk_uecs_setlen (wbuf, wl) == (hawk_oow_t)-1)
|
||||||
|
{
|
||||||
|
dir->errnum = HAWK_DIR_ENOMEM;
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hawk_mbstowcs (mbs, &ml, HAWK_UECS_PTR(wbuf), &wl);
|
||||||
|
return HAWK_UECS_PTR(wbuf);
|
||||||
|
#else
|
||||||
|
/* convert all regardless of encoding failure */
|
||||||
|
if (hawk_uecs_ncatbchars(wbuf, mbs, hawk_count_bcstr(mbs), dir->gem->cmgr, 1) == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
return HAWK_UECS_PTR(wbuf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static hawk_uch_t* wcs_to_wbuf (hawk_dir_t* dir, const hawk_uch_t* wcs, hawk_uecs_t* wbuf)
|
||||||
|
{
|
||||||
|
if (hawk_uecs_cpy(&dir->wbuf, wcs) == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
return HAWK_UECS_PTR(wbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static hawk_bch_t* mbs_to_mbuf (hawk_dir_t* dir, const hawk_bch_t* mbs, hawk_becs_t* mbuf)
|
||||||
|
{
|
||||||
|
if (hawk_becs_cpy(&dir->mbuf, mbs) == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
return HAWK_BECS_PTR(mbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||||
|
static hawk_bch_t* make_mbsdos_path (hawk_dir_t* dir, const hawk_bch_t* mpath)
|
||||||
|
{
|
||||||
|
if (mpath[0] == '\0')
|
||||||
|
{
|
||||||
|
if (hawk_becs_cpy(&dir->mbuf, "*.*") == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
if ((len = hawk_becs_cpy(&dir->mbuf, mpath)) == (hawk_oow_t)-1 ||
|
||||||
|
(!HAWK_ISPATHMBSEP(mpath[len - 1]) &&
|
||||||
|
!hawk_ismbsdrivecurpath(mpath) &&
|
||||||
|
hawk_becs_ccat(&dir->mbuf, '\\') == (hawk_oow_t)-1) ||
|
||||||
|
hawk_becs_cat(&dir->mbuf, "*.*") == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HAWK_BECS_PTR(&dir->mbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static hawk_uch_t* make_wcsdos_path (hawk_dir_t* dir, const hawk_uch_t* wpath)
|
||||||
|
{
|
||||||
|
if (wpath[0] == HAWK_UT('\0'))
|
||||||
|
{
|
||||||
|
if (hawk_uecs_cpy (&dir->wbuf, HAWK_UT("*.*")) == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
if ((len = hawk_uecs_cpy (&dir->wbuf, wpath)) == (hawk_oow_t)-1 ||
|
||||||
|
(!HAWK_ISPATHWCSEP(wpath[len - 1]) &&
|
||||||
|
!hawk_iswcsdrivecurpath(wpath) &&
|
||||||
|
hawk_uecs_ccat (&dir->wbuf, HAWK_UT('\\')) == (hawk_oow_t)-1) ||
|
||||||
|
hawk_uecs_cat (&dir->wbuf, HAWK_UT("*.*")) == (hawk_oow_t)-1) return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HAWK_UECS_PTR(&dir->wbuf);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
static hawk_ooch_t* make_dos_path (hawk_dir_t* dir, const hawk_ooch_t* path)
|
||||||
|
{
|
||||||
|
if (path[0] == HAWK_T('\0'))
|
||||||
|
{
|
||||||
|
if (hawk_str_cpy (&dir->tbuf, HAWK_T("*.*")) == (hawk_oow_t)-1)
|
||||||
|
{
|
||||||
|
dir->errnum = HAWK_DIR_ENOMEM;
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
if ((len = hawk_str_cpy (&dir->tbuf, path)) == (hawk_oow_t)-1 ||
|
||||||
|
(!HAWK_ISPATHSEP(path[len - 1]) &&
|
||||||
|
!hawk_isdrivecurpath(path) &&
|
||||||
|
hawk_str_ccat (&dir->tbuf, HAWK_T('\\')) == (hawk_oow_t)-1) ||
|
||||||
|
hawk_str_cat (&dir->tbuf, HAWK_T("*.*")) == (hawk_oow_t)-1)
|
||||||
|
{
|
||||||
|
dir->errnum = HAWK_DIR_ENOMEM;
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return HAWK_STR_PTR(&dir->tbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static hawk_bch_t* mkdospath (hawk_dir_t* dir, const hawk_ooch_t* path)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
|
return make_dos_path (dir, path);
|
||||||
|
#else
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
return make_mbsdos_path (dir, (const hawk_bch_t*) path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_ooch_t* tptr;
|
||||||
|
hawk_bch_t* mptr;
|
||||||
|
|
||||||
|
tptr = make_dos_path (dir, path);
|
||||||
|
if (tptr == HAWK_NULL) return HAWK_NULL;
|
||||||
|
|
||||||
|
mptr = wcs_to_mbuf (dir, HAWK_STR_PTR(&dir->tbuf), &dir->mbuf);
|
||||||
|
if (mptr == HAWK_NULL) return HAWK_NULL;
|
||||||
|
|
||||||
|
return mptr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int reset_to_path (hawk_dir_t* dir, const hawk_ooch_t* path)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
const hawk_ooch_t* tptr;
|
||||||
|
|
||||||
|
dir->status &= ~STATUS_DONE;
|
||||||
|
dir->status &= ~STATUS_DONE_ERR;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
hawk_bch_t* mptr;
|
||||||
|
|
||||||
|
mptr = make_mbsdos_path (dir, (const hawk_bch_t*)path);
|
||||||
|
if (mptr == HAWK_NULL) return -1;
|
||||||
|
|
||||||
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
|
tptr = mptr;
|
||||||
|
#else
|
||||||
|
tptr = mbs_to_wbuf (dir, mptr, &dir->wbuf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_uch_t* wptr;
|
||||||
|
HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);
|
||||||
|
|
||||||
|
wptr = make_wcsdos_path(dir, (const hawk_uch_t*)path);
|
||||||
|
if (wptr == HAWK_NULL) return -1;
|
||||||
|
|
||||||
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
|
tptr = wcs_to_mbuf(dir, wptr, &dir->mbuf);
|
||||||
|
#else
|
||||||
|
tptr = wptr;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (tptr == HAWK_NULL) return -1;
|
||||||
|
|
||||||
|
dir->h = FindFirstFile(tptr, &dir->wfd);
|
||||||
|
if (dir->h == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#elif defined(__OS2__)
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
APIRET rc;
|
||||||
|
const hawk_bch_t* mptr;
|
||||||
|
|
||||||
|
dir->h = HDIR_CREATE;
|
||||||
|
dir->count = 1;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
mptr = make_mbsdos_path (dir, (const hawk_bch_t*)path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_uch_t* wptr;
|
||||||
|
HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);
|
||||||
|
|
||||||
|
wptr = make_wcsdos_path(dir, (const hawk_uch_t*)path);
|
||||||
|
if (wptr == HAWK_NULL) return -1;
|
||||||
|
mptr = wcs_to_mbuf(dir, wptr, &dir->mbuf);
|
||||||
|
}
|
||||||
|
if (mptr == HAWK_NULL) return -1;
|
||||||
|
|
||||||
|
rc = DosFindFirst (
|
||||||
|
mptr,
|
||||||
|
&dir->h,
|
||||||
|
FILE_DIRECTORY | FILE_READONLY,
|
||||||
|
&dir->ffb,
|
||||||
|
HAWK_SIZEOF(dir->ffb),
|
||||||
|
&dir->count,
|
||||||
|
#if defined(FIL_STANDARDL)
|
||||||
|
FIL_STANDARDL
|
||||||
|
#else
|
||||||
|
FIL_STANDARD
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rc != NO_ERROR)
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum(rc));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir->status |= STATUS_OPENED;
|
||||||
|
return 0;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#elif defined(__DOS__)
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
unsigned int rc;
|
||||||
|
const hawk_bch_t* mptr;
|
||||||
|
|
||||||
|
dir->status &= ~STATUS_DONE;
|
||||||
|
dir->status &= ~STATUS_DONE_ERR;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
mptr = make_mbsdos_path(dir, (const hawk_bch_t*)path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_uch_t* wptr;
|
||||||
|
|
||||||
|
HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);
|
||||||
|
|
||||||
|
wptr = make_wcsdos_path(dir, (const hawk_uch_t*)path);
|
||||||
|
if (wptr == HAWK_NULL) return -1;
|
||||||
|
mptr = wcs_to_mbuf(dir, wptr, &dir->mbuf);
|
||||||
|
}
|
||||||
|
if (mptr == HAWK_NULL) return -1;
|
||||||
|
|
||||||
|
rc = _dos_findfirst(mptr, _A_NORMAL | _A_SUBDIR, &dir->f);
|
||||||
|
if (rc != 0)
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL,syserr_to_errnum(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir->status |= STATUS_OPENED;
|
||||||
|
return 0;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#else
|
||||||
|
DIR* dp;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
const hawk_bch_t* mpath = (const hawk_bch_t*)path;
|
||||||
|
dp = HAWK_OPENDIR(mpath[0] == '\0'? ".": mpath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const hawk_uch_t* wpath;
|
||||||
|
/*HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);*/
|
||||||
|
|
||||||
|
wpath = (const hawk_uch_t*)path;
|
||||||
|
if (wpath[0] == '\0')
|
||||||
|
{
|
||||||
|
dp = HAWK_OPENDIR(".");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_bch_t* mptr;
|
||||||
|
|
||||||
|
mptr = wcs_to_mbuf(dir, wpath, &dir->mbuf);
|
||||||
|
if (mptr == HAWK_NULL) return -1;
|
||||||
|
|
||||||
|
dp = HAWK_OPENDIR(mptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dp == HAWK_NULL)
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir->dp = dp;
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int hawk_dir_reset (hawk_dir_t* dir, const hawk_ooch_t* path)
|
||||||
|
{
|
||||||
|
close_dir_safely (dir);
|
||||||
|
if (reset_to_path (dir, path) <= -1) return -1;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_SORT)
|
||||||
|
{
|
||||||
|
hawk_arr_clear (dir->stab);
|
||||||
|
if (read_ahead_and_sort (dir, path) <= -1)
|
||||||
|
{
|
||||||
|
dir->status |= STATUS_SORT_ERR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dir->status &= ~STATUS_SORT_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_dir_to_buf (hawk_dir_t* dir, void** name)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
if (dir->status & STATUS_DONE) return (dir->status & STATUS_DONE_ERR)? -1: 0;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_SKIPSPCDIR)
|
||||||
|
{
|
||||||
|
/* skip . and .. */
|
||||||
|
while (IS_CURDIR(dir->wfd.cFileName) || IS_PREVDIR(dir->wfd.cFileName))
|
||||||
|
{
|
||||||
|
if (FindNextFile(dir->h, &dir->wfd) == FALSE)
|
||||||
|
{
|
||||||
|
DWORD x = GetLastError();
|
||||||
|
if (x == ERROR_NO_MORE_FILES)
|
||||||
|
{
|
||||||
|
dir->status |= STATUS_DONE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum(x));
|
||||||
|
dir->status |= STATUS_DONE;
|
||||||
|
dir->status |= STATUS_DONE_ERR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
|
if (mbs_to_mbuf(dir, dir->wfd.cFileName, &dir->mbuf) == HAWK_NULL) return -1;
|
||||||
|
#else
|
||||||
|
if (wcs_to_mbuf(dir, dir->wfd.cFileName, &dir->mbuf) == HAWK_NULL) return -1;
|
||||||
|
#endif
|
||||||
|
*name = HAWK_BECS_PTR(&dir->mbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);
|
||||||
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
|
if (mbs_to_wbuf(dir, dir->wfd.cFileName, &dir->wbuf) == HAWK_NULL) return -1;
|
||||||
|
#else
|
||||||
|
if (wcs_to_wbuf(dir, dir->wfd.cFileName, &dir->wbuf) == HAWK_NULL) return -1;
|
||||||
|
#endif
|
||||||
|
*name = HAWK_UECS_PTR(&dir->wbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FindNextFile (dir->h, &dir->wfd) == FALSE)
|
||||||
|
{
|
||||||
|
DWORD x = GetLastError();
|
||||||
|
if (x == ERROR_NO_MORE_FILES) dir->status |= STATUS_DONE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum (x));
|
||||||
|
dir->status |= STATUS_DONE;
|
||||||
|
dir->status |= STATUS_DONE_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#elif defined(__OS2__)
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
APIRET rc;
|
||||||
|
|
||||||
|
if (dir->count <= 0) return 0;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_SKIPSPCDIR)
|
||||||
|
{
|
||||||
|
/* skip . and .. */
|
||||||
|
while (IS_CURDIR(dir->ffb.achName) || IS_PREVDIR(dir->ffb.achName))
|
||||||
|
{
|
||||||
|
rc = DosFindNext (dir->h, &dir->ffb, HAWK_SIZEOF(dir->ffb), &dir->count);
|
||||||
|
if (rc == ERROR_NO_MORE_FILES)
|
||||||
|
{
|
||||||
|
dir->count = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (rc != NO_ERROR)
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum (rc));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
if (mbs_to_mbuf (dir, dir->ffb.achName, &dir->mbuf) == HAWK_NULL) return -1;
|
||||||
|
*name = HAWK_BECS_PTR(&dir->mbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);
|
||||||
|
if (mbs_to_wbuf (dir, dir->ffb.achName, &dir->wbuf) == HAWK_NULL) return -1;
|
||||||
|
*name = HAWK_UECS_PTR(&dir->wbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rc = DosFindNext (dir->h, &dir->ffb, HAWK_SIZEOF(dir->ffb), &dir->count);
|
||||||
|
if (rc == ERROR_NO_MORE_FILES) dir->count = 0;
|
||||||
|
else if (rc != NO_ERROR)
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum (rc));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#elif defined(__DOS__)
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
if (dir->status & STATUS_DONE) return (dir->status & STATUS_DONE_ERR)? -1: 0;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_SKIPSPCDIR)
|
||||||
|
{
|
||||||
|
/* skip . and .. */
|
||||||
|
while (IS_CURDIR(dir->f.name) || IS_PREVDIR(dir->f.name))
|
||||||
|
{
|
||||||
|
if (_dos_findnext (&dir->f) != 0)
|
||||||
|
{
|
||||||
|
if (errno == ENOENT)
|
||||||
|
{
|
||||||
|
dir->status |= STATUS_DONE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum (errno));
|
||||||
|
dir->status |= STATUS_DONE;
|
||||||
|
dir->status |= STATUS_DONE_ERR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
if (mbs_to_mbuf (dir, dir->f.name, &dir->mbuf) == HAWK_NULL) return -1;
|
||||||
|
*name = HAWK_BECS_PTR(&dir->mbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);
|
||||||
|
|
||||||
|
if (mbs_to_wbuf (dir, dir->f.name, &dir->wbuf) == HAWK_NULL) return -1;
|
||||||
|
*name = HAWK_UECS_PTR(&dir->wbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_dos_findnext (&dir->f) != 0)
|
||||||
|
{
|
||||||
|
if (errno == ENOENT) dir->status |= STATUS_DONE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum (errno));
|
||||||
|
dir->status |= STATUS_DONE;
|
||||||
|
dir->status |= STATUS_DONE_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
hawk_dirent_t* de;
|
||||||
|
|
||||||
|
read:
|
||||||
|
errno = 0;
|
||||||
|
de = HAWK_READDIR (dir->dp);
|
||||||
|
if (de == NULL)
|
||||||
|
{
|
||||||
|
if (errno == 0) return 0;
|
||||||
|
hawk_gem_seterrnum (dir->gem, HAWK_NULL, syserr_to_errnum (errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_SKIPSPCDIR)
|
||||||
|
{
|
||||||
|
/* skip . and .. */
|
||||||
|
if (IS_CURDIR(de->d_name) ||
|
||||||
|
IS_PREVDIR(de->d_name)) goto read;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
{
|
||||||
|
if (mbs_to_mbuf (dir, de->d_name, &dir->mbuf) == HAWK_NULL) return -1;
|
||||||
|
*name = HAWK_BECS_PTR(&dir->mbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*HAWK_ASSERT (dir->flags & HAWK_DIR_WCSPATH);*/
|
||||||
|
if (mbs_to_wbuf (dir, de->d_name, &dir->wbuf) == HAWK_NULL) return -1;
|
||||||
|
*name = HAWK_UECS_PTR(&dir->wbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_ahead_and_sort (hawk_dir_t* dir, const hawk_ooch_t* path)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
void* name;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
x = read_dir_to_buf (dir, &name);
|
||||||
|
if (x >= 1)
|
||||||
|
{
|
||||||
|
hawk_oow_t size;
|
||||||
|
|
||||||
|
if (dir->flags & HAWK_DIR_MBSPATH)
|
||||||
|
size = (hawk_count_bcstr(name) + 1) * HAWK_SIZEOF(hawk_bch_t);
|
||||||
|
else
|
||||||
|
size = (hawk_count_ucstr(name) + 1) * HAWK_SIZEOF(hawk_uch_t);
|
||||||
|
|
||||||
|
if (hawk_arr_pushheap(dir->stab, name, size) == (hawk_oow_t)-1) return -1;
|
||||||
|
}
|
||||||
|
else if (x == 0) break;
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir->status &= ~STATUS_POPHEAP;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int hawk_dir_read (hawk_dir_t* dir, hawk_dir_ent_t* ent)
|
||||||
|
{
|
||||||
|
if (dir->flags & HAWK_DIR_SORT)
|
||||||
|
{
|
||||||
|
if (dir->status & STATUS_SORT_ERR) return -1;
|
||||||
|
|
||||||
|
if (dir->status & STATUS_POPHEAP) hawk_arr_popheap (dir->stab);
|
||||||
|
else dir->status |= STATUS_POPHEAP;
|
||||||
|
|
||||||
|
if (HAWK_ARR_SIZE(dir->stab) <= 0) return 0; /* no more entry */
|
||||||
|
|
||||||
|
ent->name = HAWK_ARR_DPTR(dir->stab, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
void* name;
|
||||||
|
|
||||||
|
x = read_dir_to_buf(dir, &name);
|
||||||
|
if (x >= 1)
|
||||||
|
{
|
||||||
|
HAWK_MEMSET (ent, 0, HAWK_SIZEOF(ent));
|
||||||
|
ent->name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
@ -454,6 +454,33 @@
|
|||||||
/* Define to 1 if `d_type' is a member of `struct dirent'. */
|
/* Define to 1 if `d_type' is a member of `struct dirent'. */
|
||||||
#undef HAVE_STRUCT_DIRENT_D_TYPE
|
#undef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
|
|
||||||
|
/* Define to 1 if `st_birthtime' is a member of `struct stat'. */
|
||||||
|
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
|
||||||
|
|
||||||
|
/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */
|
||||||
|
#undef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
|
||||||
|
|
||||||
|
/* Define to 1 if `st_birthtim.tv_nsec' is a member of `struct stat'. */
|
||||||
|
#undef HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC
|
||||||
|
|
||||||
|
/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */
|
||||||
|
#undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
|
||||||
|
|
||||||
|
/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */
|
||||||
|
#undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
|
||||||
|
|
||||||
|
/* Define to 1 if `tm_gmtoff' is a member of `struct tm'. */
|
||||||
|
#undef HAVE_STRUCT_TM_TM_GMTOFF
|
||||||
|
|
||||||
|
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
|
||||||
|
#undef HAVE_STRUCT_TM_TM_ZONE
|
||||||
|
|
||||||
|
/* Define to 1 if `__tm_gmtoff' is a member of `struct tm'. */
|
||||||
|
#undef HAVE_STRUCT_TM___TM_GMTOFF
|
||||||
|
|
||||||
|
/* Define to 1 if `__tm_zone' is a member of `struct tm'. */
|
||||||
|
#undef HAVE_STRUCT_TM___TM_ZONE
|
||||||
|
|
||||||
/* Define to 1 if you have the `swapcontext' function. */
|
/* Define to 1 if you have the `swapcontext' function. */
|
||||||
#undef HAVE_SWAPCONTEXT
|
#undef HAVE_SWAPCONTEXT
|
||||||
|
|
||||||
@ -525,6 +552,12 @@
|
|||||||
/* Define to 1 if you have the `tanq' function. */
|
/* Define to 1 if you have the `tanq' function. */
|
||||||
#undef HAVE_TANQ
|
#undef HAVE_TANQ
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `timegm' function. */
|
||||||
|
#undef HAVE_TIMEGM
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `timelocal' function. */
|
||||||
|
#undef HAVE_TIMELOCAL
|
||||||
|
|
||||||
/* Define to 1 if you have the <time.h> header file. */
|
/* Define to 1 if you have the <time.h> header file. */
|
||||||
#undef HAVE_TIME_H
|
#undef HAVE_TIME_H
|
||||||
|
|
||||||
|
87
hawk/lib/hawk-dir.h
Normal file
87
hawk/lib/hawk-dir.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _HAWK_DIR_H_
|
||||||
|
#define _HAWK_DIR_H_
|
||||||
|
|
||||||
|
#include <hawk-cmn.h>
|
||||||
|
|
||||||
|
typedef struct hawk_dir_t hawk_dir_t;
|
||||||
|
typedef struct hawk_dir_ent_t hawk_dir_ent_t;
|
||||||
|
|
||||||
|
enum hawk_dir_flag_t
|
||||||
|
{
|
||||||
|
HAWK_DIR_MBSPATH = (1 << 0),
|
||||||
|
HAWK_DIR_WCSPATH = (1 << 1),
|
||||||
|
HAWK_DIR_SORT = (1 << 2),
|
||||||
|
HAWK_DIR_SKIPSPCDIR = (1 << 3) /**< limited to normal entries excluding . and .. */
|
||||||
|
};
|
||||||
|
typedef enum hawk_dir_flag_t hawk_dir_flag_t;
|
||||||
|
|
||||||
|
struct hawk_dir_ent_t
|
||||||
|
{
|
||||||
|
const hawk_ooch_t* name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
HAWK_EXPORT hawk_dir_t* hawk_dir_open (
|
||||||
|
hawk_gem_t* gem,
|
||||||
|
hawk_oow_t xtnsize,
|
||||||
|
const hawk_ooch_t* path,
|
||||||
|
int flags
|
||||||
|
);
|
||||||
|
|
||||||
|
HAWK_EXPORT void hawk_dir_close (
|
||||||
|
hawk_dir_t* dir
|
||||||
|
);
|
||||||
|
|
||||||
|
HAWK_EXPORT void* hawk_dir_getxtn (
|
||||||
|
hawk_dir_t* dir
|
||||||
|
);
|
||||||
|
|
||||||
|
HAWK_EXPORT int hawk_dir_reset (
|
||||||
|
hawk_dir_t* dir,
|
||||||
|
const hawk_ooch_t* path
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hawk_dir_read() function reads a directory entry and
|
||||||
|
* stores it in memory pointed to by \a ent.
|
||||||
|
* \return -1 on failure, 0 upon no more entry, 1 on success
|
||||||
|
*/
|
||||||
|
HAWK_EXPORT int hawk_dir_read (
|
||||||
|
hawk_dir_t* dir,
|
||||||
|
hawk_dir_ent_t* ent
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "mod-sys.h"
|
#include "mod-sys.h"
|
||||||
#include "hawk-prv.h"
|
#include "hawk-prv.h"
|
||||||
|
#include <hawk-dir.h>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
@ -119,7 +120,7 @@ struct sys_node_data_t
|
|||||||
union
|
union
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
//hawk_dir_t* dir;
|
hawk_dir_t* dir;
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
typedef struct sys_node_data_t sys_node_data_t;
|
typedef struct sys_node_data_t sys_node_data_t;
|
||||||
@ -164,50 +165,33 @@ static HAWK_INLINE sys_rc_t syserr_to_rc (int syserr)
|
|||||||
|
|
||||||
case EBADF: return RC_EBADF;
|
case EBADF: return RC_EBADF;
|
||||||
case ECHILD: return RC_ECHILD;
|
case ECHILD: return RC_ECHILD;
|
||||||
|
case EEXIST: return RC_EEXIST;
|
||||||
case EINTR: return RC_EINTR;
|
case EINTR: return RC_EINTR;
|
||||||
case EINVAL: return RC_EINVAL;
|
case EINVAL: return RC_EINVAL;
|
||||||
|
case ENOENT: return RC_ENOENT;
|
||||||
case ENOMEM: return RC_ENOMEM;
|
case ENOMEM: return RC_ENOMEM;
|
||||||
case ENOSYS: return RC_ENOSYS;
|
case ENOSYS: return RC_ENOSYS;
|
||||||
case EPERM: return RC_EPERM;
|
case EPERM: return RC_EPERM;
|
||||||
|
|
||||||
default: return RC_ERROR;
|
default: return RC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
static HAWK_INLINE sys_rc_t hawkerr_to_rc (hawk_errnum_t hawkerr)
|
||||||
static HAWK_INLINE sys_rc_t direrr_to_rc (hawk_dir_errnum_t direrr)
|
|
||||||
{
|
{
|
||||||
switch (direrr)
|
switch (hawkerr)
|
||||||
{
|
|
||||||
case HAWK_DIR_ENOIMPL: return RC_ENOIMPL;
|
|
||||||
case HAWK_DIR_ENOMEM: return RC_ENOMEM;
|
|
||||||
case HAWK_DIR_EINVAL: return RC_EINVAL;
|
|
||||||
case HAWK_DIR_EPERM: return RC_EPERM;
|
|
||||||
case HAWK_DIR_ENOENT: return RC_ENOENT;
|
|
||||||
case HAWK_DIR_EEXIST: return RC_EEXIST;
|
|
||||||
case HAWK_DIR_ENOTDIR: return RC_ENOTDIR;
|
|
||||||
case HAWK_DIR_EINTR: return RC_EINTR;
|
|
||||||
case HAWK_DIR_EAGAIN: return RC_EAGAIN;
|
|
||||||
|
|
||||||
default: return RC_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static HAWK_INLINE sys_rc_t awkerr_to_rc (hawk_dir_errnum_t awkerr)
|
|
||||||
{
|
|
||||||
switch (awkerr)
|
|
||||||
{
|
{
|
||||||
|
case HAWK_EAGAIN: return RC_EAGAIN;
|
||||||
|
case HAWK_ECHILD: return RC_ECHILD;
|
||||||
|
case HAWK_EEXIST: return RC_EEXIST;
|
||||||
|
case HAWK_EINTR: return RC_EINTR;
|
||||||
|
case HAWK_EINVAL: return RC_EINVAL;
|
||||||
|
case HAWK_ENOENT: return RC_ENOENT;
|
||||||
case HAWK_ENOIMPL: return RC_ENOIMPL;
|
case HAWK_ENOIMPL: return RC_ENOIMPL;
|
||||||
case HAWK_ENOMEM: return RC_ENOMEM;
|
case HAWK_ENOMEM: return RC_ENOMEM;
|
||||||
case HAWK_EINVAL: return RC_EINVAL;
|
|
||||||
case HAWK_EPERM: return RC_EPERM;
|
case HAWK_EPERM: return RC_EPERM;
|
||||||
case HAWK_ENOENT: return RC_ENOENT;
|
|
||||||
case HAWK_EEXIST: return RC_EEXIST;
|
|
||||||
|
|
||||||
default: return RC_ERROR;
|
default: return RC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static const hawk_ooch_t* rc_to_errstr (sys_rc_t rc)
|
static const hawk_ooch_t* rc_to_errstr (sys_rc_t rc)
|
||||||
{
|
{
|
||||||
@ -236,7 +220,7 @@ static void set_errmsg_on_sys_list (hawk_rtx_t* rtx, sys_list_t* sys_list, const
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, errfmt);
|
va_start (ap, errfmt);
|
||||||
hawk_strxvfmt (sys_list->ctx.errmsg, HAWK_COUNTOF(sys_list->ctx.errmsg), errfmt, ap);
|
hawk_rtx_vfmttooocstr (rtx, sys_list->ctx.errmsg, HAWK_COUNTOF(sys_list->ctx.errmsg), errfmt, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -392,7 +376,7 @@ static int fnc_close (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
BEGIN {
|
BEGIN {
|
||||||
f = sys::open ("/tmp/test.txt", sys::O_RDONLY);
|
f = sys::open("/tmp/test.txt", sys::O_RDONLY);
|
||||||
while (sys::read(f, x, 10) > 0) printf (B"%s", x);
|
while (sys::read(f, x, 10) > 0) printf (B"%s", x);
|
||||||
sys::close (f);
|
sys::close (f);
|
||||||
}
|
}
|
||||||
@ -436,7 +420,7 @@ static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
fail:
|
fail:
|
||||||
rx = awkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,7 +430,7 @@ static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
set_errmsg_on_sys_list_with_syserr (rtx, sys_list);
|
set_errmsg_on_sys_list_with_syserr (rtx, sys_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
/*HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));*/
|
||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -471,7 +455,7 @@ static int fnc_openfd (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 0), &fd) <= -1)
|
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 0), &fd) <= -1)
|
||||||
{
|
{
|
||||||
rx = awkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
||||||
}
|
}
|
||||||
else if (fd >= 0 && fd <= HAWK_TYPE_MAX(int))
|
else if (fd >= 0 && fd <= HAWK_TYPE_MAX(int))
|
||||||
@ -485,7 +469,7 @@ static int fnc_openfd (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rx = awkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -495,7 +479,7 @@ static int fnc_openfd (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
||||||
}
|
}
|
||||||
|
|
||||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
/*HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));*/
|
||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -695,7 +679,7 @@ static int fnc_dup (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
rx = awkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
set_errmsg_on_sys_list (rtx, sys_list, HAWK_NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -855,7 +839,6 @@ static int fnc_pipe (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
/*
|
||||||
d = sys::opendir("/etc", sys::DIR_SORT);
|
d = sys::opendir("/etc", sys::DIR_SORT);
|
||||||
if (d >= 0)
|
if (d >= 0)
|
||||||
@ -874,7 +857,6 @@ static int fnc_opendir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
hawk_oow_t plen;
|
hawk_oow_t plen;
|
||||||
hawk_val_t* a0;
|
hawk_val_t* a0;
|
||||||
hawk_dir_t* dir;
|
hawk_dir_t* dir;
|
||||||
hawk_dir_errnum_t oe;
|
|
||||||
|
|
||||||
sys_list = rtx_to_sys_list(rtx, fi);
|
sys_list = rtx_to_sys_list(rtx, fi);
|
||||||
|
|
||||||
@ -883,7 +865,7 @@ static int fnc_opendir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
a0 = hawk_rtx_getarg(rtx, 0);
|
a0 = hawk_rtx_getarg(rtx, 0);
|
||||||
pstr = hawk_rtx_getvaloocstr(rtx, a0, &plen);
|
pstr = hawk_rtx_getvaloocstr(rtx, a0, &plen);
|
||||||
if (!pstr) goto fail;
|
if (!pstr) goto fail;
|
||||||
dir = hawk_dir_open(hawk_rtx_getmmgr(rtx), 0, pstr, flags, &oe);
|
dir = hawk_dir_open(hawk_rtx_getgem(rtx), 0, pstr, flags);
|
||||||
hawk_rtx_freevaloocstr (rtx, a0, pstr);
|
hawk_rtx_freevaloocstr (rtx, a0, pstr);
|
||||||
|
|
||||||
if (dir)
|
if (dir)
|
||||||
@ -902,11 +884,11 @@ static int fnc_opendir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rx = direrr_to_rc(oe);
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
||||||
}
|
}
|
||||||
|
|
||||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
/*HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));*/
|
||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -953,7 +935,7 @@ static int fnc_readdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
y = hawk_dir_read(sys_node->ctx.u.dir, &ent);
|
y = hawk_dir_read(sys_node->ctx.u.dir, &ent);
|
||||||
if (y <= -1)
|
if (y <= -1)
|
||||||
{
|
{
|
||||||
rx = direrr_to_rc(hawk_dir_geterrnum(sys_node->ctx.u.dir));
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
||||||
}
|
}
|
||||||
else if (y == 0)
|
else if (y == 0)
|
||||||
@ -965,7 +947,7 @@ static int fnc_readdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
tmp = hawk_rtx_makestrvalwithoocstr(rtx, ent.name);
|
tmp = hawk_rtx_makestrvalwithoocstr(rtx, ent.name);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
{
|
{
|
||||||
rx = awkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
rx = hawkerr_to_rc(hawk_rtx_geterrnum(rtx));
|
||||||
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
set_errmsg_on_sys_list (rtx, sys_list, rc_to_errstr(rx));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -991,7 +973,7 @@ static int fnc_readdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static int fnc_fork (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
static int fnc_fork (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||||
@ -1559,7 +1541,7 @@ static int fnc_mktime (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
hawk_ooch_t* str, * p, * end;
|
hawk_ooch_t* str, * p, * end;
|
||||||
hawk_oow_t len;
|
hawk_oow_t len;
|
||||||
hawk_val_t* a0;
|
hawk_val_t* a0;
|
||||||
hawk_btime_t bt;
|
struct tm tm;
|
||||||
|
|
||||||
a0 = hawk_rtx_getarg(rtx, 0);
|
a0 = hawk_rtx_getarg(rtx, 0);
|
||||||
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
|
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
|
||||||
@ -1568,54 +1550,58 @@ static int fnc_mktime (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
/* the string must be of the format YYYY MM DD HH MM SS[ DST] */
|
/* the string must be of the format YYYY MM DD HH MM SS[ DST] */
|
||||||
p = str;
|
p = str;
|
||||||
end = str + len;
|
end = str + len;
|
||||||
HAWK_MEMSET (&bt, 0, HAWK_SIZEOF(bt));
|
HAWK_MEMSET (&tm, 0, HAWK_SIZEOF(tm));
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.year = bt.year * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_year = tm.tm_year * 10 + (*p++ - '0');
|
||||||
bt.year *= sign;
|
tm.tm_year *= sign;
|
||||||
bt.year -= 1900;
|
tm.tm_year -= 1900;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.mon = bt.mon * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_mon = tm.tm_mon * 10 + (*p++ - '0');
|
||||||
bt.mon *= sign;
|
tm.tm_mon *= sign;
|
||||||
bt.mon -= 1;
|
tm.tm_mon -= 1;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.mday = bt.mday * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_mday = tm.tm_mday * 10 + (*p++ - '0');
|
||||||
bt.mday *= sign;
|
tm.tm_mday *= sign;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.hour = bt.hour * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_hour = tm.tm_hour * 10 + (*p++ - '0');
|
||||||
bt.hour *= sign;
|
tm.tm_hour *= sign;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.min = bt.min * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_min = tm.tm_min * 10 + (*p++ - '0');
|
||||||
bt.min *= sign;
|
tm.tm_min *= sign;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.sec = bt.sec * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_sec = tm.tm_sec * 10 + (*p++ - '0');
|
||||||
bt.sec *= sign;
|
tm.tm_sec *= sign;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
sign = 1;
|
sign = 1;
|
||||||
if (p < end && *p == HAWK_T('-')) { sign = -1; p++; }
|
if (p < end && *p == '-') { sign = -1; p++; }
|
||||||
while (p < end && hawk_is_ooch_digit(*p)) bt.isdst = bt.isdst * 10 + (*p++ - HAWK_T('0'));
|
while (p < end && hawk_is_ooch_digit(*p)) tm.tm_isdst = tm.tm_isdst * 10 + (*p++ - '0');
|
||||||
bt.isdst *= sign;
|
tm.tm_isdst *= sign;
|
||||||
while (p < end && (hawk_is_ooch_space(*p) || *p == HAWK_T('\0'))) p++;
|
while (p < end && (hawk_is_ooch_space(*p) || *p == '\0')) p++;
|
||||||
|
|
||||||
hawk_rtx_freevaloocstr (rtx, a0, str);
|
hawk_rtx_freevaloocstr (rtx, a0, str);
|
||||||
hawk_timelocal (&bt, &nt);
|
#if defined(HAVE_TIMELOCAL)
|
||||||
|
nt.sec = timelocal(&tm);
|
||||||
|
#else
|
||||||
|
nt.sec = mktime(&tm);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1649,7 +1635,7 @@ static int fnc_strftime (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
if (fmt)
|
if (fmt)
|
||||||
{
|
{
|
||||||
hawk_ntime_t nt;
|
hawk_ntime_t nt;
|
||||||
hawk_btime_t bt;
|
struct tm tm, * tmx;
|
||||||
hawk_int_t tmpsec, flags = 0;
|
hawk_int_t tmpsec, flags = 0;
|
||||||
|
|
||||||
nt.nsec = 0;
|
nt.nsec = 0;
|
||||||
@ -1662,15 +1648,33 @@ static int fnc_strftime (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
nt.sec = tmpsec;
|
nt.sec = tmpsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &flags) <= -1 || flags < 0)) flags = 0;
|
if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &flags) <= -1 || flags < 0)) flags = 0;
|
||||||
|
|
||||||
if (((flags & STRFTIME_UTC)? hawk_gmtime(&nt, &bt): hawk_localtime(&nt, &bt)) >= 0)
|
if (flags & STRFTIME_UTC)
|
||||||
|
{
|
||||||
|
time_t t = nt.sec;
|
||||||
|
#if defined(HAVE_GMTIME_R)
|
||||||
|
tmx = gmtime_r(&t, &tm);
|
||||||
|
#else
|
||||||
|
tmx = gmtime(&t.sec);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time_t t = nt.sec;
|
||||||
|
#if defined(HAVE_LOCALTIME_R)
|
||||||
|
tmx = localtime_r(&t, &tm);
|
||||||
|
#else
|
||||||
|
tmx = localtime(&t.sec);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmx)
|
||||||
{
|
{
|
||||||
hawk_bch_t tmpbuf[64], * tmpptr;
|
hawk_bch_t tmpbuf[64], * tmpptr;
|
||||||
struct tm tm;
|
|
||||||
hawk_oow_t sl;
|
hawk_oow_t sl;
|
||||||
|
|
||||||
|
#if 0
|
||||||
HAWK_MEMSET (&tm, 0, HAWK_SIZEOF(tm));
|
HAWK_MEMSET (&tm, 0, HAWK_SIZEOF(tm));
|
||||||
tm.tm_year = bt.year;
|
tm.tm_year = bt.year;
|
||||||
tm.tm_mon = bt.mon;
|
tm.tm_mon = bt.mon;
|
||||||
@ -1692,8 +1696,9 @@ static int fnc_strftime (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
tm.__tm_zone = "GMT";
|
tm.__tm_zone = "GMT";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
sl = strftime(tmpbuf, HAWK_COUNTOF(tmpbuf), fmt, &tm);
|
sl = strftime(tmpbuf, HAWK_COUNTOF(tmpbuf), fmt, tmx);
|
||||||
if (sl <= 0 || sl >= HAWK_COUNTOF(tmpbuf))
|
if (sl <= 0 || sl >= HAWK_COUNTOF(tmpbuf))
|
||||||
{
|
{
|
||||||
/* buffer too small */
|
/* buffer too small */
|
||||||
@ -1774,6 +1779,7 @@ I use 'count' to limit the maximum number of retries when 0 is returned.
|
|||||||
hawk_rtx_freemem (rtx, fmt);
|
hawk_rtx_freemem (rtx, fmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1783,7 +1789,7 @@ static int fnc_getenv (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
hawk_oow_t len;
|
hawk_oow_t len;
|
||||||
hawk_val_t* retv;
|
hawk_val_t* retv;
|
||||||
|
|
||||||
var = hawk_rtx_valtobcstrdup(rtx, hawk_rtx_getarg (rtx, 0), &len);
|
var = hawk_rtx_valtobcstrdup(rtx, hawk_rtx_getarg(rtx, 0), &len);
|
||||||
if (var)
|
if (var)
|
||||||
{
|
{
|
||||||
hawk_bch_t* val;
|
hawk_bch_t* val;
|
||||||
@ -1805,6 +1811,8 @@ static int fnc_getenv (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
static int fnc_getnwifcfg (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
static int fnc_getnwifcfg (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
// TODO: put this back
|
||||||
hawk_nwifcfg_t cfg;
|
hawk_nwifcfg_t cfg;
|
||||||
hawk_rtx_valtostr_out_t out;
|
hawk_rtx_valtostr_out_t out;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -1889,6 +1897,7 @@ static int fnc_getnwifcfg (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
/* no error check for hawk_rtx_makeintval() since ret is 0 or -1 */
|
/* no error check for hawk_rtx_makeintval() since ret is 0 or -1 */
|
||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval (rtx, ret));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval (rtx, ret));
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@ -1906,7 +1915,7 @@ static int fnc_system (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
/* the target name contains a null character.
|
/* the target name contains a null character.
|
||||||
* make system return -1 */
|
* make system return -1 */
|
||||||
if (hawk_strxchr (str, len, HAWK_T('\0')))
|
if (hawk_find_oochar(str, len, '\0'))
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_system;
|
goto skip_system;
|
||||||
@ -1920,7 +1929,7 @@ static int fnc_system (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
{
|
{
|
||||||
hawk_bch_t* mbs;
|
hawk_bch_t* mbs;
|
||||||
mbs = hawk_wcstombsdupwithcmgr(str, HAWK_NULL, hawk_rtx_getmmgr(rtx), hawk_rtx_getcmgr(rtx));
|
mbs = hawk_rtx_duputobcstr(rtx, str, HAWK_NULL);
|
||||||
if (mbs == HAWK_NULL)
|
if (mbs == HAWK_NULL)
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
@ -1951,13 +1960,13 @@ static int fnc_chmod (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
int n = 0;
|
int n = 0;
|
||||||
hawk_int_t mode;
|
hawk_int_t mode;
|
||||||
|
|
||||||
a0 = hawk_rtx_getarg (rtx, 0);
|
a0 = hawk_rtx_getarg(rtx, 0);
|
||||||
str = hawk_rtx_getvaloocstr (rtx, a0, &len);
|
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
|
||||||
if (!str) return -1;
|
if (!str) return -1;
|
||||||
|
|
||||||
/* the target name contains a null character.
|
/* the target name contains a null character.
|
||||||
* make system return -1 */
|
* make system return -1 */
|
||||||
if (hawk_strxchr(str, len, HAWK_T('\0')))
|
if (hawk_find_oochar(str, len, '\0'))
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_mkdir;
|
goto skip_mkdir;
|
||||||
@ -1970,10 +1979,9 @@ static int fnc_chmod (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
#elif defined(HAWK_OOCH_IS_BCH)
|
#elif defined(HAWK_OOCH_IS_BCH)
|
||||||
n = chmod(str, mode);
|
n = chmod(str, mode);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
{
|
{
|
||||||
hawk_bch_t* mbs;
|
hawk_bch_t* mbs;
|
||||||
mbs = hawk_wcstombsdupwithcmgr(str, HAWK_NULL, hawk_rtx_getmmgr(rtx), hawk_rtx_getcmgr(rtx));
|
mbs = hawk_rtx_duputobcstr(rtx, str, HAWK_NULL);
|
||||||
if (mbs == HAWK_NULL)
|
if (mbs == HAWK_NULL)
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
@ -1982,7 +1990,6 @@ static int fnc_chmod (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
n = chmod(mbs, mode);
|
n = chmod(mbs, mode);
|
||||||
hawk_rtx_freemem (rtx, mbs);
|
hawk_rtx_freemem (rtx, mbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
skip_mkdir:
|
skip_mkdir:
|
||||||
@ -2003,13 +2010,13 @@ static int fnc_mkdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
int n = 0;
|
int n = 0;
|
||||||
hawk_int_t mode;
|
hawk_int_t mode;
|
||||||
|
|
||||||
a0 = hawk_rtx_getarg (rtx, 0);
|
a0 = hawk_rtx_getarg(rtx, 0);
|
||||||
str = hawk_rtx_getvaloocstr (rtx, a0, &len);
|
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
|
||||||
if (!str) return -1;
|
if (!str) return -1;
|
||||||
|
|
||||||
/* the target name contains a null character.
|
/* the target name contains a null character.
|
||||||
* make system return -1 */
|
* make system return -1 */
|
||||||
if (hawk_strxchr(str, len, HAWK_T('\0')))
|
if (hawk_find_oochar(str, len, '\0'))
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_mkdir;
|
goto skip_mkdir;
|
||||||
@ -2025,7 +2032,7 @@ static int fnc_mkdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
{
|
{
|
||||||
hawk_bch_t* mbs;
|
hawk_bch_t* mbs;
|
||||||
mbs = hawk_wcstombsdupwithcmgr(str, HAWK_NULL, hawk_rtx_getmmgr(rtx), hawk_rtx_getcmgr(rtx));
|
mbs = hawk_rtx_duputobcstr(rtx, str, HAWK_NULL);
|
||||||
if (mbs == HAWK_NULL)
|
if (mbs == HAWK_NULL)
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
@ -2060,7 +2067,7 @@ static int fnc_unlink (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
/* the target name contains a null character.
|
/* the target name contains a null character.
|
||||||
* make system return -1 */
|
* make system return -1 */
|
||||||
if (hawk_strxchr(str, len, HAWK_T('\0')))
|
if (hawk_find_oochar(str, len, '\0'))
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
goto skip_unlink;
|
goto skip_unlink;
|
||||||
@ -2074,7 +2081,7 @@ static int fnc_unlink (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
{
|
{
|
||||||
hawk_bch_t* mbs;
|
hawk_bch_t* mbs;
|
||||||
mbs = hawk_wcstombsdupwithcmgr(str, HAWK_NULL, hawk_rtx_getmmgr(rtx), hawk_rtx_getcmgr(rtx));
|
mbs = hawk_rtx_duputobcstr(rtx, str, HAWK_NULL);
|
||||||
if (mbs == HAWK_NULL)
|
if (mbs == HAWK_NULL)
|
||||||
{
|
{
|
||||||
n = -1;
|
n = -1;
|
||||||
@ -2098,6 +2105,7 @@ skip_unlink:
|
|||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
#if 0
|
#if 0
|
||||||
|
// TODO: add back the syslog support
|
||||||
static void open_remote_log_socket (hawk_rtx_t* rtx, mod_ctx_t* mctx)
|
static void open_remote_log_socket (hawk_rtx_t* rtx, mod_ctx_t* mctx)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -2168,19 +2176,19 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
/* the target name contains a null character.
|
/* the target name contains a null character.
|
||||||
* make system return -1 */
|
* make system return -1 */
|
||||||
if (hawk_strxchr(ident, ident_len, HAWK_T('\0'))) goto done;
|
if (hawk_find_oochar(ident, ident_len, '\0')) goto done;
|
||||||
|
|
||||||
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 1), &opt) <= -1) goto done;
|
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 1), &opt) <= -1) goto done;
|
||||||
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &fac) <= -1) goto done;
|
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &fac) <= -1) goto done;
|
||||||
|
|
||||||
if (hawk_strbeg(ident, HAWK_T("remote://")))
|
if (hawk_comp_bcstr_limited(ident, HAWK_T("remote://"), 9))
|
||||||
{
|
{
|
||||||
hawk_ooch_t* slash;
|
hawk_ooch_t* slash;
|
||||||
/* "udp://remote-addr:remote-port/syslog-identifier" */
|
/* "udp://remote-addr:remote-port/syslog-identifier" */
|
||||||
|
|
||||||
log_type = SYSLOG_REMOTE;
|
log_type = SYSLOG_REMOTE;
|
||||||
actual_ident = ident + 9;
|
actual_ident = ident + 9;
|
||||||
slash = hawk_strchr(actual_ident, HAWK_T('/'));
|
slash = hawk_find_oochar_in_oocstr(actual_ident, '/');
|
||||||
if (!slash) goto done;
|
if (!slash) goto done;
|
||||||
if (hawk_strntonwad(actual_ident, slash - actual_ident, &nwad) <= -1) goto done;
|
if (hawk_strntonwad(actual_ident, slash - actual_ident, &nwad) <= -1) goto done;
|
||||||
actual_ident = slash + 1;
|
actual_ident = slash + 1;
|
||||||
@ -2196,9 +2204,9 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAWK_OOCH_IS_BCH)
|
#if defined(HAWK_OOCH_IS_BCH)
|
||||||
mbs_ident = hawk_becsdup(actual_ident, hawk_rtx_getmmgr(rtx));
|
mbs_ident = hawk_rtx_dupbcstr(rtx, actual_ident);
|
||||||
#else
|
#else
|
||||||
mbs_ident = hawk_wcstombsdupwithcmgr(actual_ident, HAWK_NULL, hawk_rtx_getmmgr(rtx), hawk_rtx_getcmgr(rtx));
|
mbs_ident = hawk_rtx_duputobcstr(actual_ident, str, HAWK_NULL);
|
||||||
#endif
|
#endif
|
||||||
if (!mbs_ident) goto done;
|
if (!mbs_ident) goto done;
|
||||||
|
|
||||||
@ -2323,7 +2331,7 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
msg = hawk_rtx_getvaloocstr(rtx, hawk_rtx_getarg(rtx, 1), &msglen);
|
msg = hawk_rtx_getvaloocstr(rtx, hawk_rtx_getarg(rtx, 1), &msglen);
|
||||||
if (!msg) goto done;
|
if (!msg) goto done;
|
||||||
|
|
||||||
if (hawk_strxchr(msg, msglen, HAWK_T('\0'))) goto done;
|
if (hawk_find_oochar(msg, msglen, '\0')) goto done;
|
||||||
|
|
||||||
if (mctx->log.type == SYSLOG_LOCAL)
|
if (mctx->log.type == SYSLOG_LOCAL)
|
||||||
{
|
{
|
||||||
@ -2333,7 +2341,7 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
hawk_bch_t* mbs;
|
hawk_bch_t* mbs;
|
||||||
mbs = hawk_wcstombsdupwithcmgr(msg, HAWK_NULL, hawk_rtx_getmmgr(rtx), hawk_rtx_getcmgr(rtx));
|
mbs = hawk_rtx_duputobcstr(rtx, msg, HAWK_NULL);
|
||||||
if (!mbs) goto done;
|
if (!mbs) goto done;
|
||||||
syslog(pri, "%s", mbs);
|
syslog(pri, "%s", mbs);
|
||||||
hawk_rtx_freemem (rtx, mbs);
|
hawk_rtx_freemem (rtx, mbs);
|
||||||
@ -2449,7 +2457,7 @@ static fnctab_t fnctab[] =
|
|||||||
{ HAWK_T("chmod"), { { 2, 2, HAWK_NULL }, fnc_chmod, 0 } },
|
{ HAWK_T("chmod"), { { 2, 2, HAWK_NULL }, fnc_chmod, 0 } },
|
||||||
{ HAWK_T("close"), { { 1, 2, HAWK_NULL }, fnc_close, 0 } },
|
{ HAWK_T("close"), { { 1, 2, HAWK_NULL }, fnc_close, 0 } },
|
||||||
{ HAWK_T("closedir"), { { 1, 1, HAWK_NULL }, fnc_closedir, 0 } },
|
{ HAWK_T("closedir"), { { 1, 1, HAWK_NULL }, fnc_closedir, 0 } },
|
||||||
{ HAWK_T("closelog"), { { 0, 0, HAWK_NULL }, fnc_closelog, 0 } },
|
//{ HAWK_T("closelog"), { { 0, 0, HAWK_NULL }, fnc_closelog, 0 } },
|
||||||
{ HAWK_T("dup"), { { 1, 3, HAWK_NULL }, fnc_dup, 0 } },
|
{ HAWK_T("dup"), { { 1, 3, HAWK_NULL }, fnc_dup, 0 } },
|
||||||
{ HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } },
|
{ HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } },
|
||||||
{ HAWK_T("fork"), { { 0, 0, HAWK_NULL }, fnc_fork, 0 } },
|
{ HAWK_T("fork"), { { 0, 0, HAWK_NULL }, fnc_fork, 0 } },
|
||||||
@ -2470,7 +2478,7 @@ static fnctab_t fnctab[] =
|
|||||||
{ HAWK_T("open"), { { 2, 3, HAWK_NULL }, fnc_open, 0 } },
|
{ HAWK_T("open"), { { 2, 3, HAWK_NULL }, fnc_open, 0 } },
|
||||||
{ HAWK_T("opendir"), { { 1, 2, HAWK_NULL }, fnc_opendir, 0 } },
|
{ HAWK_T("opendir"), { { 1, 2, HAWK_NULL }, fnc_opendir, 0 } },
|
||||||
{ HAWK_T("openfd"), { { 1, 1, HAWK_NULL }, fnc_openfd, 0 } },
|
{ HAWK_T("openfd"), { { 1, 1, HAWK_NULL }, fnc_openfd, 0 } },
|
||||||
{ HAWK_T("openlog"), { { 3, 3, HAWK_NULL }, fnc_openlog, 0 } },
|
//{ HAWK_T("openlog"), { { 3, 3, HAWK_NULL }, fnc_openlog, 0 } },
|
||||||
{ HAWK_T("pipe"), { { 2, 3, HAWK_T("rrv") }, fnc_pipe, 0 } },
|
{ HAWK_T("pipe"), { { 2, 3, HAWK_T("rrv") }, fnc_pipe, 0 } },
|
||||||
{ HAWK_T("read"), { { 2, 3, HAWK_T("vrv") }, fnc_read, 0 } },
|
{ HAWK_T("read"), { { 2, 3, HAWK_T("vrv") }, fnc_read, 0 } },
|
||||||
{ HAWK_T("readdir"), { { 2, 2, HAWK_T("vr") }, fnc_readdir, 0 } },
|
{ HAWK_T("readdir"), { { 2, 2, HAWK_T("vr") }, fnc_readdir, 0 } },
|
||||||
@ -2482,7 +2490,7 @@ static fnctab_t fnctab[] =
|
|||||||
{ HAWK_T("unlink"), { { 1, 1, HAWK_NULL }, fnc_unlink, 0 } },
|
{ HAWK_T("unlink"), { { 1, 1, HAWK_NULL }, fnc_unlink, 0 } },
|
||||||
{ HAWK_T("wait"), { { 1, 3, HAWK_T("vrv") }, fnc_wait, 0 } },
|
{ HAWK_T("wait"), { { 1, 3, HAWK_T("vrv") }, fnc_wait, 0 } },
|
||||||
{ HAWK_T("write"), { { 2, 2, HAWK_NULL }, fnc_write, 0 } },
|
{ HAWK_T("write"), { { 2, 2, HAWK_NULL }, fnc_write, 0 } },
|
||||||
{ HAWK_T("writelog"), { { 2, 2, HAWK_NULL }, fnc_writelog, 0 } }
|
//{ HAWK_T("writelog"), { { 2, 2, HAWK_NULL }, fnc_writelog, 0 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined(SIGHUP)
|
#if !defined(SIGHUP)
|
||||||
@ -2554,8 +2562,11 @@ static inttab_t inttab[] =
|
|||||||
{ HAWK_T("LOG_PRI_WARNING"), { LOG_WARNING } },
|
{ HAWK_T("LOG_PRI_WARNING"), { LOG_WARNING } },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// PUT THESE BACK
|
||||||
{ HAWK_T("NWIFCFG_IN4"), { HAWK_NWIFCFG_IN4 } },
|
{ HAWK_T("NWIFCFG_IN4"), { HAWK_NWIFCFG_IN4 } },
|
||||||
{ HAWK_T("NWIFCFG_IN6"), { HAWK_NWIFCFG_IN6 } },
|
{ HAWK_T("NWIFCFG_IN6"), { HAWK_NWIFCFG_IN6 } },
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(O_APPEND)
|
#if defined(O_APPEND)
|
||||||
{ HAWK_T("O_APPEND"), { O_APPEND } },
|
{ HAWK_T("O_APPEND"), { O_APPEND } },
|
||||||
|
@ -7036,7 +7036,7 @@ static struct
|
|||||||
{ HAWK_T("sed"), hawk_mod_sed },
|
{ HAWK_T("sed"), hawk_mod_sed },
|
||||||
#endif
|
#endif
|
||||||
{ HAWK_T("str"), hawk_mod_str },
|
{ HAWK_T("str"), hawk_mod_str },
|
||||||
// { HAWK_T("sys"), hawk_mod_sys },
|
{ HAWK_T("sys"), hawk_mod_sys },
|
||||||
#if defined(HAWK_ENABLE_MOD_UCI)
|
#if defined(HAWK_ENABLE_MOD_UCI)
|
||||||
{ HAWK_T("uci"), hawk_mod_uci }
|
{ HAWK_T("uci"), hawk_mod_uci }
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,10 +48,8 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static hawk_ooi_t pio_input (
|
static hawk_ooi_t pio_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size);
|
||||||
hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size);
|
static hawk_ooi_t pio_output (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size);
|
||||||
static hawk_ooi_t pio_output (
|
|
||||||
hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size);
|
|
||||||
|
|
||||||
#include "syserr.h"
|
#include "syserr.h"
|
||||||
IMPLEMENT_SYSERR_TO_ERRNUM (hawk, HAWK)
|
IMPLEMENT_SYSERR_TO_ERRNUM (hawk, HAWK)
|
||||||
|
Loading…
Reference in New Issue
Block a user