fixed glob.c to use qse_stat_t instead of struct stat.

fixed other minor problems
This commit is contained in:
2014-11-28 17:01:29 +00:00
parent 947f5a8d8d
commit 44129510dc
12 changed files with 82 additions and 38 deletions

View File

@ -61,8 +61,8 @@ 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;
case ERROR_DIR_NOT_EMPTY:
return QSE_FS_ENOTVOID;
default:
return QSE_FS_ESYSERR;

View File

@ -44,6 +44,16 @@ static int make_directory_in_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
rc = DosMkDir (fspath, QSE_NULL);
if (rc != NO_ERROR)
{
FILESTATUS3L ffb;
if (DosQueryPathInfo (fspath, FIL_STANDARDL, &ffb, QSE_SIZEOF(ffb)) == NO_ERROR)
{
if (ffb.attrFile & FILE_DIRECTORY)
{
fs->errnum = QSE_FS_EEXIST;
return -1;
}
}
fs->errnum = qse_fs_syserrtoerrnum (fs, rc);
return -1;
}
@ -52,6 +62,16 @@ static int make_directory_in_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
if (mkdir (fspath) <= -1)
{
struct stat st;
if (errno != EEXIST && stat (fspath, &st) >= 0)
{
if (S_ISDIR(st.st_mode))
{
fs->errnum = QSE_FS_EEXIST;
return -1;
}
}
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
return -1;
}
@ -73,24 +93,44 @@ static int make_directory_in_fs (qse_fs_t* fs, const qse_fs_char_t* fspath)
static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath)
{
qse_fs_char_t* p, c;
qse_fs_char_t* core, * p, c;
int ret = 0;
p = get_fspath_core (fspath);
canon_fspath (p, p, 0);
core = get_fspath_core (fspath);
canon_fspath (core, core, 0);
if (*core == QSE_FS_T('\0'))
{
fs->errnum = QSE_FS_EINVAL;
return -1;
}
p = core;
if (IS_FSPATHSEP(*p)) p++;
for (; *p; p++)
{
if (IS_FSPATHSEP(*p))
{
#if defined(_WIN32) || defined(__DOS__) || defined(__OS2__)
/* exclude the separtor from the path name */
c = *p;
*p = QSE_FS_T('\0');
#else
/* include the separater in the path name */
c = *(p + 1);
*(p + 1) = QSE_FS_T('\0');
#endif
ret = make_directory_in_fs (fs, fspath);
if (ret <= -1 && fs->errnum != QSE_FS_EEXIST)
{
return -1;
goto done; /* abort */
}
#if defined(_WIN32) || defined(__DOS__) || defined(__OS2__)
*p = c;
#else
*(p + 1) = c;
#endif
}
}

View File

@ -183,8 +183,6 @@ int qse_fs_setopt (qse_fs_t* fs, qse_fs_opt_t id, const void* value)
return -1;
}
static QSE_INLINE info_t* get_info (qse_fs_t* fs)
{
info_t* info;
@ -454,7 +452,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_ENOENT; /* TODO: is this correct? */
return QSE_NULL;
}
@ -757,7 +755,7 @@ qse_fs_char_t* qse_fs_makefspathformbs (qse_fs_t* fs, const qse_mchar_t* path)
#if defined(QSE_FS_CHAR_IS_MCHAR)
fspath = path;
#else
fspath = qse_mbstowcsdupwithcmgr (path, QSE_NULL, fs->mmgrm fs->cmgr);
fspath = qse_mbstowcsdupwithcmgr (path, QSE_NULL, fs->mmgr, fs->cmgr);
if (!fspath) fs->errnum = QSE_FS_ENOMEM;
#endif
@ -785,7 +783,7 @@ qse_fs_char_t* qse_fs_dupfspathformbs (qse_fs_t* fs, const qse_mchar_t* path)
#if defined(QSE_FS_CHAR_IS_MCHAR)
fspath = qse_mbsdup (path, fs->mmgr);
#else
fspath = qse_mbstowcsdupwithcmgr (path, QSE_NULL, fs->mmgrm fs->cmgr);
fspath = qse_mbstowcsdupwithcmgr (path, QSE_NULL, fs->mmgr, fs->cmgr);
if (!fspath) fs->errnum = QSE_FS_ENOMEM;
#endif
@ -808,10 +806,10 @@ qse_fs_char_t* qse_fs_dupfspathforwcs (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)
{
if (path != fspath) QSE_MMGR_FREE (fs->mmgr, fspath);
if (path != (const qse_mchar_t*)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);
if (path != (const qse_wchar_t*)fspath) QSE_MMGR_FREE (fs->mmgr, fspath);
}

