renamed qse_tmr_remove() to qse_tmr_delete().

removed qse_fs_delete() and added qse_fs_delfile()/qse_fs_deldir() with some new options
This commit is contained in:
2014-11-24 17:01:04 +00:00
parent 8678660b82
commit 7d21e90ce2
21 changed files with 767 additions and 238 deletions

View File

@ -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 \

View File

@ -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@

View File

@ -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)
{

461
qse/lib/cmn/fs-delete.c Normal file
View File

@ -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;
}

View File

@ -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;

View File

@ -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...????
*/

View File

@ -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);
}

View File

@ -25,6 +25,11 @@
*/
#include <qse/cmn/fs.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/glob.h>
#include <qse/cmn/dir.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/str.h>
#if defined(_WIN32)
# include <windows.h>
@ -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

View File

@ -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)

View File

@ -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);

View File

@ -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 */

View File

@ -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);
}
/* ----------------------------------------------------------------------- */