From 7d21e90ce2c07c071d1e57448a3d067e13db9ce6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 24 Nov 2014 17:01:04 +0000 Subject: [PATCH] renamed qse_tmr_remove() to qse_tmr_delete(). removed qse_fs_delete() and added qse_fs_delfile()/qse_fs_deldir() with some new options --- qse/Makefile.in | 2 +- qse/cmd/sed/sed.c | 2 +- qse/doc/page/installation.md | 7 +- qse/include/qse/cmn/dir.h | 5 + qse/include/qse/cmn/env.h | 8 +- qse/include/qse/cmn/fs.h | 119 +++++++-- qse/include/qse/cmn/glob.h | 8 +- qse/include/qse/cmn/mbwc.h | 2 +- qse/include/qse/cmn/tmr.h | 2 +- qse/lib/cmn/Makefile.am | 1 + qse/lib/cmn/Makefile.in | 80 +++--- qse/lib/cmn/dir.c | 16 +- qse/lib/cmn/fs-delete.c | 461 +++++++++++++++++++++++++++++++++++ qse/lib/cmn/fs-err.c | 16 +- qse/lib/cmn/fs-move.c | 153 +----------- qse/lib/cmn/fs.c | 41 +++- qse/lib/cmn/fs.h | 58 +++++ qse/lib/cmn/glob.c | 12 +- qse/lib/cmn/mbwc-str.c | 2 +- qse/lib/cmn/tmr.c | 6 +- qse/lib/http/httpd.c | 4 +- 21 files changed, 767 insertions(+), 238 deletions(-) create mode 100644 qse/lib/cmn/fs-delete.c diff --git a/qse/Makefile.in b/qse/Makefile.in index 69dd0bff..9b9cdaa2 100644 --- a/qse/Makefile.in +++ b/qse/Makefile.in @@ -51,7 +51,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = . -DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ +DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/README.in \ $(top_srcdir)/configure ac/config.guess ac/config.sub \ ac/depcomp ac/install-sh ac/ltmain.sh ac/missing diff --git a/qse/cmd/sed/sed.c b/qse/cmd/sed/sed.c index d0cd0de4..ba47be29 100644 --- a/qse/cmd/sed/sed.c +++ b/qse/cmd/sed/sed.c @@ -919,7 +919,7 @@ static int sed_main (int argc, qse_char_t* argv[]) if (tmpl_tmpfile) { - qse_fs_delete (fs, tmpl_tmpfile); + qse_fs_delfile (fs, tmpl_tmpfile, 0); QSE_MMGR_FREE (qse_sed_getmmgr(sed), tmpl_tmpfile); } print_exec_error (sed); diff --git a/qse/doc/page/installation.md b/qse/doc/page/installation.md index a7032896..09ead2ce 100644 --- a/qse/doc/page/installation.md +++ b/qse/doc/page/installation.md @@ -160,7 +160,7 @@ available for the native makefile for Watcom C/C++ for OS/2 only. - If /usr/include/netinet and /usr/include/net are missing, check if there are /usr/include/sys/netinet and /usr/include/sys/net. - f they exists, you can make these symbolic links. + if they exists, you can make symbolic links. cd /usr/include ln -sf sys/netinet netinet @@ -173,9 +173,10 @@ available for the native makefile for Watcom C/C++ for OS/2 only. for dificiency of the bundled make utility. - Do not include -g in CFLAGS. - ./configure GREP=/bin/grep RANLIB=/bin/true CFLAGS="" + ./configure GREP=/bin/grep RANLIB=/bin/true CFLAGS="" RAN -- Change RANLIB from "ranlib" to "true" in libltdl/libtool. +- Remove $(LIBLTDL) from LIBADD_LIB_COMMON in lib/awk/Makefile +- Remove $(LIBLTDL) from libqsehttp_la_LIBADD in lib/http/Makefile make diff --git a/qse/include/qse/cmn/dir.h b/qse/include/qse/cmn/dir.h index a423906e..31d4169d 100644 --- a/qse/include/qse/cmn/dir.h +++ b/qse/include/qse/cmn/dir.h @@ -101,6 +101,11 @@ QSE_EXPORT int qse_dir_reset ( const qse_char_t* path ); +/** + * The qse_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 + */ QSE_EXPORT int qse_dir_read ( qse_dir_t* dir, qse_dir_ent_t* ent diff --git a/qse/include/qse/cmn/env.h b/qse/include/qse/cmn/env.h index 559488f1..786aea24 100644 --- a/qse/include/qse/cmn/env.h +++ b/qse/include/qse/cmn/env.h @@ -30,7 +30,7 @@ #include #include -/** @file +/** \file * This file defines data types and functions that you can use to build * an environment block. */ @@ -44,9 +44,11 @@ #if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) typedef qse_wchar_t qse_env_char_t; # define QSE_ENV_CHAR_IS_WCHAR +# define QSE_SIZEOF_ENV_CHAR_T QSE_SIZEOF_WCHAR_T #else typedef qse_mchar_t qse_env_char_t; # define QSE_ENV_CHAR_IS_MCHAR +# define QSE_SIZEOF_ENV_CHAR_T QSE_SIZEOF_MCHAR_T #endif /** @@ -120,10 +122,10 @@ QSE_EXPORT qse_env_char_t** qse_env_getarr ( /** * The qse_env_insertwcs() function adds a new environment variable - * @a name with the @a value. If the @a value is #QSE_NULL, it takes + * \a name with the \a value. If the \a value is #QSE_NULL, it takes * the actual value from the system environment * - * @return 0 on success, -1 on failure + * \return 0 on success, -1 on failure */ QSE_EXPORT int qse_env_insertwcs ( qse_env_t* env, diff --git a/qse/include/qse/cmn/fs.h b/qse/include/qse/cmn/fs.h index 0ab91296..b18cdf25 100644 --- a/qse/include/qse/cmn/fs.h +++ b/qse/include/qse/cmn/fs.h @@ -27,27 +27,45 @@ #ifndef _QSE_CMN_FS_H_ #define _QSE_CMN_FS_H_ +/** \file + * This file defines data types and functions for manipulating files and + * directories on a file system. + */ + #include #include #include + +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + typedef qse_wchar_t qse_fs_char_t; +# define QSE_FS_CHAR_IS_WCHAR +# define QSE_SIZEOF_FS_CHAR_T QSE_SIZEOF_WCHAR_T +#else + typedef qse_mchar_t qse_fs_char_t; +# define QSE_FS_CHAR_IS_MCHAR +# define QSE_SIZEOF_FS_CHAR_T QSE_SIZEOF_MCHAR_T +#endif + enum qse_fs_errnum_t { QSE_FS_ENOERR = 0, QSE_FS_EOTHER, - QSE_FS_ENOIMPL, /**< not implemented */ - QSE_FS_ESYSERR, /**< subsystem error */ - QSE_FS_EINTERN, /**< internal error */ + QSE_FS_ENOIMPL, /**< not implemented */ + QSE_FS_ESYSERR, /**< subsystem error */ + QSE_FS_EINTERN, /**< internal error */ - QSE_FS_ENOMEM, /**< out of memory */ - QSE_FS_EINVAL, /**< invalid parameter */ - QSE_FS_EACCES, /**< access denied */ - QSE_FS_ENOENT, /**< no such file */ - QSE_FS_EEXIST, /**< already exist */ - QSE_FS_EINTR, /**< interrupted */ - QSE_FS_ENODIR, - QSE_FS_EISDIR, - QSE_FS_EXDEV + QSE_FS_ENOMEM, /**< out of memory */ + QSE_FS_EINVAL, /**< invalid parameter */ + QSE_FS_EACCES, /**< access denied */ + QSE_FS_ENOENT, /**< no such file or directory */ + QSE_FS_EEXIST, /**< already exist */ + QSE_FS_EINTR, /**< interrupted */ + QSE_FS_EISDIR, /**< is a directory */ + QSE_FS_ENOTDIR, /**< not a directory */ + QSE_FS_ENOTVOID, /**< directory not empty */ + QSE_FS_EXDEV, /**< cross device */ + QSE_FS_EGLOB /**< glob error */ }; typedef enum qse_fs_errnum_t qse_fs_errnum_t; @@ -58,6 +76,7 @@ enum qse_fs_ent_flag_t QSE_FS_ENT_SIZE = (1 << 2), QSE_FS_ENT_TIME = (1 << 3) }; +typedef enum qse_fs_ent_flag_t qse_fs_ent_flag_t; enum qse_fs_ent_type_t { @@ -82,7 +101,7 @@ struct qse_fs_ent_t qse_char_t* path; } name; qse_fs_ent_type_t type; - qse_foff_t size; + qse_foff_t size; struct { @@ -98,6 +117,8 @@ typedef struct qse_fs_ent_t qse_fs_ent_t; struct qse_fs_t { qse_mmgr_t* mmgr; + qse_cmgr_t* cmgr; /* for name conversion */ + qse_fs_errnum_t errnum; qse_fs_ent_t ent; qse_char_t* curdir; @@ -114,6 +135,30 @@ enum qse_fs_option_t /**< check directories against file system in qse_fs_chdir() */ QSE_FS_REALPATH = (1 << 2) }; +typedef enum qse_fs_option_t qse_fs_option_t; + + +enum qse_fs_delfile_flag_t +{ + QSE_FS_DELFILE_GLOB = (1 << 0), + + QSE_FS_DELFILEMBS_GLOB = QSE_FS_DELFILE_GLOB, + QSE_FS_DELFILEWCS_GLOB = QSE_FS_DELFILE_GLOB +}; +typedef enum qse_fs_delfile_flag_t qse_fs_delfile_flag_t; + +enum qse_fs_deldir_flag_t +{ + QSE_FS_DELDIR_GLOB = (1 << 0), + QSE_FS_DELDIR_RECURSIVE = (1 << 1), + + QSE_FS_DELDIRMBS_GLOB = QSE_FS_DELDIR_GLOB, + QSE_FS_DELDIRMBS_RECURSIVE = QSE_FS_DELDIR_RECURSIVE, + + QSE_FS_DELDIRWCS_GLOB = QSE_FS_DELDIR_GLOB, + QSE_FS_DELDIRWCS_RECURSIVE = QSE_FS_DELDIR_RECURSIVE +}; +typedef enum qse_fs_deldir_flag_t qse_fs_deldir_flag_t; #if defined(__cplusplus) extern "C" { @@ -174,12 +219,52 @@ QSE_EXPORT int qse_fs_move ( const qse_char_t* oldpath, const qse_char_t* newpath ); - -QSE_EXPORT int qse_fs_delete ( - qse_fs_t* fs, - const qse_char_t* path + + +QSE_EXPORT int qse_fs_mkdirmbs ( + qse_fs_t* fs, + const qse_mchar_t* path ); +QSE_EXPORT int qse_fs_mkdirwcs ( + qse_fs_t* fs, + const qse_mchar_t* path +); + +QSE_EXPORT int qse_fs_delfilembs ( + qse_fs_t* fs, + const qse_mchar_t* path, + int flags +); + +QSE_EXPORT int qse_fs_delfilewcs ( + qse_fs_t* fs, + const qse_wchar_t* path, + int flags +); + +QSE_EXPORT int qse_fs_deldirmbs ( + qse_fs_t* fs, + const qse_mchar_t* path, + int flags +); + +QSE_EXPORT int qse_fs_deldirwcs ( + qse_fs_t* fs, + const qse_wchar_t* path, + int flags +); + +#if defined(QSE_CHAR_IS_MCHAR) +# define qse_fs_mkdir(fs,path) qse_fs_mkdirmbs(fs,path) +# define qse_fs_delfile(fs,path,flags) qse_fs_delfilembs(fs,path,flags) +# define qse_fs_deldir(fs,path,flags) qse_fs_deldirmbs(fs,path,flags) +#else +# define qse_fs_mkdir(fs,path) qse_fs_mkdirwcs(fs,path) +# define qse_fs_delfile(fs,path,flags) qse_fs_delfilewcs(fs,path,flags) +# define qse_fs_deldir(fs,path,flags) qse_fs_deldirwcs(fs,path,flags) +#endif + #if defined(__cplusplus) } #endif diff --git a/qse/include/qse/cmn/glob.h b/qse/include/qse/cmn/glob.h index 6a15bf10..4556c18a 100644 --- a/qse/include/qse/cmn/glob.h +++ b/qse/include/qse/cmn/glob.h @@ -30,7 +30,7 @@ #include #include -/** @file +/** \file * This file provides functions, types, macros for wildcard expansion * in a path name. */ @@ -62,10 +62,10 @@ extern "C" { #endif /** - * The qse_glob() function finds path names matchin the @a pattern. - * It calls the call-back function @a cbimpl for each path name found. + * The qse_glob() function finds path names matchin the \a pattern. + * It calls the call-back function \a cbimpl for each path name found. * - * @return -1 on failure, 0 on no match, 1 if matches are found. + * \return -1 on failure, 0 on no match, 1 if matches are found. */ QSE_EXPORT int qse_glob ( const qse_char_t* pattern, diff --git a/qse/include/qse/cmn/mbwc.h b/qse/include/qse/cmn/mbwc.h index 017c99df..1ab0ceac 100644 --- a/qse/include/qse/cmn/mbwc.h +++ b/qse/include/qse/cmn/mbwc.h @@ -411,7 +411,7 @@ QSE_EXPORT int qse_wcstombs ( qse_size_t* mbslen /**< [in,out] buffer size for in, actual length for out*/ ); - + /** * The qse_wcsntombsn() function converts the first \a wcslen characters from * a wide character string \a wcs to a multibyte string and writes it to a diff --git a/qse/include/qse/cmn/tmr.h b/qse/include/qse/cmn/tmr.h index f0bb77f1..67a9a197 100644 --- a/qse/include/qse/cmn/tmr.h +++ b/qse/include/qse/cmn/tmr.h @@ -123,7 +123,7 @@ QSE_EXPORT qse_size_t qse_tmr_update ( const qse_tmr_event_t* event ); -QSE_EXPORT void qse_tmr_remove ( +QSE_EXPORT void qse_tmr_delete ( qse_tmr_t* tmr, qse_tmr_index_t index ); diff --git a/qse/lib/cmn/Makefile.am b/qse/lib/cmn/Makefile.am index 81ab34c0..832f3986 100644 --- a/qse/lib/cmn/Makefile.am +++ b/qse/lib/cmn/Makefile.am @@ -45,6 +45,7 @@ libqsecmn_la_SOURCES = \ fmt-intmax.c \ fmt-out.c \ fs.c \ + fs-delete.c \ fs-err.c \ fs-move.c \ glob.c \ diff --git a/qse/lib/cmn/Makefile.in b/qse/lib/cmn/Makefile.in index 79a9e0bb..0f202a21 100644 --- a/qse/lib/cmn/Makefile.in +++ b/qse/lib/cmn/Makefile.in @@ -107,36 +107,38 @@ libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.c \ alg-sort.c assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c \ - fma.c fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c \ - hton.c ipad.c lda.c main.c mb8.c mbwc.c mbwc-str.c mem.c mux.c \ - nwad.c nwad-skad.c nwif.c nwif-cfg.c nwio.c oht.c opt.c \ - path-base.c path-canon.c pio.c pma.c rbt.c rex.c sck.c sio.c \ - sll.c slmb.c str-beg.c str-cat.c str-chr.c str-cnv.c str-cmp.c \ - str-cpy.c str-del.c str-dup.c str-dyn.c str-end.c str-excl.c \ - str-fcpy.c str-fmt.c str-fnmat.c str-incl.c str-join.c \ - str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c str-rot.c \ - str-set.c str-spl.c str-spn.c str-str.c str-subst.c str-tok.c \ - str-trm.c str-word.c task.c time.c tio.c tmr.c tre.c tre-ast.c \ - tre-compile.c tre-match-bt.c tre-match-pa.c tre-parse.c \ - tre-stack.c uri.c utf8.c xma.c uni.c cp949.c cp950.c + fma.c fmt-intmax.c fmt-out.c fs.c fs-delete.c fs-err.c \ + fs-move.c glob.c hton.c ipad.c lda.c main.c mb8.c mbwc.c \ + mbwc-str.c mem.c mux.c nwad.c nwad-skad.c nwif.c nwif-cfg.c \ + nwio.c oht.c opt.c path-base.c path-canon.c pio.c pma.c rbt.c \ + rex.c sck.c sio.c sll.c slmb.c str-beg.c str-cat.c str-chr.c \ + str-cnv.c str-cmp.c str-cpy.c str-del.c str-dup.c str-dyn.c \ + str-end.c str-excl.c str-fcpy.c str-fmt.c str-fnmat.c \ + str-incl.c str-join.c str-len.c str-pac.c str-pbrk.c str-put.c \ + str-rev.c str-rot.c str-set.c str-spl.c str-spn.c str-str.c \ + str-subst.c str-tok.c str-trm.c str-word.c task.c time.c tio.c \ + tmr.c tre.c tre-ast.c tre-compile.c tre-match-bt.c \ + tre-match-pa.c tre-parse.c tre-stack.c uri.c utf8.c xma.c \ + uni.c cp949.c cp950.c @ENABLE_BUNDLED_UNICODE_TRUE@am__objects_1 = uni.lo @ENABLE_XCMGRS_TRUE@am__objects_2 = cp949.lo cp950.lo am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \ alg-sort.lo assert.lo chr.lo dir.lo dll.lo env.lo gdl.lo \ - htb.lo fio.lo fma.lo fmt-intmax.lo fmt-out.lo fs.lo fs-err.lo \ - fs-move.lo glob.lo hton.lo ipad.lo lda.lo main.lo mb8.lo \ - mbwc.lo mbwc-str.lo mem.lo mux.lo nwad.lo nwad-skad.lo nwif.lo \ - nwif-cfg.lo nwio.lo oht.lo opt.lo path-base.lo path-canon.lo \ - pio.lo pma.lo rbt.lo rex.lo sck.lo sio.lo sll.lo slmb.lo \ - str-beg.lo str-cat.lo str-chr.lo str-cnv.lo str-cmp.lo \ - str-cpy.lo str-del.lo str-dup.lo str-dyn.lo str-end.lo \ - str-excl.lo str-fcpy.lo str-fmt.lo str-fnmat.lo str-incl.lo \ - str-join.lo str-len.lo str-pac.lo str-pbrk.lo str-put.lo \ - str-rev.lo str-rot.lo str-set.lo str-spl.lo str-spn.lo \ - str-str.lo str-subst.lo str-tok.lo str-trm.lo str-word.lo \ - task.lo time.lo tio.lo tmr.lo tre.lo tre-ast.lo tre-compile.lo \ - tre-match-bt.lo tre-match-pa.lo tre-parse.lo tre-stack.lo \ - uri.lo utf8.lo xma.lo $(am__objects_1) $(am__objects_2) + htb.lo fio.lo fma.lo fmt-intmax.lo fmt-out.lo fs.lo \ + fs-delete.lo fs-err.lo fs-move.lo glob.lo hton.lo ipad.lo \ + lda.lo main.lo mb8.lo mbwc.lo mbwc-str.lo mem.lo mux.lo \ + nwad.lo nwad-skad.lo nwif.lo nwif-cfg.lo nwio.lo oht.lo opt.lo \ + path-base.lo path-canon.lo pio.lo pma.lo rbt.lo rex.lo sck.lo \ + sio.lo sll.lo slmb.lo str-beg.lo str-cat.lo str-chr.lo \ + str-cnv.lo str-cmp.lo str-cpy.lo str-del.lo str-dup.lo \ + str-dyn.lo str-end.lo str-excl.lo str-fcpy.lo str-fmt.lo \ + str-fnmat.lo str-incl.lo str-join.lo str-len.lo str-pac.lo \ + str-pbrk.lo str-put.lo str-rev.lo str-rot.lo str-set.lo \ + str-spl.lo str-spn.lo str-str.lo str-subst.lo str-tok.lo \ + str-trm.lo str-word.lo task.lo time.lo tio.lo tmr.lo tre.lo \ + tre-ast.lo tre-compile.lo tre-match-bt.lo tre-match-pa.lo \ + tre-parse.lo tre-stack.lo uri.lo utf8.lo xma.lo \ + $(am__objects_1) $(am__objects_2) libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -412,18 +414,19 @@ noinst_HEADERS = \ libqsecmn_la_SOURCES = alg-base64.c alg-rand.c alg-search.c alg-sort.c \ assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c fma.c \ - fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c hton.c \ - ipad.c lda.c main.c mb8.c mbwc.c mbwc-str.c mem.c mux.c nwad.c \ - nwad-skad.c nwif.c nwif-cfg.c nwio.c oht.c opt.c path-base.c \ - path-canon.c pio.c pma.c rbt.c rex.c sck.c sio.c sll.c slmb.c \ - str-beg.c str-cat.c str-chr.c str-cnv.c str-cmp.c str-cpy.c \ - str-del.c str-dup.c str-dyn.c str-end.c str-excl.c str-fcpy.c \ - str-fmt.c str-fnmat.c str-incl.c str-join.c str-len.c \ - str-pac.c str-pbrk.c str-put.c str-rev.c str-rot.c str-set.c \ - str-spl.c str-spn.c str-str.c str-subst.c str-tok.c str-trm.c \ - str-word.c task.c time.c tio.c tmr.c tre.c tre-ast.c \ - tre-compile.c tre-match-bt.c tre-match-pa.c tre-parse.c \ - tre-stack.c uri.c utf8.c xma.c $(am__append_1) $(am__append_2) + fmt-intmax.c fmt-out.c fs.c fs-delete.c fs-err.c fs-move.c \ + glob.c hton.c ipad.c lda.c main.c mb8.c mbwc.c mbwc-str.c \ + mem.c mux.c nwad.c nwad-skad.c nwif.c nwif-cfg.c nwio.c oht.c \ + opt.c path-base.c path-canon.c pio.c pma.c rbt.c rex.c sck.c \ + sio.c sll.c slmb.c str-beg.c str-cat.c str-chr.c str-cnv.c \ + str-cmp.c str-cpy.c str-del.c str-dup.c str-dyn.c str-end.c \ + str-excl.c str-fcpy.c str-fmt.c str-fnmat.c str-incl.c \ + str-join.c str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c \ + str-rot.c str-set.c str-spl.c str-spn.c str-str.c str-subst.c \ + str-tok.c str-trm.c str-word.c task.c time.c tio.c tmr.c tre.c \ + tre-ast.c tre-compile.c tre-match-bt.c tre-match-pa.c \ + tre-parse.c tre-stack.c uri.c utf8.c xma.c $(am__append_1) \ + $(am__append_2) libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined libqsecmn_la_LIBADD = $(SOCKET_LIBS) $(QUADMATH_LIBS) @ENABLE_CXX_TRUE@libqsecmnxx_la_SOURCES = \ @@ -525,6 +528,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fma.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt-intmax.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt-out.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs-delete.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs-err.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs-move.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs.Plo@am__quote@ diff --git a/qse/lib/cmn/dir.c b/qse/lib/cmn/dir.c index 9e624a96..9842a36b 100644 --- a/qse/lib/cmn/dir.c +++ b/qse/lib/cmn/dir.c @@ -65,13 +65,13 @@ struct qse_dir_t #if defined(_WIN32) HANDLE h; - WIN32_FIND_DATA wfd; + WIN32_FIND_DATA wfd; #elif defined(__OS2__) HDIR h; #if defined(FIL_STANDARDL) - FILEFINDBUF3L ffb; + FILEFINDBUF3L ffb; #else - FILEFINDBUF3 ffb; + FILEFINDBUF3 ffb; #endif ULONG count; #elif defined(__DOS__) @@ -317,7 +317,6 @@ static qse_char_t* make_dos_path (qse_dir_t* dir, const qse_char_t* path) return QSE_STR_PTR(&dir->tbuf); } - static qse_mchar_t* mkdospath (qse_dir_t* dir, const qse_char_t* path) { @@ -696,7 +695,7 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name) if (mbs_to_wbuf (dir, de->d_name, &dir->tbuf) == QSE_NULL) return -1; *name = QSE_STR_PTR(&dir->tbuf); } - #endif + #endif return 1; /* ------------------------------------------------------------------- */ @@ -716,15 +715,14 @@ static int read_ahead_and_sort (qse_dir_t* dir, const qse_char_t* path) { qse_size_t size; -#if defined(QSE_CHAR_IS_MCHAR) + #if defined(QSE_CHAR_IS_MCHAR) size = (qse_mbslen(name) + 1) * QSE_SIZEOF(qse_mchar_t); -#else + #else if (dir->flags & QSE_DIR_MBSPATH) size = (qse_mbslen(name) + 1) * QSE_SIZEOF(qse_mchar_t); else size = (qse_wcslen(name) + 1) * QSE_SIZEOF(qse_wchar_t); - -#endif + #endif if (qse_lda_pushheap (dir->stab, name, size) == (qse_size_t)-1) { diff --git a/qse/lib/cmn/fs-delete.c b/qse/lib/cmn/fs-delete.c new file mode 100644 index 00000000..8376b6ba --- /dev/null +++ b/qse/lib/cmn/fs-delete.c @@ -0,0 +1,461 @@ +/* + * $Id$ + * + Copyright (c) 2006-2014 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 "fs.h" + +static int delete_file (qse_fs_t* fs, const qse_fs_char_t* fspath) +{ + +#if defined(_WIN32) + + if (DeleteFile (fspath) == FALSE) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, GetLastError()); + return -1; + } + +#elif defined(__OS2__) + + APIRET rc; + + rc = DosDelete (fspath); + if (rc != NO_ERROR) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, rc); + return -1; + } + +#elif defined(__DOS__) + + if (unlink (fspath) <= -1) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, errno); + return -1; + } + +#else + + if (QSE_UNLINK (fspath) <= -1) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, errno); + return -1; + } + +#endif + + return 0; +} + +static int delete_directory (qse_fs_t* fs, const qse_fs_char_t* fspath) +{ +#if defined(_WIN32) + + if (RemoveDirectory (fspath) == FALSE) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, GetLastError()); + return -1; + } + +#elif defined(__OS2__) + + APIRET rc; + + rc = DosRmDir (fspath); + if (rc != NO_ERROR) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, rc); + return -1; + } + +#elif defined(__DOS__) + + if (rmdir (fspath) <= -1) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, errno); + return -1; + } + +#else + + if (QSE_RMDIR (fspath) <= -1) + { + fs->errnum = qse_fs_syserrtoerrnum (fs, errno); + return -1; + } + +#endif + + return 0; +} + +static int purge_path (qse_fs_t* fs, const qse_char_t* path) +{ + qse_dir_t* dir; + qse_dir_errnum_t errnum; + qse_dir_ent_t ent; + qse_fs_char_t* fspath; + int ret, x; + + dir = qse_dir_open (fs->mmgr, 0, path, 0, &errnum); + if (!dir) + { + /* not a directory. attempt to delete it as a file */ + fspath = qse_fs_makefspath(fs, path); + if (!fspath) return -1; + +/*TODO query: */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_file (fs, fspath); + qse_fs_freefspath (fs, path, fspath); + + return ret; + } + else + { + /* it must be a directory. delete all entries under it */ + const qse_char_t* seg[4]; + qse_char_t* joined_path; + + while (1) + { + x = qse_dir_read (dir, &ent); + if (x <= -1) + { + /* TODO: CONVERT dir->errnum to fs errnum */ + goto oops; + } + if (x == 0) break; /* no more entries */ + + /* skip . and .. */ + if (IS_CURDIR(ent.name) || IS_PREVDIR(ent.name)) continue; + + seg[0] = path; + seg[1] = DEFAULT_PATH_SEPARATOR; + seg[2] = ent.name; + seg[3] = QSE_NULL; + + joined_path = qse_stradup (seg, QSE_NULL, fs->mmgr); + if (!joined_path) + { + fs->errnum = QSE_FS_ENOMEM; + goto oops; + } + + /* join path and ent->name.... */ + fspath = qse_fs_makefspath(fs, joined_path); + if (!fspath) goto oops; +/*TODO query: */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_file (fs, fspath); + qse_fs_freefspath (fs, ent.name, fspath); + if (ret <= -1) ret = purge_path(fs, joined_path); + + QSE_MMGR_FREE (fs->mmgr, joined_path); + if (ret <= -1) goto oops; + } + + qse_dir_close (dir); + + fspath = qse_fs_makefspath (fs, path); + if (!fspath) goto oops; + + ret = delete_directory (fs, fspath); + + qse_fs_freefspath (fs, path, fspath); + + return ret; + + oops: + qse_dir_close (dir); + return -1; + } +} + + +/* --------------------------------------------------------------------- */ + + +static int delete_file_for_glob (const qse_cstr_t* path, void* ctx) +{ + qse_fs_t* fs = (qse_fs_t*)ctx; + qse_fs_char_t* fspath; + int ret; + + /* skip . and .. */ + if (IS_CURDIR(path->ptr) || IS_PREVDIR(path->ptr)) return 0; + + fspath = qse_fs_makefspath (fs, path->ptr); + if (!fspath) return -1; + +/*TODO query: */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_file (fs, fspath); + + qse_fs_freefspath (fs, path->ptr, fspath); + + return ret; +} + +int qse_fs_delfilembs (qse_fs_t* fs, const qse_mchar_t* path, int flags) +{ + int ret; + + if (flags & QSE_FS_DELFILEMBS_GLOB) + { + qse_char_t* xpath; + + xpath = (qse_char_t*)make_str_with_mbs (fs, path); + if (!xpath) + { + fs->errnum = QSE_FS_ENOMEM; + return -1; + } + + ret = qse_glob (xpath, delete_file_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr); + + free_str_with_mbs (fs, path, xpath); + + if (ret <= -1) + { + fs->errnum = QSE_FS_EGLOB; + return -1; + } + } + else + { + qse_fs_char_t* fspath; + + fspath = qse_fs_makefspathformbs (fs, path); + if (!fspath) return -1; + +/* TODO: query */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_file (fs, fspath); + + qse_fs_freefspathformbs (fs, path, fspath); + } + + return ret; +} + +int qse_fs_delfilewcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) +{ + int ret; + + if (flags & QSE_FS_DELFILEWCS_GLOB) + { + qse_char_t* xpath; + + xpath = (qse_char_t*)make_str_with_wcs (fs, path); + if (!xpath) + { + fs->errnum = QSE_FS_ENOMEM; + return -1; + } + + ret = qse_glob (xpath, delete_file_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr); + + free_str_with_wcs (fs, path, xpath); + + if (ret <= -1) + { + fs->errnum = QSE_FS_EGLOB; + return -1; + } + } + else + { + qse_fs_char_t* fspath; + + fspath = qse_fs_makefspathforwcs (fs, path); + if (!fspath) return -1; + +/* TODO: query */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_file (fs, fspath); + + qse_fs_freefspathforwcs (fs, path, fspath); + } + + return ret; +} + + +/* --------------------------------------------------------------------- */ + +static int delete_directory_for_glob (const qse_cstr_t* path, void* ctx) +{ + qse_fs_t* fs = (qse_fs_t*)ctx; + qse_fs_char_t* fspath; + int ret; + + /* skip . and .. */ + if (IS_CURDIR(path->ptr) || IS_PREVDIR(path->ptr)) return 0; + + fspath = qse_fs_makefspath (fs, path->ptr); + if (!fspath) return -1; + +/*TODO query: */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_directory (fs, fspath); + + qse_fs_freefspath (fs, path->ptr, fspath); + + return ret; +} + +static int purge_path_for_glob (const qse_cstr_t* path, void* ctx) +{ + qse_fs_t* fs = (qse_fs_t*)ctx; + int ret; + + /* skip . and .. */ + if (IS_CURDIR(path->ptr) || IS_PREVDIR(path->ptr)) return 0; + +/*TODO query: */ +/*if (fs->cb.delete) fs->cb.delete (joined_path);*/ + return purge_path (fs, path->ptr); +} + +int qse_fs_deldirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) +{ + int ret; + + if (flags & QSE_FS_DELDIRMBS_GLOB) + { + qse_char_t* xpath; + + xpath = (qse_char_t*)make_str_with_mbs (fs, path); + if (!xpath) + { + fs->errnum = QSE_FS_ENOMEM; + return -1; + } + + if (flags & QSE_FS_DELDIRMBS_RECURSIVE) + { + ret = qse_glob (xpath, purge_path_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr); + } + else + { + ret = qse_glob (xpath, delete_directory_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr); + } + + free_str_with_mbs (fs, path, xpath); + + if (ret <= -1) fs->errnum = QSE_FS_EGLOB; + } + else if (flags & QSE_FS_DELDIRMBS_RECURSIVE) + { + qse_char_t* xpath; + + xpath = (qse_char_t*)make_str_with_mbs (fs, path); + if (!xpath) + { + fs->errnum = QSE_FS_ENOMEM; + return -1; + } + + ret = purge_path (fs, xpath); + + free_str_with_mbs (fs, path, xpath); + } + else + { + qse_fs_char_t* fspath; + + fspath = qse_fs_makefspathformbs (fs, path); + if (!fspath) return -1; + +/* TODO: query */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_directory (fs, fspath); + + qse_fs_freefspathformbs (fs, path, fspath); + } + + return ret; +} + +int qse_fs_deldirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) +{ + int ret; + + if (flags & QSE_FS_DELDIRWCS_GLOB) + { + qse_char_t* xpath; + + xpath = (qse_char_t*)make_str_with_wcs (fs, path); + if (!xpath) + { + fs->errnum = QSE_FS_ENOMEM; + return -1; + } + + if (flags & QSE_FS_DELDIRWCS_RECURSIVE) + { + ret = qse_glob (xpath, purge_path_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr); + } + else + { + ret = qse_glob (xpath, delete_directory_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr); + } + + free_str_with_wcs (fs, path, xpath); + + if (ret <= -1) fs->errnum = QSE_FS_EGLOB; + } + else if (flags & QSE_FS_DELDIRWCS_RECURSIVE) + { + qse_char_t* xpath; + + xpath = (qse_char_t*)make_str_with_wcs (fs, path); + if (!xpath) + { + fs->errnum = QSE_FS_ENOMEM; + return -1; + } + + ret = purge_path (fs, xpath); + + free_str_with_wcs (fs, path, xpath); + } + else + { + qse_fs_char_t* fspath; + + fspath = qse_fs_makefspathforwcs (fs, path); + if (!fspath) return -1; + +/* TODO: query */ +/*if (fs->cb.delete) fs->cb.delete (path);*/ + ret = delete_directory (fs, fspath); + + qse_fs_freefspathforwcs (fs, path, fspath); + } + + return ret; +} diff --git a/qse/lib/cmn/fs-err.c b/qse/lib/cmn/fs-err.c index 587dd6fa..cce31aba 100644 --- a/qse/lib/cmn/fs-err.c +++ b/qse/lib/cmn/fs-err.c @@ -60,7 +60,10 @@ qse_fs_errnum_t qse_fs_syserrtoerrnum (qse_fs_t* fs, qse_fs_syserr_t e) case ERROR_NOT_SAME_DEVICE: return QSE_FS_EXDEV; - + + case ERROR_DIR_NOT_EMPTY; + return QSE_FS_ENOTEMPTY; + default: return QSE_FS_ESYSERR; } @@ -109,7 +112,6 @@ qse_fs_errnum_t qse_fs_syserrtoerrnum (qse_fs_t* fs, qse_fs_syserr_t e) return QSE_FS_EACCES; case ENOENT: - case ENOTDIR: return QSE_FS_ENOENT; case EEXIST: @@ -118,6 +120,9 @@ qse_fs_errnum_t qse_fs_syserrtoerrnum (qse_fs_t* fs, qse_fs_syserr_t e) case EISDIR: return QSE_FS_EISDIR; + case ENOTDIR: + return QSE_FS_ENOTDIR; + default: return QSE_FS_ESYSERR; } @@ -136,7 +141,6 @@ qse_fs_errnum_t qse_fs_syserrtoerrnum (qse_fs_t* fs, qse_fs_syserr_t e) return QSE_FS_EACCES; case ENOENT: - case ENOTDIR: return QSE_FS_ENOENT; case EEXIST: @@ -148,6 +152,12 @@ qse_fs_errnum_t qse_fs_syserrtoerrnum (qse_fs_t* fs, qse_fs_syserr_t e) case EISDIR: return QSE_FS_EISDIR; + case ENOTDIR: + return QSE_FS_ENOTDIR; + + case ENOTEMPTY: + return QSE_FS_ENOTVOID; + case EXDEV: return QSE_FS_EXDEV; diff --git a/qse/lib/cmn/fs-move.c b/qse/lib/cmn/fs-move.c index 4f669315..e4de5869 100644 --- a/qse/lib/cmn/fs-move.c +++ b/qse/lib/cmn/fs-move.c @@ -378,150 +378,15 @@ struct del_op_t #endif }; -int qse_fs_delete (qse_fs_t* fs, const qse_char_t* path) -{ - /* TODO: improve this function to support fs->curdir ... etc - * delete directory ... etc */ - -#if defined(_WIN32) - - if (DeleteFile (path) == FALSE) - { - fs->errnum = qse_fs_syserrtoerrnum (fs, GetLastError()); - return -1; - } - - return 0; +/* +int qse_cpfile +int qse_mvfile +* +int qse_rmdir +qse_mkdir -#elif defined(__OS2__) +qse_statfile - /* ------------------------------------------------------ */ - - APIRET rc; - del_op_t dop; - - - QSE_MEMSET (&dop, 0, QSE_SIZEOF(dop)); - - #if defined(QSE_CHAR_IS_MCHAR) - dop.path = path; - #else - dop.path = qse_wcstombsdup (path, QSE_NULL, fs->mmgr); - if (dop.path == QSE_NULL) - { - fs->errnum = QSE_FS_ENOMEM; - goto oops; - } - #endif - - rc = DosDelete (dop.path); - if (rc != NO_ERROR) - { - fs->errnum = qse_fs_syserrtoerrnum (fs, rc); - goto oops; - } - - #if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ - #else - QSE_MMGR_FREE (fs->mmgr, dop.path); - #endif - return 0; - - /* ------------------------------------------------------ */ - -oops: - #if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ - #else - if (dop.path) QSE_MMGR_FREE (fs->mmgr, dop.path); - #endif - return -1; - -#elif defined(__DOS__) - - /* ------------------------------------------------------ */ - - del_op_t dop; - - QSE_MEMSET (&dop, 0, QSE_SIZEOF(dop)); - - #if defined(QSE_CHAR_IS_MCHAR) - dop.path = path; - #else - dop.path = qse_wcstombsdup (path, QSE_NULL, fs->mmgr); - if (dop.path == QSE_NULL) - { - fs->errnum = QSE_FS_ENOMEM; - goto oops; - } - #endif - - if (unlink (dop.path) <= -1) - { - fs->errnum = qse_fs_syserrtoerrnum (fs, errno); - goto oops; - } - - #if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ - #else - QSE_MMGR_FREE (fs->mmgr, dop.path); - #endif - return 0; - -oops: - #if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ - #else - if (dop.path) QSE_MMGR_FREE (fs->mmgr, dop.path); - #endif - return -1; - - /* ------------------------------------------------------ */ - -#else - - /* ------------------------------------------------------ */ - - del_op_t dop; - - QSE_MEMSET (&dop, 0, QSE_SIZEOF(dop)); - - #if defined(QSE_CHAR_IS_MCHAR) - dop.path = path; - #else - dop.path = qse_wcstombsdup (path, QSE_NULL, fs->mmgr); - if (dop.path == QSE_NULL) - { - fs->errnum = QSE_FS_ENOMEM; - goto oops; - } - #endif - - if (QSE_UNLINK (dop.path) <= -1) - { - fs->errnum = qse_fs_syserrtoerrnum (fs, errno); - goto oops; - } - - #if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ - #else - QSE_MMGR_FREE (fs->mmgr, dop.path); - #endif - return 0; - -oops: - #if defined(QSE_CHAR_IS_MCHAR) - /* nothing to do */ - #else - if (dop.path) QSE_MMGR_FREE (fs->mmgr, dop.path); - #endif - return -1; - - /* ------------------------------------------------------ */ - -#endif -} +qse_rm...???? +*/ diff --git a/qse/lib/cmn/fs.c b/qse/lib/cmn/fs.c index a8287cea..21a8233f 100644 --- a/qse/lib/cmn/fs.c +++ b/qse/lib/cmn/fs.c @@ -85,6 +85,7 @@ int qse_fs_init (qse_fs_t* fs, qse_mmgr_t* mmgr) { QSE_MEMSET (fs, 0, QSE_SIZEOF(*fs)); fs->mmgr = mmgr; + fs->cmgr = qse_getdflcmgr(); return 0; } @@ -554,7 +555,7 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags) info = fs->info; if (info == QSE_NULL) { - fs->errnum = QSE_FS_ENODIR; + fs->errnum = QSE_FS_ENOTDIR; return QSE_NULL; } @@ -710,3 +711,41 @@ int qse_fs_rewind (qse_fs_t* fs) return 0; } + +qse_fs_char_t* qse_fs_makefspathformbs (qse_fs_t* fs, const qse_mchar_t* path) +{ + qse_fs_char_t* fspath; + +#if defined(QSE_FS_CHAR_IS_MCHAR) + fspath = path; +#else + fspath = qse_mbstowcsdupwithcmgr (path, QSE_NULL, fs->mmgrm fs->cmgr); + if (!fspath) fs->errnum = QSE_FS_ENOMEM; +#endif + + return fspath; +} + +qse_fs_char_t* qse_fs_makefspathforwcs (qse_fs_t* fs, const qse_wchar_t* path) +{ + qse_fs_char_t* fspath; + +#if defined(QSE_FS_CHAR_IS_MCHAR) + fspath = qse_wcstombsdupwithcmgr (path, QSE_NULL, fs->mmgr, fs->cmgr); + if (!fspath) fs->errnum = QSE_FS_ENOMEM; +#else + fspath = path; +#endif + + return fspath; +} + +void qse_fs_freefspathformbs (qse_fs_t* fs, const qse_mchar_t* path, qse_fs_char_t* fspath) +{ + if (path != fspath) QSE_MMGR_FREE (fs->mmgr, fspath); +} + +void qse_fs_freefspathforwcs (qse_fs_t* fs, const qse_wchar_t* path, qse_fs_char_t* fspath) +{ + if (path != fspath) QSE_MMGR_FREE (fs->mmgr, fspath); +} diff --git a/qse/lib/cmn/fs.h b/qse/lib/cmn/fs.h index 6b78ca9e..ca30011e 100644 --- a/qse/lib/cmn/fs.h +++ b/qse/lib/cmn/fs.h @@ -25,6 +25,11 @@ */ #include +#include +#include +#include +#include +#include #if defined(_WIN32) # include @@ -43,6 +48,29 @@ typedef int qse_fs_syserr_t; #endif +#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) +# define DEFAULT_GLOB_FLAGS (QSE_GLOB_PERIOD | QSE_GLOB_NOESCAPE | QSE_GLOB_IGNORECASE) +# define DEFAULT_PATH_SEPARATOR QSE_T("\\") +#else +# define DEFAULT_GLOB_FLAGS (QSE_GLOB_PERIOD) +# define DEFAULT_PATH_SEPARATOR QSE_T("/") +#endif + +#define IS_CURDIR(x) ((x)[0] == QSE_T('.') && (x)[1] == QSE_T('\0')) +#define IS_PREVDIR(x) ((x)[0] == QSE_T('.') && (x)[1] == QSE_T('.') && (x)[2] == QSE_T('\0')) + +#if defined(QSE_CHAR_IS_MCHAR) +# define make_str_with_wcs(fs,wcs) qse_wcstombsdupwithcmgr(wcs,QSE_NULL,(fs)->mmgr,(fs)->cmgr) +# define make_str_with_mbs(fs,mbs) (mbs) +# define free_str_with_wcs(fs,wcs,str) QSE_MMGR_FREE((fs)->mmgr,str) +# define free_str_with_mbs(fs,mbs,str) +#else +# define make_str_with_wcs(fs,wcs) (wcs) +# define make_str_with_mbs(fs,mbs) qse_mbstowcsdupwithcmgr(mbs,QSE_NULL,(fs)->mmgr,(fs)->cmgr) +# define free_str_with_wcs(fs,wcs,str) +# define free_str_with_mbs(fs,mbs,str) QSE_MMGR_FREE((fs)->mmgr,str) +#endif + #if defined(__cplusplus) extern "C" { #endif @@ -52,6 +80,36 @@ qse_fs_errnum_t qse_fs_syserrtoerrnum ( qse_fs_syserr_t e ); +qse_fs_char_t* qse_fs_makefspathformbs ( + qse_fs_t* fs, + const qse_mchar_t* path +); + +qse_fs_char_t* qse_fs_makefspathforwcs ( + qse_fs_t* fs, + const qse_wchar_t* path +); + +void qse_fs_freefspathformbs ( + qse_fs_t* fs, + const qse_mchar_t* path, + qse_fs_char_t* fspath +); + +void qse_fs_freefspathforwcs ( + qse_fs_t* fs, + const qse_wchar_t* path, + qse_fs_char_t* fspath +); + +#if defined(QSE_CHAR_IS_MCHAR) +# define qse_fs_makefspath(fs,path) qse_fs_makefspathformbs(fs,path) +# define qse_fs_freefspath(fs,path,fspath) qse_fs_freefspathformbs(fs,path,fspath); +#else +# define qse_fs_makefspath(fs,path) qse_fs_makefspathforwcs(fs,path) +# define qse_fs_freefspath(fs,path,fspath) qse_fs_freefspathforwcs(fs,path,fspath); +#endif + #if defined(__cplusplus) } #endif diff --git a/qse/lib/cmn/glob.c b/qse/lib/cmn/glob.c index 19f96784..d6bc9489 100644 --- a/qse/lib/cmn/glob.c +++ b/qse/lib/cmn/glob.c @@ -242,7 +242,7 @@ static int get_next_segment (glob_t* g, segment_t* seg) seg->wild = 0; seg->esc = 0; } -#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) + #if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) else if (IS_DRIVE(seg->ptr)) { seg->type = ROOT; @@ -253,7 +253,7 @@ static int get_next_segment (glob_t* g, segment_t* seg) seg->wild = 0; seg->esc = 0; } -#endif + #endif else { int escaped = 0; @@ -463,7 +463,7 @@ entry: { if (seg->next) { -#if defined(NO_RECURSION) + #if defined(NO_RECURSION) if (g->free) { r = g->free; @@ -492,7 +492,7 @@ entry: resume: ; -#else + #else segment_t save; int x; @@ -500,7 +500,7 @@ entry: x = search (g, seg); *seg = save; if (x <= -1) goto oops; -#endif + #endif } else { @@ -551,7 +551,7 @@ entry: return 0; oops: - if (dp) qse_dir_close (dp); + if (dp) qse_dir_close (dp); #if defined(NO_RECURSION) while (g->stack) diff --git a/qse/lib/cmn/mbwc-str.c b/qse/lib/cmn/mbwc-str.c index 79cea16f..22b54fb6 100644 --- a/qse/lib/cmn/mbwc-str.c +++ b/qse/lib/cmn/mbwc-str.c @@ -295,7 +295,7 @@ static qse_wchar_t* mbs_to_wcs_dup_with_cmgr ( mbs, &ml, QSE_NULL, &wl, cmgr, all) <= -1) return QSE_NULL; wl++; /* for terminating null */ - wcs = QSE_MMGR_ALLOC (mmgr, wl * QSE_SIZEOF(*wcs)); + wcs = QSE_MMGR_ALLOC (mmgr, wl * QSE_SIZEOF(*wcs)); if (wcs == QSE_NULL) return QSE_NULL; mbs_to_wcs_with_cmgr (mbs, &ml, wcs, &wl, cmgr, all); diff --git a/qse/lib/cmn/tmr.c b/qse/lib/cmn/tmr.c index 0ef6a955..36dac513 100644 --- a/qse/lib/cmn/tmr.c +++ b/qse/lib/cmn/tmr.c @@ -95,7 +95,7 @@ void* qse_tmr_getxtn (qse_tmr_t* tmr) void qse_tmr_clear (qse_tmr_t* tmr) { - while (tmr->size > 0) qse_tmr_remove (tmr, 0); + while (tmr->size > 0) qse_tmr_delete (tmr, 0); } static qse_tmr_index_t sift_up (qse_tmr_t* tmr, qse_tmr_index_t index, int notify) @@ -179,7 +179,7 @@ static qse_tmr_index_t sift_down (qse_tmr_t* tmr, qse_tmr_index_t index, int not return index; } -void qse_tmr_remove (qse_tmr_t* tmr, qse_tmr_index_t index) +void qse_tmr_delete (qse_tmr_t* tmr, qse_tmr_index_t index) { qse_tmr_event_t item; @@ -243,7 +243,7 @@ qse_size_t qse_tmr_fire (qse_tmr_t* tmr, const qse_ntime_t* tm) if (qse_cmptime(&tmr->event[0].when, &now) > 0) break; event = tmr->event[0]; - qse_tmr_remove (tmr, 0); /* remove the registered event structure */ + qse_tmr_delete (tmr, 0); /* remove the registered event structure */ fire_count++; event.handler (tmr, &now, &event); /* then fire the event */ diff --git a/qse/lib/http/httpd.c b/qse/lib/http/httpd.c index 9bc70620..f1d6c733 100644 --- a/qse/lib/http/httpd.c +++ b/qse/lib/http/httpd.c @@ -2202,7 +2202,7 @@ int qse_httpd_inserttimerevent (qse_httpd_t* httpd, const qse_httpd_timer_event_ void qse_httpd_removetimerevent (qse_httpd_t* httpd, qse_httpd_timer_index_t index) { - qse_tmr_remove (httpd->tmr, index); + qse_tmr_delete (httpd->tmr, index); } /* qse_httpd_insert_timer_event() is a lighter-weight version of @@ -2222,7 +2222,7 @@ int qse_httpd_insert_timer_event (qse_httpd_t* httpd, const qse_tmr_event_t* eve } void qse_httpd_remove_timer_event (qse_httpd_t* httpd, qse_tmr_index_t index) { - qse_tmr_remove (httpd->tmr, index); + qse_tmr_delete (httpd->tmr, index); } /* ----------------------------------------------------------------------- */