added qse_dir_geterrnum()

This commit is contained in:
hyung-hwan 2012-12-25 14:10:02 +00:00
parent c133af0e55
commit b8c66b5b8d
16 changed files with 446 additions and 363 deletions

View File

@ -2,7 +2,7 @@ The directory contains makefiles generated with bakefile(www.bakefile.org)
for non-autoconf environments. for non-autoconf environments.
- os2-watcom/makefile Watcom C/C++ for OS/2 - os2-watcom/makefile Watcom C/C++ for OS/2
- win32-watcom/makefile Watcom C/C++ for OS/2 - win32-watcom/makefile Watcom C/C++ for Windows
- win32-borland/makefile Borland C/C++ for Windows - win32-borland/makefile Borland C/C++ for Windows
- win32-msvc/makefile Microsoft Visual C/C++ for Windows - win32-msvc/makefile Microsoft Visual C/C++ for Windows

4
qse/configure vendored
View File

@ -18183,7 +18183,7 @@ rm -f core conftest.err conftest.$ac_objext \
LIBS=$OLD_LIBS LIBS=$OLD_LIBS
CPPFLAGS=$OLD_CPPFLAGS CPPFLAGS=$OLD_CPPFLAGS
else else
Echo Unable to find suitable MPI Compiler. Try setting MPICC. echo Unable to find suitable MPI Compiler. Try setting MPICC.
have_C_mpi='no' have_C_mpi='no'
fi fi
@ -18331,7 +18331,7 @@ rm -f core conftest.err conftest.$ac_objext \
LIBS=$OLD_LIBS LIBS=$OLD_LIBS
CPPFLAGS=$OLD_CPPFLAGS CPPFLAGS=$OLD_CPPFLAGS
else else
Echo Unable to find suitable MPI Compiler. Try setting MPICC. echo Unable to find suitable MPI Compiler. Try setting MPICC.
have_C_mpi='no' have_C_mpi='no'
fi fi

View File

@ -1133,6 +1133,7 @@ enum qse_awk_errnum_t
/* common errors */ /* common errors */
QSE_AWK_ENOMEM, /**< insufficient memory */ QSE_AWK_ENOMEM, /**< insufficient memory */
QSE_AWK_EINVAL, /**< invalid parameter or data */ QSE_AWK_EINVAL, /**< invalid parameter or data */
QSE_AWK_EACCES, /**< access denied */
QSE_AWK_ENOSUP, /**< not supported */ QSE_AWK_ENOSUP, /**< not supported */
QSE_AWK_ENOPER, /**< operation not allowed */ QSE_AWK_ENOPER, /**< operation not allowed */
QSE_AWK_ENOENT, /**< '${0}' not found */ QSE_AWK_ENOENT, /**< '${0}' not found */

View File

