changed the default cmgr to utf8
added qse_get_prog_mbspath_with_mmgr()/qse_get_prog_wcspath_with_mmgr() filled Path::setToSelf().
This commit is contained in:
parent
c794863aa6
commit
2ff8ee7c27
@ -41,14 +41,16 @@ public:
|
||||
};
|
||||
|
||||
Path (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
|
||||
Path (const qse_char_t* n, Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
|
||||
Path (const qse_mchar_t* n, Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
|
||||
Path (const qse_wchar_t* n, Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
|
||||
Path (const Path& path) QSE_CPP_NOEXCEPT;
|
||||
Path& operator= (const Path& path) QSE_CPP_NOEXCEPT;
|
||||
|
||||
// NOTE: the current implementation doesn't have much to benefit from C++11 Move
|
||||
// semantics and the rvalue reference.
|
||||
|
||||
void setName (const qse_char_t* n) QSE_CPP_NOEXCEPT;
|
||||
void setName (const qse_wchar_t* n) QSE_CPP_NOEXCEPT;
|
||||
void setName (const qse_mchar_t* n) QSE_CPP_NOEXCEPT;
|
||||
|
||||
const qse_char_t* getName () const QSE_CPP_NOEXCEPT { return this->full_path; }
|
||||
const qse_char_t* getBaseName () const QSE_CPP_NOEXCEPT { return this->base_name; }
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
#include <qse/cmn/time.h>
|
||||
#include <qse/cmn/mem.h>
|
||||
|
||||
struct qse_fattr_t
|
||||
{
|
||||
@ -60,9 +61,9 @@ typedef struct qse_fattr_t qse_fattr_t;
|
||||
|
||||
enum qse_fperm_t
|
||||
{
|
||||
QSE_FPERM_READ,
|
||||
QSE_FPERM_WRITE,
|
||||
QSE_FPERM_EXEC
|
||||
QSE_FPERM_READ = 4, /* R */
|
||||
QSE_FPERM_WRITE = 2, /* W */
|
||||
QSE_FPERM_EXEC = 1 /* X */
|
||||
};
|
||||
typedef enum qse_fperm_t qse_fperm_t;
|
||||
|
||||
@ -506,63 +507,94 @@ QSE_EXPORT int qse_fs_rmdirwcs (
|
||||
* GLOBAL UTILITIES NOT USING THE FS OBJECT
|
||||
* ========================================================================= */
|
||||
|
||||
QSE_EXPORT qse_mchar_t* qse_get_current_mbsdir (
|
||||
QSE_EXPORT qse_mchar_t* qse_get_current_mbsdir_with_mmgr (
|
||||
qse_mchar_t* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_wchar_t* qse_get_current_wcsdir (
|
||||
qse_wchar_t* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_get_mbsfile_attr (
|
||||
const qse_mchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_attr_flag_t enumerators */
|
||||
qse_fattr_t* attr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_get_wcsfile_attr (
|
||||
const qse_wchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_attr_flag_t enumerators */
|
||||
qse_fattr_t* attr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_check_mbsfile_perm (
|
||||
const qse_mchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_perm_flag_t enumerators */
|
||||
qse_fperm_t perm
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_check_wcsfile_perm (
|
||||
const qse_wchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_perm_flag_t enumerators */
|
||||
qse_fperm_t perm
|
||||
);
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_get_current_dir(buf,size) qse_get_current_mbsdir(buf,size)
|
||||
# define qse_get_file_attr(file,flags,attr) qse_get_mbsfile_attr(file,flags,attr)
|
||||
# define qse_check_file_perm(file,flags,perm) qse_check_mbsfile_perm(file,flags,perm)
|
||||
#else
|
||||
# define qse_get_current_dir(buf,size) qse_get_current_wcsdir(buf,size)
|
||||
# define qse_get_file_attr(file,flags,attr) qse_get_wcsfile_attr(file,flags,attr)
|
||||
# define qse_check_file_perm(file,flags,perm) qse_check_wcsfile_perm(file,flags,perm)
|
||||
#endif
|
||||
|
||||
QSE_EXPORT int qse_get_prog_path_with_mmgr (
|
||||
const qse_char_t* argv0,
|
||||
qse_char_t* buf,
|
||||
qse_size_t size,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_get_prog_path (
|
||||
const qse_char_t* argv0,
|
||||
qse_char_t* buf,
|
||||
qse_size_t size
|
||||
QSE_EXPORT qse_wchar_t* qse_get_current_wcsdir_with_mmgr (
|
||||
qse_wchar_t* buf,
|
||||
qse_size_t size,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#define qse_get_current_mbsdir(buf,size) qse_get_current_mbsdir_with_mmgr(buf,size,QSE_MMGR_GETDFL())
|
||||
#define qse_get_current_wcsdir(buf,size) qse_get_current_wcsdir_with_mmgr(buf,size,QSE_MMGR_GETDFL())
|
||||
|
||||
QSE_EXPORT int qse_get_mbsfile_attr_with_mmgr (
|
||||
const qse_mchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_attr_flag_t enumerators */
|
||||
qse_fattr_t* attr,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_get_wcsfile_attr_with_mmgr (
|
||||
const qse_wchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_attr_flag_t enumerators */
|
||||
qse_fattr_t* attr,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#define qse_get_mbsfile_attr(file,flags,attr) qse_get_mbsfile_attr_with_mmgr(file,flags,attr,QSE_MMGR_GETDFL())
|
||||
#define qse_get_wcsfile_attr(file,flags,attr) qse_get_wcsfile_attr_with_mmgr(file,flags,attr,QSE_MMGR_GETDFL())
|
||||
|
||||
QSE_EXPORT int qse_check_mbsfile_perm_with_mmgr (
|
||||
const qse_mchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_perm_flag_t enumerators */
|
||||
qse_fperm_t perm, /* 0 or bitwise-ORed of the qse_fperm_t enumerators */
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_check_wcsfile_perm_with_mmgr (
|
||||
const qse_wchar_t* file,
|
||||
int flags, /* 0 or bitwise-ORed of the qse_file_perm_flag_t enumerators */
|
||||
qse_fperm_t perm,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#define qse_check_mbsfile_perm(file,flags,perm) qse_check_mbsfile_perm_with_mmgr(file,flags,perm,QSE_MMGR_GETDFL())
|
||||
#define qse_check_wcsfile_perm(file,flags,perm) qse_check_wcsfile_perm_with_mmgr(file,flags,perm,QSE_MMGR_GETDFL())
|
||||
|
||||
QSE_EXPORT int qse_get_prog_mbspath_with_mmgr (
|
||||
const qse_mchar_t* argv0,
|
||||
qse_mchar_t* buf,
|
||||
qse_size_t size,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_get_prog_wcspath_with_mmgr (
|
||||
const qse_wchar_t* argv0,
|
||||
qse_wchar_t* buf,
|
||||
qse_size_t size,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
|
||||
#define qse_get_prog_mbspath(argv0,buf,size) qse_get_prog_mbspath_with_mmgr(argv0, buf, size, QSE_MMGR_GETDFL())
|
||||
#define qse_get_prog_wcspath(argv0,buf,size) qse_get_prog_wcspath_with_mmgr(argv0, buf, size, QSE_MMGR_GETDFL())
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_get_current_dir_with_mmgr(buf,size,mmgr) qse_get_current_mbsdir_with_mmgr(buf,size,mmgr)
|
||||
# define qse_get_current_dir(buf,size) qse_get_current_mbsdir(buf,size)
|
||||
# define qse_get_file_attr_with_mmgr(file,flags,attr,mmgr) qse_get_mbsfile_attr_with_mmgr(file,flags,attr,mmgr)
|
||||
# define qse_get_file_attr(file,flags,attr) qse_get_mbsfile_attr(file,flags,attr)
|
||||
# define qse_check_file_perm_with_mmgr(file,flags,perm,mmgr) qse_check_mbsfile_perm_with_mmgr(file,flags,perm,mmgr)
|
||||
# define qse_check_file_perm(file,flags,perm) qse_check_mbsfile_perm(file,flags,perm)
|
||||
# define qse_get_prog_path_with_mmgr(argv0,buf,size,mmgr) qse_get_prog_mbspath_with_mmgr(argv0,buf,size,mmgr)
|
||||
# define qse_get_prog_path(argv0,buf,size) qse_get_prog_mbspath(argv0,buf,size)
|
||||
#else
|
||||
# define qse_get_current_dir_with_mmgr(buf,size,mmgr) qse_get_current_mbsdir_with_mmgr(buf,size,mmgr)
|
||||
# define qse_get_current_dir(buf,size) qse_get_current_wcsdir(buf,size)
|
||||
# define qse_get_file_attr_with_mmgr(file,flags,attr,mmgr) qse_get_wcsfile_attr_with_mmgr(file,flags,attr,mmgr)
|
||||
# define qse_get_file_attr(file,flags,attr) qse_get_wcsfile_attr(file,flags,attr)
|
||||
# define qse_check_file_perm_with_mmgr(file,flags,perm,mmgr) qse_check_wcsfile_perm_with_mmgr(file,flags,perm,mmgr)
|
||||
# define qse_check_file_perm(file,flags,perm) qse_check_wcsfile_perm(file,flags,perm)
|
||||
# define qse_get_prog_path_with_mmgr(argv0,buf,size,mmgr) qse_get_prog_wcspath_with_mmgr(argv0,buf,size,mmgr)
|
||||
# define qse_get_prog_path(argv0,buf,size) qse_get_prog_wcspath(argv0,buf,size)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -42,7 +42,7 @@ static int mbs_to_wcs_with_cmgr (
|
||||
for (mp = mbs; *mp != QSE_MT('\0'); mp++);
|
||||
|
||||
mlen = mp - mbs; wlen = *wcslen;
|
||||
n = mbsn_to_wcsn_with_cmgr (mbs, &mlen, wcs, &wlen, cmgr, all);
|
||||
n = mbsn_to_wcsn_with_cmgr(mbs, &mlen, wcs, &wlen, cmgr, all);
|
||||
if (wcs)
|
||||
{
|
||||
if (wlen < *wcslen) wcs[wlen] = QSE_WT('\0');
|
||||
@ -57,14 +57,14 @@ int qse_mbstowcswithcmgr (
|
||||
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
||||
qse_wchar_t* wcs, qse_size_t* wcslen, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbs_to_wcs_with_cmgr (mbs, mbslen, wcs, wcslen, cmgr, 0);
|
||||
return mbs_to_wcs_with_cmgr(mbs, mbslen, wcs, wcslen, cmgr, 0);
|
||||
}
|
||||
|
||||
int qse_mbstowcsallwithcmgr (
|
||||
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
||||
qse_wchar_t* wcs, qse_size_t* wcslen, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbs_to_wcs_with_cmgr (mbs, mbslen, wcs, wcslen, cmgr, 1);
|
||||
return mbs_to_wcs_with_cmgr(mbs, mbslen, wcs, wcslen, cmgr, 1);
|
||||
}
|
||||
|
||||
static int mbsn_to_wcsn_with_cmgr (
|
||||
@ -95,7 +95,7 @@ static int mbsn_to_wcsn_with_cmgr (
|
||||
break;
|
||||
}
|
||||
|
||||
n = cmgr->mbtowc (p, mlen, q);
|
||||
n = cmgr->mbtowc(p, mlen, q);
|
||||
if (n == 0)
|
||||
{
|
||||
/* invalid sequence */
|
||||
@ -183,14 +183,14 @@ int qse_mbsntowcsnwithcmgr (
|
||||
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
||||
qse_wchar_t* wcs, qse_size_t* wcslen, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbsn_to_wcsn_with_cmgr (mbs, mbslen, wcs, wcslen, cmgr, 0);
|
||||
return mbsn_to_wcsn_with_cmgr(mbs, mbslen, wcs, wcslen, cmgr, 0);
|
||||
}
|
||||
|
||||
int qse_mbsntowcsnallwithcmgr (
|
||||
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
||||
qse_wchar_t* wcs, qse_size_t* wcslen, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbsn_to_wcsn_with_cmgr (mbs, mbslen, wcs, wcslen, cmgr, 1);
|
||||
return mbsn_to_wcsn_with_cmgr(mbs, mbslen, wcs, wcslen, cmgr, 1);
|
||||
}
|
||||
|
||||
int qse_mbsntowcsnuptowithcmgr (
|
||||
@ -259,8 +259,7 @@ static qse_wchar_t* mbsn_to_wcs_dup_with_cmgr (
|
||||
qse_wchar_t* wcs;
|
||||
|
||||
ml = *mbslen;
|
||||
if (mbsn_to_wcsn_with_cmgr (
|
||||
mbs, &ml, QSE_NULL, &wl, cmgr, all) <= -1) return QSE_NULL;
|
||||
if (mbsn_to_wcsn_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));
|
||||
|
@ -50,7 +50,7 @@ static qse_cmgr_t builtin_cmgr[] =
|
||||
#endif
|
||||
};
|
||||
|
||||
#define DEFAULT_CMGR QSE_CMGR_SLMB
|
||||
#define DEFAULT_CMGR QSE_CMGR_UTF8
|
||||
|
||||
static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[DEFAULT_CMGR];
|
||||
static qse_cmgr_finder_t cmgr_finder = QSE_NULL;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#undef strxcajoinv
|
||||
#undef strcpy
|
||||
#undef strxcpy
|
||||
#undef strlen
|
||||
|
||||
#define char_t qse_mchar_t
|
||||
#define strjoin qse_mbsjoin
|
||||
@ -51,6 +52,7 @@
|
||||
#define strxcajoinv qse_mbsxcajoinv
|
||||
#define strcpy qse_mbscpy
|
||||
#define strxcpy qse_mbsxcpy
|
||||
#define strlen qse_mbslen
|
||||
#include "str-join.h"
|
||||
|
||||
/* ----------------------------------- */
|
||||
@ -66,6 +68,7 @@
|
||||
#undef strxcajoinv
|
||||
#undef strcpy
|
||||
#undef strxcpy
|
||||
#undef strlen
|
||||
|
||||
#define char_t qse_wchar_t
|
||||
#define strjoin qse_wcsjoin
|
||||
@ -78,4 +81,5 @@
|
||||
#define strxcajoinv qse_wcsxcajoinv
|
||||
#define strcpy qse_wcscpy
|
||||
#define strxcpy qse_wcsxcpy
|
||||
#define strlen qse_wcslen
|
||||
#include "str-join.h"
|
||||
|
@ -104,8 +104,8 @@ qse_size_t strxcajoinv (char_t* buf, qse_size_t size, va_list ap)
|
||||
|
||||
while (left > 0)
|
||||
{
|
||||
p = va_arg (ap, const char_t*);
|
||||
if (p == QSE_NULL) break;
|
||||
p = va_arg(ap, const char_t*);
|
||||
if (!p) break;
|
||||
|
||||
n = strxcpy(ptr, left, p);
|
||||
left -= n; ptr += n;
|
||||
|
@ -414,6 +414,12 @@
|
||||
# define QSE_ACCESS(path,mode) access(path,mode)
|
||||
#endif
|
||||
|
||||
#if defined(SYS_faccessat) && defined(QSE_USE_SYSCALL)
|
||||
# define QSE_FACCESSAT(dirfd,path,mode,flags) syscall(SYS_faccessat,dirfd,path,mode,flags)
|
||||
#elif defined(HAVE_FACCESSAT)
|
||||
# define QSE_FACCESSAT(dirfd,path,mode,flags) faccessat(dirfd,path,mode,flags)
|
||||
#endif
|
||||
|
||||
#if defined(SYS_rename) && defined(QSE_USE_SYSCALL)
|
||||
# define QSE_RENAME(oldpath,newpath) syscall(SYS_rename,oldpath,newpath)
|
||||
#else
|
||||
|
@ -31,8 +31,6 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include "../cmn/syscall.h"
|
||||
|
||||
|
||||
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
|
||||
Path::Path (Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr)
|
||||
@ -40,7 +38,12 @@ Path::Path (Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr)
|
||||
this->set_to_root ();
|
||||
}
|
||||
|
||||
Path::Path (const qse_char_t* n, Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr)
|
||||
Path::Path (const qse_mchar_t* n, Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr)
|
||||
{
|
||||
this->setName (n);
|
||||
}
|
||||
|
||||
Path::Path (const qse_wchar_t* n, Mmgr* mmgr) QSE_CPP_NOEXCEPT: Mmged(mmgr)
|
||||
{
|
||||
this->setName (n);
|
||||
}
|
||||
@ -62,12 +65,32 @@ Path& Path::operator= (const Path& path) QSE_CPP_NOEXCEPT
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Path::setName (const qse_char_t* n) QSE_CPP_NOEXCEPT
|
||||
void Path::setName (const qse_mchar_t* n) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (n == QSE_NULL || n[0] == QSE_T('\0')) this->set_to_root();
|
||||
if (n == QSE_NULL || n[0] == QSE_MT('\0')) this->set_to_root();
|
||||
else
|
||||
{
|
||||
qse_strxcpy (this->full_path, QSE_COUNTOF(this->full_path), n);
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_mbsxcpy (this->full_path, QSE_COUNTOF(this->full_path), n);
|
||||
#else
|
||||
qse_size_t ml, wl = QSE_COUNTOF(this->full_path);
|
||||
qse_mbstowcsall (n, &ml, this->full_path, &wl);
|
||||
#endif
|
||||
this->set_base_name ();
|
||||
}
|
||||
}
|
||||
|
||||
void Path::setName (const qse_wchar_t* n) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (n == QSE_NULL || n[0] == QSE_WT('\0')) this->set_to_root();
|
||||
else
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_size_t ml = QSE_COUNTOF(this->full_path), wl;
|
||||
qse_wcstombsall (n, &wl, this->full_path, &ml);
|
||||
#else
|
||||
qse_wcsxcpy (this->full_path, QSE_COUNTOF(this->full_path), n);
|
||||
#endif
|
||||
this->set_base_name ();
|
||||
}
|
||||
}
|
||||
@ -285,13 +308,16 @@ void Path::set_to_root () QSE_CPP_NOEXCEPT
|
||||
|
||||
int Path::setToSelf (const qse_mchar_t* argv0) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
qse_mchar_t p[MAX_LEN + 1];
|
||||
if (qse_get_prog_mbspath_with_mmgr(argv0, p, QSE_COUNTOF(p), this->getMmgr()) == -1) return -1;
|
||||
this->setName (p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Path::setToSelf (const qse_wchar_t* argv0) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
qse_char_t p[MAX_LEN + 1];
|
||||
if (qse_get_prog_path_with_mmgr(argv0, p, QSE_COUNTOF(p), this->getMmgr()) == -1) return -1;
|
||||
qse_wchar_t p[MAX_LEN + 1];
|
||||
if (qse_get_prog_wcspath_with_mmgr(argv0, p, QSE_COUNTOF(p), this->getMmgr()) == -1) return -1;
|
||||
this->setName (p);
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,9 +36,8 @@
|
||||
/* ==========================================================================
|
||||
* CURRENT WORKING DIRECTORY
|
||||
* ========================================================================== */
|
||||
qse_mchar_t* qse_get_current_mbsdir (qse_mchar_t* buf, qse_size_t size)
|
||||
qse_mchar_t* qse_get_current_mbsdir_with_mmgr (qse_mchar_t* buf, qse_size_t size, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_mmgr_t* mmgr = QSE_MMGR_GETDFL();
|
||||
qse_mchar_t* tmp;
|
||||
|
||||
if (buf)
|
||||
@ -74,10 +73,9 @@ again:
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_get_current_wcsdir (qse_wchar_t* buf, qse_size_t size)
|
||||
qse_wchar_t* qse_get_current_wcsdir_with_mmgr (qse_wchar_t* buf, qse_size_t size, qse_mmgr_t* mmgr)
|
||||
{
|
||||
/* TODO: for WIN32, use the unicode API directly */
|
||||
qse_mmgr_t* mmgr = QSE_MMGR_GETDFL();
|
||||
qse_mchar_t* mbsdir;
|
||||
qse_wchar_t* wcsdir;
|
||||
qse_size_t wcslen;
|
||||
@ -147,7 +145,7 @@ void qse_stat_to_attr (const qse_stat_t* st, qse_fattr_t* attr)
|
||||
#endif
|
||||
}
|
||||
|
||||
int qse_get_mbsfile_attr (const qse_mchar_t* file, int flags, qse_fattr_t* attr)
|
||||
int qse_get_mbsfile_attr_with_mmgr (const qse_mchar_t* file, int flags, qse_fattr_t* attr, qse_mmgr_t* mmgr)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return -1;
|
||||
@ -158,7 +156,7 @@ int qse_get_mbsfile_attr (const qse_mchar_t* file, int flags, qse_fattr_t* attr)
|
||||
#elif defined(__DOS__)
|
||||
return -1;
|
||||
|
||||
#elif defined(HAVE_FSTATAT) && defined(AT_SYMLINK_NOFOLLOW)
|
||||
#elif defined(QSE_FSTATAT) && defined(AT_SYMLINK_NOFOLLOW)
|
||||
qse_fstatat_t st;
|
||||
int sysflags = 0;
|
||||
|
||||
@ -183,12 +181,11 @@ int qse_get_mbsfile_attr (const qse_mchar_t* file, int flags, qse_fattr_t* attr)
|
||||
#endif
|
||||
}
|
||||
|
||||
int qse_get_wcsfile_attr (const qse_wchar_t* file, int flags, qse_fattr_t* attr)
|
||||
int qse_get_wcsfile_attr_with_mmgr (const qse_wchar_t* file, int flags, qse_fattr_t* attr, qse_mmgr_t* mmgr)
|
||||
{
|
||||
/* TODO: for WIN32, use the unicode API directly */
|
||||
qse_mchar_t* mbsfile;
|
||||
qse_mchar_t mbsfile_buf[QSE_PATH_MAX];
|
||||
qse_mmgr_t* mmgr = QSE_MMGR_GETDFL();
|
||||
qse_size_t wl, ml;
|
||||
int n;
|
||||
|
||||
@ -213,15 +210,20 @@ int qse_get_wcsfile_attr (const qse_wchar_t* file, int flags, qse_fattr_t* attr)
|
||||
return n;
|
||||
}
|
||||
|
||||
int qse_check_mbsfile_perm (const qse_mchar_t* file, int flags, qse_fperm_t perm)
|
||||
int qse_check_mbsfile_perm_with_mmgr (const qse_mchar_t* file, int flags, qse_fperm_t perm, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return -1;
|
||||
#if defined(QSE_FACCESSAT) && defined(AT_SYMLINK_NOFOLLOW)
|
||||
int sysflags = 0;
|
||||
if (flags & QSE_FILE_PERM_SYMLINK) sysflags |= AT_SYMLINK_FOLLOW;
|
||||
return QSE_FACCESSAT(AT_FDCWD, file, perm, sysflags);
|
||||
#else
|
||||
return QSE_ACCESS(file, perm);
|
||||
#endif
|
||||
}
|
||||
|
||||
int qse_check_wcsfile_perm (const qse_wchar_t* file, int flags, qse_fperm_t perm)
|
||||
int qse_check_wcsfile_perm_with_mmgr (const qse_wchar_t* file, int flags, qse_fperm_t perm, qse_mmgr_t* mmgr)
|
||||
{
|
||||
/* TODO: for WIN32, use the unicode API directly */
|
||||
qse_mmgr_t* mmgr = QSE_MMGR_GETDFL();
|
||||
qse_mchar_t* mbsfile;
|
||||
qse_mchar_t mbsfile_buf[QSE_PATH_MAX];
|
||||
qse_size_t wl, ml;
|
||||
@ -248,54 +250,42 @@ int qse_check_wcsfile_perm (const qse_wchar_t* file, int flags, qse_fperm_t perm
|
||||
return n;
|
||||
}
|
||||
|
||||
int qse_get_prog_path_with_mmgr (const qse_char_t* argv0, qse_char_t* buf, qse_size_t size, qse_mmgr_t* mmgr)
|
||||
int qse_get_prog_mbspath_with_mmgr (const qse_mchar_t* argv0, qse_mchar_t* buf, qse_size_t size, qse_mmgr_t* mmgr)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (GetModuleFileName(QSE_NULL, buf, size) == 0) return -1;
|
||||
if (GetModuleFileNameA(QSE_NULL, buf, size) == 0) return -1;
|
||||
#else
|
||||
if (argv0 == QSE_NULL) return -1;
|
||||
if (!argv0) return -1;
|
||||
|
||||
if (argv0[0] == QSE_T('/'))
|
||||
if (argv0[0] == QSE_MT('/'))
|
||||
{
|
||||
/*qse_strxcpy (buf, size, argv0);*/
|
||||
qse_canonpath(argv0, buf, size);
|
||||
qse_canonmbspath(argv0, buf, size);
|
||||
}
|
||||
else if (qse_strchr(argv0, QSE_T('/')))
|
||||
else if (qse_mbschr(argv0, QSE_MT('/')))
|
||||
{
|
||||
if (!qse_get_current_dir(buf, size)) return -1;
|
||||
qse_strxcajoin (buf, size, QSE_T("/"), argv0, QSE_NULL);
|
||||
qse_canonpath (buf, buf, size);
|
||||
if (!qse_get_current_mbsdir(buf, size)) return -1;
|
||||
qse_mbsxcajoin (buf, size, QSE_MT("/"), argv0, QSE_NULL);
|
||||
qse_canonmbspath (buf, buf, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_char_t *p, *q, * px = QSE_NULL;
|
||||
qse_mchar_t *p, *q, * px = QSE_NULL;
|
||||
qse_fattr_t attr;
|
||||
qse_char_t dir[QSE_PATH_MAX + 1];
|
||||
qse_char_t pbuf[QSE_PATH_MAX + 1];
|
||||
qse_mchar_t dir[QSE_PATH_MAX + 1];
|
||||
qse_mchar_t pbuf[QSE_PATH_MAX + 1];
|
||||
int first = 1;
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
p = getenv("PATH");
|
||||
if (!p) p = (qse_char_t*)QSE_T("/bin:/usr/bin");
|
||||
#else
|
||||
qse_mchar_t* mp = getenv ("PATH");
|
||||
if (!p) p = (qse_mchar_t*)QSE_MT("/bin:/usr/bin");
|
||||
|
||||
if (!mp) p = (qse_char_t*)QSE_T("/bin:/usr/bin");
|
||||
else
|
||||
{
|
||||
px = qse_mbstowcsdup(mp, QSE_NULL, mmgr);
|
||||
if (!px) return -1;
|
||||
p = px;
|
||||
}
|
||||
#endif
|
||||
for (;;)
|
||||
{
|
||||
while (*p == QSE_T(':')) p++;
|
||||
if (*p == QSE_T('\0'))
|
||||
while (*p == QSE_MT(':')) p++;
|
||||
if (*p == QSE_MT('\0'))
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
p = (qse_char_t*)QSE_T("./");
|
||||
p = (qse_mchar_t*)QSE_MT("./");
|
||||
first = 0;
|
||||
}
|
||||
else
|
||||
@ -306,7 +296,7 @@ int qse_get_prog_path_with_mmgr (const qse_char_t* argv0, qse_char_t* buf, qse_s
|
||||
}
|
||||
|
||||
q = p;
|
||||
while (*p != QSE_T(':') && *p != QSE_T('\0')) p++;
|
||||
while (*p != QSE_MT(':') && *p != QSE_MT('\0')) p++;
|
||||
|
||||
if (p - q >= QSE_COUNTOF(dir) - 1)
|
||||
{
|
||||
@ -314,29 +304,23 @@ int qse_get_prog_path_with_mmgr (const qse_char_t* argv0, qse_char_t* buf, qse_s
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_strxncpy (dir, QSE_COUNTOF(dir), q, p - q);
|
||||
qse_canonpath (dir, dir, QSE_COUNTOF(dir));
|
||||
qse_mbsxncpy (dir, QSE_COUNTOF(dir), q, p - q);
|
||||
qse_canonmbspath (dir, dir, QSE_COUNTOF(dir));
|
||||
|
||||
qse_strxjoin (pbuf, QSE_COUNTOF(pbuf), dir, QSE_T("/"), argv0, QSE_NULL);
|
||||
qse_mbsxjoin (pbuf, QSE_COUNTOF(pbuf), dir, QSE_MT("/"), argv0, QSE_NULL);
|
||||
|
||||
if (qse_check_file_perm(pbuf, 0, QSE_FPERM_EXEC) >= 0 &&
|
||||
qse_get_file_attr(pbuf, 0, &attr) >= 0 && attr.isreg) break;
|
||||
/*
|
||||
if (qse_access(pbuf, QSE_ACCESS_EXECUTE) == 0 &&
|
||||
qse_stat(pbuf, &st) == 0 && S_ISREG(st.st_mode))
|
||||
{
|
||||
break;
|
||||
}*/
|
||||
if (qse_check_mbsfile_perm(pbuf, 0, QSE_FPERM_EXEC) >= 0 &&
|
||||
qse_get_mbsfile_attr(pbuf, 0, &attr) >= 0 && attr.isreg) break;
|
||||
}
|
||||
|
||||
if (px) QSE_MMGR_FREE (mmgr, px);
|
||||
|
||||
if (pbuf[0] == QSE_T('/')) qse_strxcpy (buf, size, pbuf);
|
||||
if (pbuf[0] == QSE_MT('/')) qse_mbsxcpy (buf, size, pbuf);
|
||||
else
|
||||
{
|
||||
if (!qse_get_current_dir(buf, size)) return -1;
|
||||
qse_strxcajoin (buf, size, QSE_T("/"), pbuf, QSE_NULL);
|
||||
qse_canonpath (buf, buf, size);
|
||||
if (!qse_get_current_mbsdir(buf, size)) return -1;
|
||||
qse_mbsxcajoin (buf, size, QSE_MT("/"), pbuf, QSE_NULL);
|
||||
qse_canonmbspath (buf, buf, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -344,7 +328,89 @@ int qse_get_prog_path_with_mmgr (const qse_char_t* argv0, qse_char_t* buf, qse_s
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_get_prog_path (const qse_char_t* argv0, qse_char_t* buf, qse_size_t size)
|
||||
|
||||
int qse_get_prog_wcspath_with_mmgr (const qse_wchar_t* argv0, qse_wchar_t* buf, qse_size_t size, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_get_prog_path_with_mmgr(argv0, buf, size, QSE_MMGR_GETDFL());
|
||||
#if defined(_WIN32)
|
||||
if (GetModuleFileNameW(QSE_NULL, buf, size) == 0) return -1;
|
||||
#else
|
||||
if (argv0 == QSE_NULL) return -1;
|
||||
|
||||
if (argv0[0] == QSE_WT('/'))
|
||||
{
|
||||
/*qse_wcsxcpy (buf, size, argv0);*/
|
||||
qse_canonwcspath(argv0, buf, size);
|
||||
}
|
||||
else if (qse_wcschr(argv0, QSE_WT('/')))
|
||||
{
|
||||
if (!qse_get_current_wcsdir(buf, size)) return -1;
|
||||
qse_wcsxcajoin (buf, size, QSE_WT("/"), argv0, QSE_NULL);
|
||||
qse_canonwcspath (buf, buf, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_wchar_t *p, *q, * px = QSE_NULL;
|
||||
qse_fattr_t attr;
|
||||
qse_wchar_t dir[QSE_PATH_MAX + 1];
|
||||
qse_wchar_t pbuf[QSE_PATH_MAX + 1];
|
||||
int first = 1;
|
||||
|
||||
qse_mchar_t* mp = getenv ("PATH");
|
||||
|
||||
if (!mp) p = (qse_wchar_t*)QSE_WT("/bin:/usr/bin");
|
||||
else
|
||||
{
|
||||
px = qse_mbstowcsdup(mp, QSE_NULL, mmgr);
|
||||
if (!px) return -1;
|
||||
p = px;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
while (*p == QSE_WT(':')) p++;
|
||||
if (*p == QSE_WT('\0'))
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
p = (qse_wchar_t*)QSE_WT("./");
|
||||
first = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (px) QSE_MMGR_FREE (mmgr, px);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
q = p;
|
||||
while (*p != QSE_WT(':') && *p != QSE_WT('\0')) p++;
|
||||
|
||||
if (p - q >= QSE_COUNTOF(dir) - 1)
|
||||
{
|
||||
if (px) QSE_MMGR_FREE (mmgr, px);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_wcsxncpy (dir, QSE_COUNTOF(dir), q, p - q);
|
||||
qse_canonwcspath (dir, dir, QSE_COUNTOF(dir));
|
||||
|
||||
qse_wcsxjoin (pbuf, QSE_COUNTOF(pbuf), dir, QSE_WT("/"), argv0, QSE_NULL);
|
||||
|
||||
if (qse_check_wcsfile_perm(pbuf, 0, QSE_FPERM_EXEC) >= 0 &&
|
||||
qse_get_wcsfile_attr(pbuf, 0, &attr) >= 0 && attr.isreg) break;
|
||||
}
|
||||
|
||||
if (px) QSE_MMGR_FREE (mmgr, px);
|
||||
|
||||
if (pbuf[0] == QSE_WT('/')) qse_wcsxcpy (buf, size, pbuf);
|
||||
else
|
||||
{
|
||||
if (!qse_get_current_wcsdir(buf, size)) return -1;
|
||||
qse_wcsxcajoin (buf, size, QSE_WT("/"), pbuf, QSE_NULL);
|
||||
qse_canonwcspath (buf, buf, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user