added the qse_fs_mode_t type and the mode parameter to qse_mkdir() and related functions

This commit is contained in:
hyung-hwan 2018-01-17 07:45:31 +00:00
parent db55393050
commit d991f9c27b
8 changed files with 151 additions and 22 deletions

81
qse/configure vendored
View File

@ -21824,6 +21824,82 @@ _ACEOF
# The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
# This bug is HP SR number 8606223364.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of mode_t" >&5
$as_echo_n "checking size of mode_t... " >&6; }
if ${ac_cv_sizeof_mode_t+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (mode_t))" "ac_cv_sizeof_mode_t" "$ac_includes_default"; then :
else
if test "$ac_cv_type_mode_t" = yes; then
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "cannot compute sizeof (mode_t)
See \`config.log' for more details" "$LINENO" 5; }
else
ac_cv_sizeof_mode_t=0
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_mode_t" >&5
$as_echo "$ac_cv_sizeof_mode_t" >&6; }
cat >>confdefs.h <<_ACEOF
#define SIZEOF_MODE_T $ac_cv_sizeof_mode_t
_ACEOF
if test ${ac_cv_sizeof_mode_t} -gt 0
then
typename=`echo mode_t | sed "s/[^a-zA-Z0-9_]/_/g"`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mode_t is signed" >&5
$as_echo_n "checking whether mode_t is signed... " >&6; }
if eval \${ax_cv_decl_${typename}_signed+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
int foo [ 1 - 2 * !(((mode_t) -1) < 0) ]
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "ax_cv_decl_${typename}_signed=\"yes\""
else
eval "ax_cv_decl_${typename}_signed=\"no\""
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$ax_cv_decl_${typename}_signed
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
symbolname=`echo mode_t | sed "s/[^a-zA-Z0-9_]/_/g" | tr "a-z" "A-Z"`
if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then
$as_echo "#define QSE_MODE_T_IS_SIGNED 1" >>confdefs.h
elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then
$as_echo_n ""
fi
fi
# The cast to long int works around a bug in the HP C Compiler # The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
@ -22957,6 +23033,11 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
cat >>confdefs.h <<_ACEOF
#define QSE_SIZEOF_MODE_T ${ac_cv_sizeof_mode_t}
_ACEOF
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define QSE_SIZEOF_MBSTATE_T ${ac_cv_sizeof_mbstate_t} #define QSE_SIZEOF_MBSTATE_T ${ac_cv_sizeof_mbstate_t}

View File

@ -407,6 +407,16 @@ AC_CHECK_SIZEOF(wchar_t)
AC_CHECK_SIZEOF(off_t) AC_CHECK_SIZEOF(off_t)
AC_CHECK_SIZEOF(off64_t) AC_CHECK_SIZEOF(off64_t)
AC_CHECK_SIZEOF(mode_t)
if test ${ac_cv_sizeof_mode_t} -gt 0
then
AX_CHECK_SIGN([mode_t],
[ AC_DEFINE(QSE_MODE_T_IS_SIGNED, 1, [Define if mode_t is signed]) ],
[ AS_ECHO_N("") ],
[])
fi
AC_CHECK_SIZEOF(mbstate_t,,[#include <wchar.h>]) AC_CHECK_SIZEOF(mbstate_t,,[#include <wchar.h>])
AX_CHECK_NUMVALOF(MB_LEN_MAX,[32],[#include <limits.h>]) AX_CHECK_NUMVALOF(MB_LEN_MAX,[32],[#include <limits.h>])
AX_CHECK_NUMVALOF(PATH_MAX,[0],[#include <limits.h>]) AX_CHECK_NUMVALOF(PATH_MAX,[0],[#include <limits.h>])
@ -620,6 +630,7 @@ AC_DEFINE_UNQUOTED(QSE_SIZEOF___FLOAT128, ${ac_cv_sizeof___float128}, [sizeof(__
AC_DEFINE_UNQUOTED(QSE_SIZEOF_WCHAR_T, ${ac_cv_sizeof_wchar_t}, [sizeof(wchar_t)]) AC_DEFINE_UNQUOTED(QSE_SIZEOF_WCHAR_T, ${ac_cv_sizeof_wchar_t}, [sizeof(wchar_t)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_OFF_T, ${ac_cv_sizeof_off_t}, [sizeof(off_t)]) AC_DEFINE_UNQUOTED(QSE_SIZEOF_OFF_T, ${ac_cv_sizeof_off_t}, [sizeof(off_t)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_OFF64_T, ${ac_cv_sizeof_off64_t}, [sizeof(off64_t)]) AC_DEFINE_UNQUOTED(QSE_SIZEOF_OFF64_T, ${ac_cv_sizeof_off64_t}, [sizeof(off64_t)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_MODE_T, ${ac_cv_sizeof_mode_t}, [sizeof(mode_t)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_MBSTATE_T, ${ac_cv_sizeof_mbstate_t}, [sizeof(mbstate_t)]) AC_DEFINE_UNQUOTED(QSE_SIZEOF_MBSTATE_T, ${ac_cv_sizeof_mbstate_t}, [sizeof(mbstate_t)])
AC_DEFINE_UNQUOTED(QSE_MBLEN_MAX, ${ax_cv_numvalof_MB_LEN_MAX}, [MB_LEN_MAX]) AC_DEFINE_UNQUOTED(QSE_MBLEN_MAX, ${ax_cv_numvalof_MB_LEN_MAX}, [MB_LEN_MAX])

View File

@ -927,6 +927,9 @@
/* MB_LEN_MAX */ /* MB_LEN_MAX */
#undef QSE_MBLEN_MAX #undef QSE_MBLEN_MAX
/* Define if mode_t is signed */
#undef QSE_MODE_T_IS_SIGNED
/* Author */ /* Author */
#undef QSE_PACKAGE_AUTHOR #undef QSE_PACKAGE_AUTHOR
@ -981,6 +984,9 @@
/* sizeof(mbstate_t) */ /* sizeof(mbstate_t) */
#undef QSE_SIZEOF_MBSTATE_T #undef QSE_SIZEOF_MBSTATE_T
/* sizeof(mode_t) */
#undef QSE_SIZEOF_MODE_T
/* sizeof(off64_t) */ /* sizeof(off64_t) */
#undef QSE_SIZEOF_OFF64_T #undef QSE_SIZEOF_OFF64_T
@ -1080,6 +1086,9 @@
/* The size of `mbstate_t', as computed by sizeof. */ /* The size of `mbstate_t', as computed by sizeof. */
#undef SIZEOF_MBSTATE_T #undef SIZEOF_MBSTATE_T
/* The size of `mode_t', as computed by sizeof. */
#undef SIZEOF_MODE_T
/* The size of `off64_t', as computed by sizeof. */ /* The size of `off64_t', as computed by sizeof. */
#undef SIZEOF_OFF64_T #undef SIZEOF_OFF64_T