View File

@ -37,6 +37,7 @@
typedef DWORD qse_fs_syserr_t;
#elif defined(__OS2__)
# define INCL_DOSERRORS
# define INCL_DOSFILEMGR
# include <os2.h>
typedef APIRET qse_fs_syserr_t;
#elif defined(__DOS__)

View File

@ -182,7 +182,11 @@ static int path_exists (glob_t* g, const qse_char_t* name)
#else
/* ------------------------------------------------------------------- */
struct stat st;
#if defined(HAVE_LSTAT)
qse_lstat_t st;
#else
qse_stat_t st;
#endif
const qse_mchar_t* mptr;
#if defined(QSE_CHAR_IS_MCHAR)
@ -193,10 +197,10 @@ static int path_exists (glob_t* g, const qse_char_t* name)
#endif
#if defined(HAVE_LSTAT)
return (QSE_LSTAT (mptr, &st) == 0)? 1: 0;
return (QSE_LSTAT (mptr, &st) <= -1)? 0: 1;
#else
/* use stat() if no lstat() is available. */
return (QSE_STAT (mptr, &st) == 0)? 1: 0;
return (QSE_STAT (mptr, &st) <= -1)? 0: 1;
#endif
/* ------------------------------------------------------------------- */
@ -353,7 +357,6 @@ static int handle_non_wild_segments (glob_t* g, segment_t* seg)
QSE_ASSERT (seg->type != NONE && !seg->wild);
if (seg->sep && qse_str_ccat (&g->path, seg->sep) == (qse_size_t)-1) return -1;
if (seg->esc)
{
/* if the segment contains escape sequences,

View File

@ -83,20 +83,20 @@ int qse_ismbsdrivecurpath (const qse_mchar_t* path)
qse_mchar_t* qse_getmbspathcore (const qse_mchar_t* path)
{
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
if (IS_MDRIVE(path)) return path + 2;
if (IS_MDRIVE(path)) return (qse_mchar_t*)path + 2;
#if defined(_WIN32)
else if (IS_MSEP(*ptr) && IS_MSEP(*(ptr + 1)) && !IS_MSEP_OR_MNIL(*(ptr + 2)))
else if (IS_MSEP(*path) && IS_MSEP(*(path + 1)) && !IS_MSEP_OR_MNIL(*(path + 2)))
{
/* UNC Path */
ptr += 2;
do { ptr++; } while (!IS_MSEP_OR_MNIL(*ptr));
if (IS_MSEP(*ptr)) return ptr;
path += 2;
do { path++; } while (!IS_MSEP_OR_MNIL(*path));
if (IS_MSEP(*path)) return (qse_mchar_t*)path;
}
#endif
/* TOOD: \\server\XXX \\.\XXX \\?\XXX \\?\UNC\server\XXX */
#endif
return path;
return (qse_mchar_t*)path;
}
qse_size_t qse_canonmbspath (const qse_mchar_t* path, qse_mchar_t* canon, int flags)
@ -303,7 +303,7 @@ qse_size_t qse_canonmbspath (const qse_mchar_t* path, qse_mchar_t* canon, int fl
else
{
/* just null-terminate the canonical path normally */
dst[0] = QSE_MT('\0');
dst[0] = QSE_MT('\0');
canon_len = dst - canon;
}
@ -417,18 +417,18 @@ int qse_iswcsdrivecurpath (const qse_wchar_t* path)
qse_wchar_t* qse_getwcspathcore (const qse_wchar_t* path)
{
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
if (IS_WDRIVE(path)) return path + 2;
if (IS_WDRIVE(path)) return (qse_wchar_t*)path + 2;
#if defined(_WIN32)
else if (IS_WSEP(*ptr) && IS_WSEP(*(ptr + 1)) && !IS_WSEP_OR_WNIL(*(ptr + 2)))
else if (IS_WSEP(*path) && IS_WSEP(*(path + 1)) && !IS_WSEP_OR_WNIL(*(path + 2)))
{
/* UNC Path */
ptr += 2;
do { ptr++; } while (!IS_WSEP_OR_WNIL(*ptr));
if (IS_WSEP(*ptr)) return ptr;
path += 2;
do { path++; } while (!IS_WSEP_OR_WNIL(*path));
if (IS_WSEP(*path)) return (qse_wchar_t*)path;
}
#endif
#endif
return path;
return (qse_wchar_t*)path;
}
qse_size_t qse_canonwcspath (const qse_wchar_t* path, qse_wchar_t* canon, int flags)