@ -45,7 +45,8 @@ enum qse_dir_errnum_t
QSE_DIR_EACCES, /**< access denied */ QSE_DIR_EACCES, /**< access denied */
QSE_DIR_ENOENT, /**< no such file */ QSE_DIR_ENOENT, /**< no such file */
QSE_DIR_EEXIST, /**< already exist */ QSE_DIR_EEXIST, /**< already exist */
QSE_DIR_EINTR /**< interrupted */ QSE_DIR_EINTR, /**< interrupted */
QSE_DIR_EPIPE /**< broken pipe */
}; };
typedef enum qse_dir_errnum_t qse_dir_errnum_t; typedef enum qse_dir_errnum_t qse_dir_errnum_t;
@ -76,7 +77,8 @@ QSE_EXPORT qse_dir_t* qse_dir_open (
qse_mmgr_t* mmgr, qse_mmgr_t* mmgr,
qse_size_t xtnsize, qse_size_t xtnsize,
const qse_char_t* path, const qse_char_t* path,
int flags int flags,
qse_dir_errnum_t* errnum /** error number */
); );
QSE_EXPORT void qse_dir_close ( QSE_EXPORT void qse_dir_close (
@ -91,6 +93,10 @@ QSE_EXPORT void* qse_dir_getxtn (
qse_dir_t* dir qse_dir_t* dir
); );
QSE_EXPORT qse_dir_errnum_t qse_dir_geterrnum (
qse_dir_t* dir
);
QSE_EXPORT int qse_dir_reset ( QSE_EXPORT int qse_dir_reset (
qse_dir_t* dir, qse_dir_t* dir,
const qse_char_t* path const qse_char_t* path

View File

@ -83,7 +83,8 @@ enum qse_fio_errnum_t
QSE_FIO_EACCES, /**< access denied */ QSE_FIO_EACCES, /**< access denied */
QSE_FIO_ENOENT, /**< no such file */ QSE_FIO_ENOENT, /**< no such file */
QSE_FIO_EEXIST, /**< already exist */ QSE_FIO_EEXIST, /**< already exist */
QSE_FIO_EINTR /**< interrupted */ QSE_FIO_EINTR, /**< interrupted */
QSE_FIO_EPIPE, /**< broken pipe */
}; };
typedef enum qse_fio_errnum_t qse_fio_errnum_t; typedef enum qse_fio_errnum_t qse_fio_errnum_t;

View File

@ -123,9 +123,9 @@ enum qse_pio_errnum_t
QSE_PIO_ENOENT, /**< no such file */ QSE_PIO_ENOENT, /**< no such file */
QSE_PIO_EEXIST, /**< already exist */ QSE_PIO_EEXIST, /**< already exist */
QSE_PIO_EINTR, /**< interrupted */ QSE_PIO_EINTR, /**< interrupted */
QSE_PIO_EPIPE, /**< broken pipe */
QSE_PIO_ENOHND, /**< no handle available */ QSE_PIO_ENOHND, /**< no handle available */
QSE_PIO_ECHILD, /**< the child is not valid */ QSE_PIO_ECHILD, /**< the child is not valid */
QSE_PIO_EPIPE, /**< broken pipe */
QSE_PIO_EILSEQ, /**< illegal sequence */ QSE_PIO_EILSEQ, /**< illegal sequence */
QSE_PIO_EICSEQ, /**< incomplete sequence */ QSE_PIO_EICSEQ, /**< incomplete sequence */
QSE_PIO_EILCHR /**< illegal character */ QSE_PIO_EILCHR /**< illegal character */

View File

@ -32,6 +32,7 @@ const qse_char_t* qse_awk_dflerrstr (const qse_awk_t* awk, qse_awk_errnum_t errn
QSE_T("insufficient memory"), QSE_T("insufficient memory"),
QSE_T("invalid parameter or data"), QSE_T("invalid parameter or data"),
QSE_T("access denied"),
QSE_T("not supported"), QSE_T("not supported"),
QSE_T("operation not allowed"), QSE_T("operation not allowed"),
QSE_T("'${0}' not found"), QSE_T("'${0}' not found"),

View File

@ -718,6 +718,10 @@ static int fnc_split (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
t1 = qse_awk_rtx_makemapval (run); t1 = qse_awk_rtx_makemapval (run);
if (t1 == QSE_NULL) goto oops; if (t1 == QSE_NULL) goto oops;
/* use the following 3 lines intead of
* qse_awk_rtx_setrefval (run, a1, t1);
* just for less overhead.
*/
qse_awk_rtx_refdownval (run, *a1_ref); qse_awk_rtx_refdownval (run, *a1_ref);
*a1_ref = t1; *a1_ref = t1;
qse_awk_rtx_refupval (run, *a1_ref); qse_awk_rtx_refupval (run, *a1_ref);

View File

@ -2155,7 +2155,6 @@ static qse_awk_nde_t* parse_while (qse_awk_t* awk, const qse_awk_loc_t* xloc)
oops: oops:
if (body) qse_awk_clrpt (awk, body); if (body) qse_awk_clrpt (awk, body);
if (test) qse_awk_clrpt (awk, test); if (test) qse_awk_clrpt (awk, test);
QSE_ASSERT (nde == QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }

View File

@ -40,6 +40,7 @@
struct qse_dir_t struct qse_dir_t
{ {
qse_mmgr_t* mmgr; qse_mmgr_t* mmgr;
qse_dir_errnum_t errnum;
int flags; int flags;
qse_str_t tbuf; qse_str_t tbuf;
@ -72,7 +73,12 @@ void qse_dir_fini (qse_dir_t* dir);
static int reset_to_path (qse_dir_t* dir, const qse_char_t* path); static int reset_to_path (qse_dir_t* dir, const qse_char_t* path);
qse_dir_t* qse_dir_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* path, int flags) #include "syserr.h"
IMPLEMENT_SYSERR_TO_ERRNUM (dir, DIR)
qse_dir_t* qse_dir_open (
qse_mmgr_t* mmgr, qse_size_t xtnsize,
const qse_char_t* path, int flags, qse_dir_errnum_t* errnum)
{ {
qse_dir_t* dir; qse_dir_t* dir;
@ -81,11 +87,16 @@ qse_dir_t* qse_dir_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t*
{ {
if (qse_dir_init (dir, mmgr, path, flags) <= -1) if (qse_dir_init (dir, mmgr, path, flags) <= -1)
{ {
if (errnum) *errnum = qse_dir_geterrnum (dir);
QSE_MMGR_FREE (mmgr, dir); QSE_MMGR_FREE (mmgr, dir);
dir = QSE_NULL; dir = QSE_NULL;
} }
else QSE_MEMSET (dir + 1, 0, xtnsize); else QSE_MEMSET (dir + 1, 0, xtnsize);
} }
else
{
if (errnum) *errnum = QSE_DIR_ENOMEM;
}
return dir; return dir;
} }
@ -106,6 +117,11 @@ void* qse_dir_getxtn (qse_dir_t* dir)
return QSE_XTN (dir); return QSE_XTN (dir);
} }
qse_dir_errnum_t qse_dir_geterrnum (qse_dir_t* dir)
{
return dir->errnum;
}
int qse_dir_init (qse_dir_t* dir, qse_mmgr_t* mmgr, const qse_char_t* path, int flags) int qse_dir_init (qse_dir_t* dir, qse_mmgr_t* mmgr, const qse_char_t* path, int flags)
{ {
int n; int n;
@ -177,8 +193,17 @@ static qse_mchar_t* wcs_to_mbuf (qse_dir_t* dir, const qse_wchar_t* wcs, qse_mbs
{ {
qse_size_t ml, wl; qse_size_t ml, wl;
if (qse_wcstombs (wcs, &wl, QSE_NULL, &ml) <= -1 || if (qse_wcstombs (wcs, &wl, QSE_NULL, &ml) <= -1)
qse_mbs_setlen (mbs, ml) == (qse_size_t)-1) return QSE_NULL; {
dir->errnum = QSE_DIR_EINVAL;
return QSE_NULL;
}
if (qse_mbs_setlen (mbs, ml) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
qse_wcstombs (wcs, &wl, QSE_MBS_PTR(mbs), &ml); qse_wcstombs (wcs, &wl, QSE_MBS_PTR(mbs), &ml);
return QSE_MBS_PTR(mbs); return QSE_MBS_PTR(mbs);
@ -188,8 +213,16 @@ static qse_wchar_t* mbs_to_wbuf (qse_dir_t* dir, const qse_mchar_t* mbs, qse_wcs
{ {
qse_size_t ml, wl; qse_size_t ml, wl;
if (qse_mbstowcs (mbs, &ml, QSE_NULL, &wl) <= -1 || if (qse_mbstowcs (mbs, &ml, QSE_NULL, &wl) <= -1)
qse_wcs_setlen (wcs, wl) == (qse_size_t)-1) return QSE_NULL; {
dir->errnum = QSE_DIR_EINVAL;
return QSE_NULL;
}
if (qse_wcs_setlen (wcs, wl) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
qse_mbstowcs (mbs, &ml, QSE_WCS_PTR(wcs), &wl); qse_mbstowcs (mbs, &ml, QSE_WCS_PTR(wcs), &wl);
return QSE_WCS_PTR(wcs); return QSE_WCS_PTR(wcs);
@ -199,7 +232,11 @@ static qse_mchar_t* make_mbsdos_path (qse_dir_t* dir, const qse_mchar_t* mpath)
{ {
if (mpath[0] == QSE_MT('\0')) if (mpath[0] == QSE_MT('\0'))
{ {
if (qse_mbs_cpy (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1) return QSE_NULL; if (qse_mbs_cpy (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
} }
else else
{ {
@ -210,6 +247,7 @@ static qse_mchar_t* make_mbsdos_path (qse_dir_t* dir, const qse_mchar_t* mpath)
qse_mbs_ccat (&dir->mbuf, QSE_MT('\\')) == (qse_size_t)-1) || qse_mbs_ccat (&dir->mbuf, QSE_MT('\\')) == (qse_size_t)-1) ||
qse_mbs_cat (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1) qse_mbs_cat (&dir->mbuf, QSE_MT("*.*")) == (qse_size_t)-1)
{ {
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL; return QSE_NULL;
} }
} }
@ -221,7 +259,11 @@ static qse_char_t* make_dos_path (qse_dir_t* dir, const qse_char_t* path)
{ {
if (path[0] == QSE_T('\0')) if (path[0] == QSE_T('\0'))
{ {
if (qse_str_cpy (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1) return QSE_NULL; if (qse_str_cpy (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL;
}
} }
else else
{ {
@ -232,6 +274,7 @@ static qse_char_t* make_dos_path (qse_dir_t* dir, const qse_char_t* path)
qse_str_ccat (&dir->tbuf, QSE_T('\\')) == (qse_size_t)-1) || qse_str_ccat (&dir->tbuf, QSE_T('\\')) == (qse_size_t)-1) ||
qse_str_cat (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1) qse_str_cat (&dir->tbuf, QSE_T("*.*")) == (qse_size_t)-1)
{ {
dir->errnum = QSE_DIR_ENOMEM;
return QSE_NULL; return QSE_NULL;
} }
} }
@ -293,7 +336,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
if (tptr == QSE_NULL) return -1; if (tptr == QSE_NULL) return -1;
dir->h = FindFirstFile (tptr, &dir->wfd); dir->h = FindFirstFile (tptr, &dir->wfd);
if (dir->h == INVALID_HANDLE_VALUE) return -1; if (dir->h == INVALID_HANDLE_VALUE)
{
dir->errnum = syserr_to_errnum (GetLastError());
return -1;
}
return 0; return 0;
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
@ -337,7 +384,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
#endif #endif
); );
if (rc != NO_ERROR) return -1; if (rc != NO_ERROR)
{
dir->errnum = syserr_to_errnum (rc);
return -1;
}
dir->opened = 1; dir->opened = 1;
return 0; return 0;
@ -368,7 +419,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
if (mptr == QSE_NULL) return -1; if (mptr == QSE_NULL) return -1;
rc = _dos_findfirst (mptr, _A_NORMAL | _A_SUBDIR, &dir->f); rc = _dos_findfirst (mptr, _A_NORMAL | _A_SUBDIR, &dir->f);
if (rc != 0) return -1; if (rc != 0)
{
dir->errnum = syserr_to_errnum (errno);
return -1;
}
dir->opened = 1; dir->opened = 1;
return 0; return 0;
@ -402,7 +457,11 @@ static int reset_to_path (qse_dir_t* dir, const qse_char_t* path)
} }
} }
#endif #endif
if (dp == QSE_NULL) return -1; if (dp == QSE_NULL)
{
dir->errnum = syserr_to_errnum (errno);
return -1;
}
dir->dp = dp; dir->dp = dp;
return 0; return 0;
@ -423,7 +482,11 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
if (dir->done) return (dir->done > 0)? 0: -1; if (dir->done) return (dir->done > 0)? 0: -1;
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1) return -1; if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf); *name = QSE_STR_PTR(&dir->tbuf);
#else #else
if (dir->flags & QSE_DIR_MBSPATH) if (dir->flags & QSE_DIR_MBSPATH)
@ -433,13 +496,25 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
} }
else else
{ {
if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1) return -1; if (qse_str_cpy (&dir->tbuf, dir->wfd.cFileName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf); *name = QSE_STR_PTR(&dir->tbuf);
} }
#endif #endif
if (FindNextFile (dir->h, &dir->wfd) == FALSE) if (FindNextFile (dir->h, &dir->wfd) == FALSE)
dir->done = (GetLastError() == ERROR_NO_MORE_FILES)? 1: -1; {
DWORD x = GetLastError();
if (x == ERROR_NO_MORE_FILES) dir->done = 1;
else
{
dir->errnum = syserr_to_errnum (x);
dir->done = -1;
}
}
return 1; return 1;
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
@ -452,12 +527,20 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
if (dir->count <= 0) return 0; if (dir->count <= 0) return 0;
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, dir->ffb.achName) == (qse_size_t)-1) return -1; if (qse_str_cpy (&dir->tbuf, dir->ffb.achName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf); *name = QSE_STR_PTR(&dir->tbuf);
#else #else
if (dir->flags & QSE_DIR_MBSPATH) if (dir->flags & QSE_DIR_MBSPATH)
{ {
if (qse_mbs_cpy (&dir->mbuf, dir->ffb.achName) == (qse_size_t)-1) return -1; if (qse_mbs_cpy (&dir->mbuf, dir->ffb.achName) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_MBS_PTR(&dir->mbuf); *name = QSE_MBS_PTR(&dir->mbuf);
} }
else else
@ -469,7 +552,11 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
rc = DosFindNext (dir->h, &dir->ffb, QSE_SIZEOF(dir->ffb), &dir->count); rc = DosFindNext (dir->h, &dir->ffb, QSE_SIZEOF(dir->ffb), &dir->count);
if (rc == ERROR_NO_MORE_FILES) dir->count = 0; if (rc == ERROR_NO_MORE_FILES) dir->count = 0;
else if (rc != NO_ERROR) return -1; else if (rc != NO_ERROR)
{
dir->errnum = syserr_to_errnum (rc);
return -1;
}
return 1; return 1;
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
@ -477,17 +564,24 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
#elif defined(__DOS__) #elif defined(__DOS__)
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
unsigned int rc;
if (dir->done) return (dir->done > 0)? 0: -1; if (dir->done) return (dir->done > 0)? 0: -1;
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, dir->f.name) == (qse_size_t)-1) return -1; if (qse_str_cpy (&dir->tbuf, dir->f.name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf); *name = QSE_STR_PTR(&dir->tbuf);
#else #else
if (dir->flags & QSE_DIR_MBSPATH) if (dir->flags & QSE_DIR_MBSPATH)
{ {
if (qse_mbs_cpy (&dir->mbuf, dir->f.name) == (qse_size_t)-1) return -1; if (qse_mbs_cpy (&dir->mbuf, dir->f.name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_MBS_PTR(&dir->mbuf); *name = QSE_MBS_PTR(&dir->mbuf);
} }
else else
@ -497,8 +591,15 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
} }
#endif #endif
rc = _dos_findnext (&dir->f); if (_dos_findnext (&dir->f) != 0)
if (rc != 0) dir->done = (errno == ENOENT)? 1: -1; {
if (errno == ENOENT) dir->done = 1;
else
{
dir->errnum = syserr_to_errnum (errno);
dir->done = -1;
}
}
return 1; return 1;
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
@ -510,15 +611,29 @@ static int read_dir_to_tbuf (qse_dir_t* dir, void** name)
errno = 0; errno = 0;
de = QSE_READDIR (dir->dp); de = QSE_READDIR (dir->dp);
if (de == NULL) return (errno == 0)? 0: -1; if (de == NULL)
{
if (errno == 0) return 0;
dir->errnum = syserr_to_errnum (errno);
return -1;
}
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cpy (&dir->tbuf, de->d_name) == (qse_size_t)-1) return -1; if (qse_str_cpy (&dir->tbuf, de->d_name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_STR_PTR(&dir->tbuf); *name = QSE_STR_PTR(&dir->tbuf);
#else #else
if (dir->flags & QSE_DIR_MBSPATH) if (dir->flags & QSE_DIR_MBSPATH)
{ {
if (qse_mbs_cpy (&dir->mbuf, de->d_name) == (qse_size_t)-1) return -1; if (qse_mbs_cpy (&dir->mbuf, de->d_name) == (qse_size_t)-1)
{
dir->errnum = QSE_DIR_ENOMEM;
return -1;
}
*name = QSE_MBS_PTR(&dir->mbuf); *name = QSE_MBS_PTR(&dir->mbuf);
} }
else else

View File

@ -55,130 +55,8 @@ enum
STATUS_NOCLOSE = (1 << 1) STATUS_NOCLOSE = (1 << 1)
}; };
#if defined(_WIN32) #include "syserr.h"
static qse_fio_errnum_t syserr_to_errnum (DWORD e) IMPLEMENT_SYSERR_TO_ERRNUM (fio, FIO)
{
switch (e)
{
case ERROR_NOT_ENOUGH_MEMORY:
case ERROR_OUTOFMEMORY:
return QSE_FIO_ENOMEM;
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_NAME:
return QSE_FIO_EINVAL;
case ERROR_ACCESS_DENIED:
case ERROR_SHARING_VIOLATION:
return QSE_FIO_EACCES;
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
return QSE_FIO_ENOENT;
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
return QSE_FIO_EEXIST;
default:
return QSE_FIO_ESYSERR;
}
}
#elif defined(__OS2__)
static qse_fio_errnum_t syserr_to_errnum (APIRET e)
{
switch (e)
{
case ERROR_NOT_ENOUGH_MEMORY:
return QSE_FIO_ENOMEM;
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_NAME:
return QSE_FIO_EINVAL;
case ERROR_ACCESS_DENIED:
case ERROR_SHARING_VIOLATION:
return QSE_FIO_EACCES;
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
return QSE_FIO_ENOENT;
case ERROR_ALREADY_EXISTS:
return QSE_FIO_EEXIST;
default:
return QSE_FIO_ESYSERR;
}
}
#elif defined(__DOS__)
static qse_fio_errnum_t syserr_to_errnum (int e)
{
switch (e)
{
case ENOMEM:
return QSE_FIO_ENOMEM;
case EINVAL:
return QSE_FIO_EINVAL;
case EACCES:
return QSE_FIO_EACCES;
case ENOENT:
return QSE_FIO_ENOENT;
case EEXIST:
return QSE_FIO_EEXIST;
default:
return QSE_FIO_ESYSERR;
}
}
#elif defined(vms) || defined(__vms)
static qse_fio_errnum_t syserr_to_errnum (unsigned long e)
{
switch (e)
{
case RMS$_NORMAL:
return QSE_FIO_ENOERR;
/* TODO: add more */
default:
return QSE_FIO_ESYSERR;
}
}
#else
static qse_fio_errnum_t syserr_to_errnum (int e)
{
switch (e)
{
case ENOMEM:
return QSE_FIO_ENOMEM;
case EINVAL:
return QSE_FIO_EINVAL;
case ENOENT:
return QSE_FIO_ENOENT;
case EACCES:
return QSE_FIO_EACCES;
case EEXIST:
return QSE_FIO_EEXIST;
case EINTR:
return QSE_FIO_EINTR;
default:
return QSE_FIO_ESYSERR;
}
}
#endif
#if defined(__OS2__) #if defined(__OS2__)

View File

@ -408,7 +408,7 @@ entry:
if (seg->wild) if (seg->wild)
{ {
dp = qse_dir_open (g->mmgr, 0, QSE_STR_PTR(&g->path), 0); dp = qse_dir_open (g->mmgr, 0, QSE_STR_PTR(&g->path), 0, QSE_NULL);
if (dp) if (dp)
{ {
tmp = QSE_STR_LEN(&g->path); tmp = QSE_STR_LEN(&g->path);

View File

@ -45,125 +45,8 @@ static qse_ssize_t pio_input (
static qse_ssize_t pio_output ( static qse_ssize_t pio_output (
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size); qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
#if defined(_WIN32) #include "syserr.h"
static qse_pio_errnum_t syserr_to_errnum (DWORD e) IMPLEMENT_SYSERR_TO_ERRNUM (pio, PIO)
{
switch (e)
{
case ERROR_NOT_ENOUGH_MEMORY:
case ERROR_OUTOFMEMORY:
return QSE_PIO_ENOMEM;
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_NAME:
return QSE_PIO_EINVAL;
case ERROR_ACCESS_DENIED:
case ERROR_SHARING_VIOLATION:
return QSE_PIO_EACCES;
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
return QSE_PIO_ENOENT;
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
return QSE_PIO_EEXIST;
case ERROR_BROKEN_PIPE:
return QSE_PIO_EPIPE;
default:
return QSE_PIO_ESYSERR;
}
}
#elif defined(__OS2__)
static qse_pio_errnum_t syserr_to_errnum (APIRET e)
{
switch (e)
{
case ERROR_NOT_ENOUGH_MEMORY:
return QSE_PIO_ENOMEM;
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_NAME:
return QSE_PIO_EINVAL;
case ERROR_ACCESS_DENIED:
case ERROR_SHARING_VIOLATION:
return QSE_PIO_EACCES;
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
return QSE_PIO_ENOENT;
case ERROR_ALREADY_EXISTS:
return QSE_PIO_EEXIST;
case ERROR_BROKEN_PIPE:
return QSE_PIO_EPIPE;
default:
return QSE_PIO_ESYSERR;
}
}
#elif defined(__DOS__)
static qse_pio_errnum_t syserr_to_errnum (int e)
{
switch (e)
{
case ENOMEM:
return QSE_PIO_ENOMEM;
case EINVAL:
return QSE_PIO_EINVAL;
case EACCES:
return QSE_PIO_EACCES;
case ENOENT:
return QSE_PIO_ENOENT;
case EEXIST:
return QSE_PIO_EEXIST;
default:
return QSE_PIO_ESYSERR;
}
}
#else
static qse_pio_errnum_t syserr_to_errnum (int e)
{
switch (e)
{
case ENOMEM:
return QSE_PIO_ENOMEM;
case EINVAL:
return QSE_PIO_EINVAL;
case EACCES:
return QSE_PIO_EACCES;
case ENOENT:
return QSE_PIO_ENOENT;
case EEXIST:
return QSE_PIO_EEXIST;
case EINTR:
return QSE_PIO_EINTR;
case EPIPE:
return QSE_PIO_EPIPE;
default:
return QSE_PIO_ESYSERR;
}
}
#endif
static qse_pio_errnum_t tio_errnum_to_pio_errnum (qse_tio_t* tio) static qse_pio_errnum_t tio_errnum_to_pio_errnum (qse_tio_t* tio)
{ {

139
qse/lib/cmn/syserr.h Normal file
View File

@ -0,0 +1,139 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* this file is intended for internal use only.
* you can include this file and use IMPLEMENT_SYSERR_TO_ERRNUM.
*
* #include "syserr.h"
* IMPLEMENT_SYSERR_TO_ERRNUM (pio, PIO)
*
* header files defining system error codes must be included
* before this file.
*/
#define __SYSERRTYPE__(obj) qse_ ## obj ## _errnum_t
#define __SYSERRNUM__(obj,num) (QSE_ ## obj ## _ ## num)
#if defined(_WIN32)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (DWORD e) \
{ \
switch (e) \
{ \
case ERROR_NOT_ENOUGH_MEMORY: \
case ERROR_OUTOFMEMORY: \
return __SYSERRNUM__ (obj2, ENOMEM); \
case ERROR_INVALID_PARAMETER: \
case ERROR_INVALID_HANDLE: \
case ERROR_INVALID_NAME: \
return __SYSERRNUM__ (obj2, EINVAL); \
case ERROR_ACCESS_DENIED: \
case ERROR_SHARING_VIOLATION: \
return __SYSERRNUM__ (obj2, EACCES); \
case ERROR_FILE_NOT_FOUND: \
case ERROR_PATH_NOT_FOUND: \
return __SYSERRNUM__ (obj2, ENOENT); \
case ERROR_ALREADY_EXISTS: \
case ERROR_FILE_EXISTS: \
return __SYSERRNUM__ (obj2, EEXIST); \
case ERROR_BROKEN_PIPE: \
return __SYSERRNUM__ (obj2, EPIPE); \
default: \
return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
#elif defined(__OS2__)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (APIRET e) \
{ \
switch (e) \
{ \
case ERROR_NOT_ENOUGH_MEMORY: \
return __SYSERRNUM__ (obj2, ENOMEM); \
case ERROR_INVALID_PARAMETER: \
case ERROR_INVALID_HANDLE: \
case ERROR_INVALID_NAME: \
return __SYSERRNUM__ (obj2, EINVAL); \
case ERROR_ACCESS_DENIED: \
case ERROR_SHARING_VIOLATION: \
return __SYSERRNUM__ (obj2, EACCES); \
case ERROR_FILE_NOT_FOUND: \
case ERROR_PATH_NOT_FOUND: \
return __SYSERRNUM__ (obj2, ENOENT); \
case ERROR_ALREADY_EXISTS: \
return __SYSERRNUM__ (obj2, EEXIST); \
case ERROR_BROKEN_PIPE: \
return __SYSERRNUM__ (obj2, EPIPE); \
default: \
return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
#elif defined(__DOS__)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (syserrobj, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (syserrobj, EINVAL); \
case EACCES: return __SYSERRNUM__ (syserrobj, EACCES); \
case ENOENT: return __SYSERRNUM__ (syserrobj, ENOENT); \
case EEXIST: return __SYSERRNUM__ (syserrobj, EEXIST); \
default: return __SYSERRNUM__ (syserrobj, ESYSERR); \
} \
}
#elif defined(vms) || defined(__vms)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (unsigned long e) \
{ \
switch (e) \
{ \
case RMS$_NORMAL: return __SYSERRNUM__ (obj2, ENOERR); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
#else
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
#endif

View File

@ -197,7 +197,7 @@ AC_DEFUN([LX_QUERY_MPI_COMPILER],
LIBS=$OLD_LIBS LIBS=$OLD_LIBS
CPPFLAGS=$OLD_CPPFLAGS CPPFLAGS=$OLD_CPPFLAGS
else else
Echo Unable to find suitable MPI Compiler. Try setting $1. echo Unable to find suitable MPI Compiler. Try setting $1.
have_$3_mpi='no' have_$3_mpi='no'
fi fi
]) ])

View File

@ -30,8 +30,11 @@ typedef struct dir_node_t dir_node_t;
enum enum
{ {
DIR_ENOERR, DIR_ENOERR,
DIR_EOTHER,
DIR_ESYSERR,
DIR_ENOMEM, DIR_ENOMEM,
DIR_EINVAL, DIR_EINVAL,
DIR_EACCES,
DIR_ENOENT DIR_ENOENT
}; };
@ -60,10 +63,49 @@ struct dir_list_t
int errnum; int errnum;
}; };
static int dir_err_to_errnum (qse_dir_errnum_t num)
{
switch (num)
{
case QSE_DIR_ESYSERR:
return DIR_ESYSERR;
case QSE_DIR_ENOMEM:
return DIR_ENOMEM;
case QSE_DIR_EINVAL:
return DIR_EINVAL;
case QSE_DIR_EACCES:
return DIR_EACCES;
case QSE_DIR_ENOENT:
return DIR_ENOENT;
default:
return DIR_EOTHER;
}
}
static int awk_err_to_errnum (qse_awk_errnum_t num)
{
switch (num)
{
case QSE_AWK_ESYSERR:
return DIR_ESYSERR;
case QSE_AWK_ENOMEM:
return DIR_ENOMEM;
case QSE_AWK_EINVAL:
return DIR_EINVAL;
case QSE_AWK_EACCES:
return DIR_EACCES;
case QSE_AWK_ENOENT:
return DIR_ENOENT;
default:
return DIR_EOTHER;
}
}
static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse_char_t* path) static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse_char_t* path)
{ {
/* create a new context node and append it to the list tail */ /* create a new context node and append it to the list tail */
dir_node_t* node; dir_node_t* node;
qse_dir_errnum_t oe;
node = QSE_NULL; node = QSE_NULL;
@ -71,11 +113,19 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse
else else
{ {
node = qse_awk_rtx_callocmem (rtx, QSE_SIZEOF(*node)); node = qse_awk_rtx_callocmem (rtx, QSE_SIZEOF(*node));
if (!node) goto oops; if (!node)
{
list->errnum = DIR_ENOMEM;
goto oops;
}
} }
node->ctx = qse_dir_open (qse_awk_rtx_getmmgr(rtx), 0, path, 0); node->ctx = qse_dir_open (qse_awk_rtx_getmmgr(rtx), 0, path, 0, &oe);
if (!node->ctx) goto oops; if (!node->ctx)
{
list->errnum = dir_err_to_errnum (oe);
goto oops;
}
if (node == list->free) list->free = node->next; if (node == list->free) list->free = node->next;
else else
@ -90,7 +140,11 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse
tmp = (dir_node_t**) qse_awk_rtx_reallocmem ( tmp = (dir_node_t**) qse_awk_rtx_reallocmem (
rtx, list->map.tab, QSE_SIZEOF(*tmp) * newcapa); rtx, list->map.tab, QSE_SIZEOF(*tmp) * newcapa);
if (!tmp) goto oops; if (!tmp)
{
list->errnum = DIR_ENOMEM;
goto oops;
}
QSE_MEMSET (&tmp[list->map.capa], 0, QSE_MEMSET (&tmp[list->map.capa], 0,
QSE_SIZEOF(*tmp) * (newcapa - list->map.capa)); QSE_SIZEOF(*tmp) * (newcapa - list->map.capa));
@ -116,7 +170,6 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse
oops: oops:
if (node) qse_awk_rtx_freemem (rtx, node); if (node) qse_awk_rtx_freemem (rtx, node);
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -177,53 +230,68 @@ static void free_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, dir_node_t* nod
static int close_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id) static int close_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id)
{ {
int x = DIR_EINVAL;
if (id >= 0 && id < list->map.high && list->map.tab[id]) if (id >= 0 && id < list->map.high && list->map.tab[id])
{ {
free_dir_node (rtx, list, list->map.tab[id]); free_dir_node (rtx, list, list->map.tab[id]);
x = DIR_ENOERR; return 0;
}
else
{
list->errnum = DIR_EINVAL;
return -1;
} }
return -x;
} }
static int reset_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, const qse_char_t* path) static int reset_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, const qse_char_t* path)
{ {
int x = DIR_EINVAL;
if (id >= 0 && id < list->map.high && list->map.tab[id]) if (id >= 0 && id < list->map.high && list->map.tab[id])
{ {
if (qse_dir_reset (list->map.tab[id]->ctx, path) >= 0) x = DIR_ENOERR; if (qse_dir_reset (list->map.tab[id]->ctx, path) <= -1)
{
list->errnum = dir_err_to_errnum (qse_dir_geterrnum (list->map.tab[id]->ctx));
return -1;
}
return 0;
}
else
{
list->errnum = DIR_EINVAL;
return -1;
} }
return -x;
} }
static int read_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, qse_awk_val_t** retv) static int read_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_long_t id, qse_awk_val_ref_t* ref)
{ {
int x = DIR_EINVAL;
if (id >= 0 && id < list->map.high && list->map.tab[id]) if (id >= 0 && id < list->map.high && list->map.tab[id])
{ {
int y; int y;
qse_dir_ent_t ent; qse_dir_ent_t ent;
y = qse_dir_read (list->map.tab[id]->ctx, &ent); qse_awk_val_t* tmp;
if (y == 0) x = DIR_ENOENT;
else if (y >= 1)
{
qse_awk_val_t* tmp;
tmp = qse_awk_rtx_makestrvalwithstr (rtx, ent.name);
if (tmp)
{
*retv = tmp;
x = DIR_ENOERR;
}
else x = DIR_ENOMEM;
}
}
return -x; y = qse_dir_read (list->map.tab[id]->ctx, &ent);
if (y <= -1)
{
list->errnum = dir_err_to_errnum (qse_dir_geterrnum (list->map.tab[id]->ctx));
return -1;
}
if (y == 0) return 0;
tmp = qse_awk_rtx_makestrvalwithstr (rtx, ent.name);
if (!tmp || qse_awk_rtx_setrefval (rtx, ref, tmp) <= -1)
{
list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
if (tmp) qse_awk_rtx_freemem (rtx, tmp);
return -1;
}
return 1;
}
else
{
list->errnum = DIR_EINVAL;
return -1;
}
} }
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
@ -253,8 +321,11 @@ static int fnc_dir_errno (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
static qse_char_t* errmsg[] = static qse_char_t* errmsg[] =
{ {
QSE_T("no error"), QSE_T("no error"),
QSE_T("out of memory"), QSE_T("other error"),
QSE_T("system error"),
QSE_T("insufficient memory"),
QSE_T("invalid data"), QSE_T("invalid data"),
QSE_T("access denied"),
QSE_T("no entry"), QSE_T("no entry"),
QSE_T("unknown error") QSE_T("unknown error")
}; };
@ -287,122 +358,107 @@ static int fnc_dir_open (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
dir_list_t* list; dir_list_t* list;
dir_node_t* node; dir_node_t* node;
qse_long_t ret; qse_long_t ret;
qse_awk_val_t* retv;
qse_char_t* path; qse_char_t* path;
list = rtx_to_list (rtx, fi); list = rtx_to_list (rtx, fi);
path = qse_awk_rtx_valtostrdup (rtx, qse_awk_rtx_getarg (rtx, 0), QSE_NULL); path = qse_awk_rtx_valtostrdup (rtx, qse_awk_rtx_getarg (rtx, 0), QSE_NULL);
if (path == QSE_NULL) if (path)
{ {
list->errnum = DIR_ENOMEM; node = new_dir_node (rtx, list, path);
ret = -DIR_ENOMEM; if (node) ret = node->id;
else ret = -1;
qse_awk_rtx_freemem (rtx, path);
} }
else else
{ {
node = new_dir_node (rtx, list, path); list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
ret = node? node->id: -DIR_ENOMEM;
qse_awk_rtx_freemem (rtx, path);
}
if (ret <= -1)
{
list->errnum = -ret;
ret = -1; ret = -1;
} }
retv = qse_awk_rtx_makeintval (rtx, ret); qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret));
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0; return 0;
} }
static int fnc_dir_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_dir_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
dir_list_t* list; dir_list_t* list;
qse_awk_val_t* retv;
qse_long_t id; qse_long_t id;
int ret; int ret;
list = rtx_to_list (rtx, fi); list = rtx_to_list (rtx, fi);
ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id); ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
if (ret <= -1) ret = -DIR_EINVAL;
else ret = close_byid (rtx, list, id);
if (ret <= -1) if (ret <= -1)
{ {
list->errnum = -ret; list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
ret = -1; ret = -1;
} }
else
{
ret = close_byid (rtx, list, id);
}
retv = qse_awk_rtx_makeintval (rtx, ret); qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret));
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0; return 0;
} }
static int fnc_dir_reset (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_dir_reset (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
dir_list_t* list; dir_list_t* list;
qse_awk_val_t* retv;
qse_long_t id; qse_long_t id;
int ret; int ret;
qse_char_t* path;
list = rtx_to_list (rtx, fi); list = rtx_to_list (rtx, fi);
ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id); ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
if (ret <= -1) ret = -DIR_EINVAL; if (ret <= -1)
{
list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
}
else else
{ {
qse_char_t* path;
path = qse_awk_rtx_valtostrdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); path = qse_awk_rtx_valtostrdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (path) if (path)
{ {
ret = reset_byid (rtx, list, id, path); ret = reset_byid (rtx, list, id, path);
qse_awk_rtx_freemem (rtx, path); qse_awk_rtx_freemem (rtx, path);
} }
else ret = -DIR_ENOMEM; else
{
list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
ret = -1;
}
} }
if (ret <= -1) /* no error check for qse_awk_rtx_makeintval() here since ret
{ * is 0 or -1. it will never fail for those numbers */
list->errnum = -ret; qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret));
ret = -1;
}
retv = qse_awk_rtx_makeintval (rtx, ret);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0; return 0;
} }
static int fnc_dir_read (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_dir_read (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
dir_list_t* list; dir_list_t* list;
qse_awk_val_t* retv;
qse_long_t id; qse_long_t id;
int ret; int ret;
list = rtx_to_list (rtx, fi); list = rtx_to_list (rtx, fi);
ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id); ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
if (ret <= -1) ret = -DIR_EINVAL;
else ret = read_byid (rtx, list, id, &retv);
if (ret <= -1) if (ret <= -1)
{ {
list->errnum = -ret; list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
} }
else else
{ {
qse_awk_rtx_setretval (rtx, retv); ret = read_byid (rtx, list, id, qse_awk_rtx_getarg (rtx, 1));
} }
/* no error check for qse_awk_rtx_makeintval() here since ret
* is 0, 1, -1. it will never fail for those numbers */
qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret));
return 0; return 0;
} }
@ -417,12 +473,12 @@ struct fnctab_t
static fnctab_t fnctab[] = static fnctab_t fnctab[] =
{ {
{ QSE_T("close"), { { 1, 1, QSE_NULL }, fnc_dir_close, 0 } }, { QSE_T("close"), { { 1, 1, QSE_NULL }, fnc_dir_close, 0 } },
{ QSE_T("errno"), { { 0, 0, QSE_NULL }, fnc_dir_errno, 0 } }, { QSE_T("errno"), { { 0, 0, QSE_NULL }, fnc_dir_errno, 0 } },
{ QSE_T("errstr"), { { 0, 1, QSE_NULL }, fnc_dir_errstr, 0 } }, { QSE_T("errstr"), { { 0, 1, QSE_NULL }, fnc_dir_errstr, 0 } },
{ QSE_T("open"), { { 1, 1, QSE_NULL }, fnc_dir_open, 0 } }, { QSE_T("open"), { { 1, 1, QSE_NULL }, fnc_dir_open, 0 } },
{ QSE_T("read"), { { 1, 1, QSE_NULL }, fnc_dir_read, 0 } }, { QSE_T("read"), { { 2, 2, QSE_T("vr") }, fnc_dir_read, 0 } },
{ QSE_T("reset"), { { 2, 2, QSE_NULL }, fnc_dir_reset, 0 } }, { QSE_T("reset"), { { 2, 2, QSE_NULL }, fnc_dir_reset, 0 } },
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
@ -430,7 +486,7 @@ static fnctab_t fnctab[] =
static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym)
{ {
qse_cstr_t ea; qse_cstr_t ea;
int left, right, mid, n; int left, right, mid, n;
left = 0; right = QSE_COUNTOF(fnctab) - 1; left = 0; right = QSE_COUNTOF(fnctab) - 1;