View File

@ -36,7 +36,6 @@
#include <qse/macros.h> #include <qse/macros.h>
#include <qse/cmn/time.h> #include <qse/cmn/time.h>
#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) #if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR)
typedef qse_wchar_t qse_fs_char_t; typedef qse_wchar_t qse_fs_char_t;
# define QSE_FS_CHAR_IS_WCHAR # define QSE_FS_CHAR_IS_WCHAR
@ -47,6 +46,34 @@
# define QSE_SIZEOF_FS_CHAR_T QSE_SIZEOF_MCHAR_T # define QSE_SIZEOF_FS_CHAR_T QSE_SIZEOF_MCHAR_T
#endif #endif
#if (QSE_SIZEOF_MODE_T == QSE_SIZEOF_LONG)
# if defined(QSE_MODE_T_IS_SIGNED)
typedef long int qse_fs_mode_t;
# else
typedef unsigned long int qse_fs_mode_t;
# endif
#elif (QSE_SIZEOF_MODE_T == QSE_SIZEOF_INT)
# if defined(QSE_MODE_T_IS_SIGNED)
typedef int qse_fs_mode_t;
# else
typedef unsigned int qse_fs_mode_t;
# endif
#elif (QSE_SIZEOF_MODE_T == QSE_SIZEOF_SHORT)
# if defined(QSE_MODE_T_IS_SIGNED)
typedef short int qse_fs_mode_t;
# else
typedef unsigned short int qse_fs_mode_t;
# endif
#elif (QSE_SIZEOF_MODE_T == QSE_SIZEOF_CHAR)
# if defined(QSE_MODE_T_IS_SIGNED)
typedef signed char qse_fs_mode_t;
# else
typedef unsigned char qse_fs_mode_t;
# endif
#else
typedef unsigned int qse_fs_mode_t;
#endif
enum qse_fs_errnum_t enum qse_fs_errnum_t
{ {
QSE_FS_ENOERR = 0, QSE_FS_ENOERR = 0,
@ -441,12 +468,14 @@ QSE_EXPORT int qse_fs_cpfilewcs (
QSE_EXPORT int qse_fs_mkdirmbs ( QSE_EXPORT int qse_fs_mkdirmbs (
qse_fs_t* fs, qse_fs_t* fs,
const qse_mchar_t* path, const qse_mchar_t* path,
qse_fs_mode_t mode,
int flags int flags
); );
QSE_EXPORT int qse_fs_mkdirwcs ( QSE_EXPORT int qse_fs_mkdirwcs (
qse_fs_t* fs, qse_fs_t* fs,
const qse_wchar_t* path, const qse_wchar_t* path,
qse_fs_mode_t mode,
int flags int flags
); );
@ -475,11 +504,11 @@ QSE_EXPORT int qse_fs_rmdirwcs (
); );
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
# define qse_fs_mkdir(fs,path,flags) qse_fs_mkdirmbs(fs,path,flags) # define qse_fs_mkdir(fs,path,mode,flags) qse_fs_mkdirmbs(fs,path,mode,flags)
# define qse_fs_rmfile(fs,path,flags) qse_fs_rmfilembs(fs,path,flags) # define qse_fs_rmfile(fs,path,flags) qse_fs_rmfilembs(fs,path,flags)
# define qse_fs_rmdir(fs,path,flags) qse_fs_rmdirmbs(fs,path,flags) # define qse_fs_rmdir(fs,path,flags) qse_fs_rmdirmbs(fs,path,flags)
#else #else
# define qse_fs_mkdir(fs,path,flags) qse_fs_mkdirwcs(fs,path,flags) # define qse_fs_mkdir(fs,path,mode,flags) qse_fs_mkdirwcs(fs,path,mode,flags)
# define qse_fs_rmfile(fs,path,flags) qse_fs_rmfilewcs(fs,path,flags) # define qse_fs_rmfile(fs,path,flags) qse_fs_rmfilewcs(fs,path,flags)
# define qse_fs_rmdir(fs,path,flags) qse_fs_rmdirwcs(fs,path,flags) # define qse_fs_rmdir(fs,path,flags) qse_fs_rmdirwcs(fs,path,flags)
#endif #endif

View File

@ -515,7 +515,7 @@ start_over:
goto oops; goto oops;
} }
if (qse_fs_mkdirsys (fs, cpfile->dst_fspath) <= -1) if (qse_fs_mkdirsys(fs, cpfile->dst_fspath, 0777) <= -1) /* TODO: copy mode? */
{ {
/* it's ok if the destination directory already exists */ /* it's ok if the destination directory already exists */
if (fs->errnum != QSE_FS_EEXIST) goto oops; if (fs->errnum != QSE_FS_EEXIST) goto oops;
@ -700,7 +700,7 @@ int qse_fs_cpfilembs (qse_fs_t* fs, const qse_mchar_t* srcpath, const qse_mchar_
if (flags & QSE_FS_CPFILE_GLOB) if (flags & QSE_FS_CPFILE_GLOB)
{ {
fs->errnum = QSE_FS_ENOERR; fs->errnum = QSE_FS_ENOERR;
if (qse_globmbs (srcpath, copy_file_for_glob, &ctx, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr) <= -1) if (qse_globmbs(srcpath, copy_file_for_glob, &ctx, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr) <= -1)
{ {
if (fs->errnum == QSE_FS_ENOERR) fs->errnum = QSE_FS_EGLOB; if (fs->errnum == QSE_FS_ENOERR) fs->errnum = QSE_FS_EGLOB;
ret = -1; ret = -1;
@ -738,7 +738,7 @@ int qse_fs_cpfilewcs (qse_fs_t* fs, const qse_wchar_t* srcpath, const qse_wchar_
if (flags & QSE_FS_CPFILE_GLOB) if (flags & QSE_FS_CPFILE_GLOB)
{ {
fs->errnum = QSE_FS_ENOERR; fs->errnum = QSE_FS_ENOERR;
if (qse_globwcs (srcpath, copy_file_for_glob, &ctx, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr) <= -1) if (qse_globwcs(srcpath, copy_file_for_glob, &ctx, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr) <= -1)
{ {
if (fs->errnum == QSE_FS_ENOERR) fs->errnum = QSE_FS_EGLOB; if (fs->errnum == QSE_FS_ENOERR) fs->errnum = QSE_FS_EGLOB;
ret = -1; ret = -1;

View File

@ -26,7 +26,7 @@
#include "fs-prv.h" #include "fs-prv.h"
int qse_fs_mkdirsys (qse_fs_t* fs, const qse_fs_char_t* fspath) int qse_fs_mkdirsys (qse_fs_t* fs, const qse_fs_char_t* fspath, qse_fs_mode_t mode)
{ {
#if defined(_WIN32) #if defined(_WIN32)
@ -78,7 +78,7 @@ int qse_fs_mkdirsys (qse_fs_t* fs, const qse_fs_char_t* fspath)
#else #else
if (QSE_MKDIR (fspath, 0777) <= -1) /* TODO: proper mode?? */ if (QSE_MKDIR (fspath, mode) <= -1) /* TODO: proper mode?? */
{ {
fs->errnum = qse_fs_syserrtoerrnum (fs, errno); fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
return -1; return -1;
@ -91,7 +91,7 @@ int qse_fs_mkdirsys (qse_fs_t* fs, const qse_fs_char_t* fspath)
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath) static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath, qse_fs_mode_t mode)
{ {
qse_fs_char_t* core, * p, c; qse_fs_char_t* core, * p, c;
int ret = 0; int ret = 0;
@ -120,7 +120,7 @@ static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath)
c = *(p + 1); c = *(p + 1);
*(p + 1) = QSE_FS_T('\0'); *(p + 1) = QSE_FS_T('\0');
#endif #endif
ret = qse_fs_mkdirsys (fs, fspath); ret = qse_fs_mkdirsys (fs, fspath, mode);
if (ret <= -1 && fs->errnum != QSE_FS_EEXIST) goto done; /* abort */ if (ret <= -1 && fs->errnum != QSE_FS_EEXIST) goto done; /* abort */
#if defined(_WIN32) || defined(__DOS__) || defined(__OS2__) #if defined(_WIN32) || defined(__DOS__) || defined(__OS2__)
*p = c; *p = c;
@ -130,13 +130,13 @@ static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath)
} }
} }
if (!IS_FSPATHSEP(*(p - 1))) ret = qse_fs_mkdirsys (fs, fspath); if (!IS_FSPATHSEP(*(p - 1))) ret = qse_fs_mkdirsys (fs, fspath, mode);
done: done:
return ret; return ret;
} }
int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, qse_fs_mode_t mode, int flags)
{ {
qse_fs_char_t* fspath; qse_fs_char_t* fspath;
int ret; int ret;
@ -154,14 +154,14 @@ int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags)
fspath = qse_fs_dupfspathformbs (fs, path); fspath = qse_fs_dupfspathformbs (fs, path);
if (!fspath) return -1; if (!fspath) return -1;
ret = make_directory_chain (fs, fspath); ret = make_directory_chain (fs, fspath, mode);
} }
else else
{ {
fspath = (qse_fs_char_t*)qse_fs_makefspathformbs (fs, path); fspath = (qse_fs_char_t*)qse_fs_makefspathformbs (fs, path);
if (!fspath) return -1; if (!fspath) return -1;
ret = qse_fs_mkdirsys (fs, fspath); ret = qse_fs_mkdirsys (fs, fspath, mode);
} }
qse_fs_freefspathformbs (fs, path, fspath); qse_fs_freefspathformbs (fs, path, fspath);
@ -169,7 +169,7 @@ int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags)
return ret; return ret;
} }
int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, qse_fs_mode_t mode, int flags)
{ {
qse_fs_char_t* fspath; qse_fs_char_t* fspath;
int ret; int ret;
@ -187,14 +187,14 @@ int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags)
fspath = qse_fs_dupfspathforwcs (fs, path); fspath = qse_fs_dupfspathforwcs (fs, path);
if (!fspath) return -1; if (!fspath) return -1;
ret = make_directory_chain (fs, fspath); ret = make_directory_chain (fs, fspath, mode);
} }
else else
{ {
fspath = (qse_fs_char_t*)qse_fs_makefspathforwcs (fs, path); fspath = (qse_fs_char_t*)qse_fs_makefspathforwcs (fs, path);
if (!fspath) return -1; if (!fspath) return -1;
ret = qse_fs_mkdirsys (fs, fspath); ret = qse_fs_mkdirsys (fs, fspath, mode);
} }
qse_fs_freefspathforwcs (fs, path, fspath); qse_fs_freefspathforwcs (fs, path, fspath);

View File

@ -179,7 +179,8 @@ int qse_fs_syscpfile (
int qse_fs_mkdirsys ( int qse_fs_mkdirsys (
qse_fs_t* fs, qse_fs_t* fs,
const qse_fs_char_t* fspath const qse_fs_char_t* fspath,
qse_fs_mode_t mode
); );
int qse_fs_rmfilesys ( int qse_fs_rmfilesys (

View File

@ -103,8 +103,7 @@ static qse_sio_errnum_t tio_errnum_to_sio_errnum (qse_tio_t* tio)
} }
} }
qse_sio_t* qse_sio_open ( qse_sio_t* qse_sio_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* file, int flags)
qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* file, int flags)
{ {
qse_sio_t* sio; qse_sio_t* sio;
@ -161,8 +160,7 @@ void qse_sio_close (qse_sio_t* sio)
QSE_MMGR_FREE (sio->mmgr, sio); QSE_MMGR_FREE (sio->mmgr, sio);
} }
int qse_sio_init ( int qse_sio_init (qse_sio_t* sio, qse_mmgr_t* mmgr, const qse_char_t* path, int flags)
qse_sio_t* sio, qse_mmgr_t* mmgr, const qse_char_t* path, int flags)
{ {
int mode; int mode;
int topt = 0; int topt = 0;