added qse_getpathcore()/qse_getmbspathcore()/qse_getwcspathcore()
added qse_fs_dupfspathforwcs() improved qse_fs_mkdirXXX()
This commit is contained in:
		| @ -71,63 +71,102 @@ static int make_directory_in_fs (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
|  | ||||
| /* --------------------------------------------------------------------- */ | ||||
|  | ||||
| static int make_directory_with_mbs (qse_fs_t* fs, const qse_mchar_t* path) | ||||
| static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath) | ||||
| { | ||||
| 	qse_fs_char_t* p, c; | ||||
| 	int ret = 0; | ||||
|  | ||||
| 	p = get_fspath_core (fspath); | ||||
| 	canon_fspath (p, p, 0); | ||||
| 	for (; *p; p++) | ||||
| 	{ | ||||
| 		if (IS_FSPATHSEP(*p)) | ||||
| 		{ | ||||
| 			c = *(p + 1); | ||||
| 			*(p + 1) = QSE_FS_T('\0'); | ||||
| 			ret = make_directory_in_fs (fs, fspath); | ||||
| 			if (ret <= -1 && fs->errnum != QSE_FS_EEXIST)  | ||||
| 			{ | ||||
| 				return -1; | ||||
| 				goto done; /* abort */ | ||||
| 			} | ||||
| 			*(p + 1) = c; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (!IS_FSPATHSEP(*(p - 1))) ret = make_directory_in_fs (fs, fspath); | ||||
|  | ||||
| done: | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| { | ||||
| 	qse_fs_char_t* fspath; | ||||
| 	int ret; | ||||
|  | ||||
| #if 0 | ||||
| 	if (fs->cbs.mk)  | ||||
| 	if (*path == QSE_MT('\0'))  | ||||
| 	{ | ||||
| 		int x; | ||||
| 		x = fs->cbs.mk (fs, path); | ||||
| 		if (x <= -1) return -1; | ||||
| 		if (x == 0) return 0; /* skipped */ | ||||
| 		fs->errnum = QSE_FS_EINVAL; | ||||
| 		return -1; | ||||
| 	} | ||||
| #endif | ||||
|  | ||||
| 	fspath = (qse_fs_char_t*)qse_fs_makefspathformbs (fs, path); | ||||
| 	if (!fspath) return -1; | ||||
| 	if (flags & QSE_FS_MKDIRMBS_PARENT) | ||||
| 	{ | ||||
| 		fspath = qse_fs_dupfspathformbs (fs, path); | ||||
| 		if (!fspath) return -1; | ||||
|  | ||||
| 		ret = make_directory_chain (fs, fspath); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		fspath = (qse_fs_char_t*)qse_fs_makefspathformbs (fs, path); | ||||
| 		if (!fspath) return -1; | ||||
|  | ||||
| 		ret = make_directory_in_fs (fs, fspath); | ||||
| 	} | ||||
|  | ||||
| 	ret = make_directory_from_fs (fs, fspath); | ||||
| 	qse_fs_freefspathformbs (fs, path, fspath); | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
|  | ||||
| static int make_directory_with_wcs (qse_fs_t* fs, const qse_wchar_t* path) | ||||
| int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| { | ||||
| 	qse_fs_char_t* fspath; | ||||
| 	int ret; | ||||
|  | ||||
| #if 0 | ||||
| 	if (fs->cbs.mk)  | ||||
| 	if (*path == QSE_WT('\0'))  | ||||
| 	{ | ||||
| 		int x; | ||||
| 		x = fs->cbs.del (fs, path); | ||||
| 		if (x <= -1) return -1; | ||||
| 		if (x == 0) return 0; /* skipped */ | ||||
| 		fs->errnum = QSE_FS_EINVAL; | ||||
| 		return -1; | ||||
| 	} | ||||
| #endif | ||||
|  | ||||
| 	fspath = (qse_fs_char_t*)qse_fs_makefspathforwcs (fs, path); | ||||
| 	if (!fspath) return -1; | ||||
| 	if (flags & QSE_FS_MKDIRWCS_PARENT) | ||||
| 	{ | ||||
| 		fspath = qse_fs_dupfspathforwcs (fs, path); | ||||
| 		if (!fspath) return -1; | ||||
|  | ||||
| 		ret = make_directory_chain (fs, fspath); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		fspath = (qse_fs_char_t*)qse_fs_makefspathforwcs (fs, path); | ||||
| 		if (!fspath) return -1; | ||||
|  | ||||
| 		ret = make_directory_in_fs (fs, fspath); | ||||
| 	} | ||||
|  | ||||
| 	ret = make_directory_from_fs (fs, fspath); | ||||
| 	qse_fs_freefspathforwcs (fs, path, fspath); | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
|  | ||||
| /* --------------------------------------------------------------------- */ | ||||
| int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path) | ||||
| { | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path) | ||||
| { | ||||
| 	return 0; | ||||
| } | ||||
| /* | ||||
| mknodmbs | ||||
| mkfifombs | ||||
| mknodwcs | ||||
| mknodwcs | ||||
| */ | ||||
|  | ||||
| @ -778,6 +778,34 @@ qse_fs_char_t* qse_fs_makefspathforwcs (qse_fs_t* fs, const qse_wchar_t* path) | ||||
| 	return fspath; | ||||
| } | ||||
|  | ||||
| qse_fs_char_t* qse_fs_dupfspathformbs (qse_fs_t* fs, const qse_mchar_t* path) | ||||
| { | ||||
| 	qse_fs_char_t* fspath; | ||||
|  | ||||
| #if defined(QSE_FS_CHAR_IS_MCHAR) | ||||
| 	fspath = qse_mbsdup (path, fs->mmgr); | ||||
| #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_dupfspathforwcs (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 = qse_wcsdup (path, fs->mmgr); | ||||
| #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); | ||||
|  | ||||
| @ -30,6 +30,7 @@ | ||||
| #include <qse/cmn/dir.h> | ||||
| #include <qse/cmn/mem.h> | ||||
| #include <qse/cmn/str.h> | ||||
| #include <qse/cmn/path.h> | ||||
|  | ||||
| #if defined(_WIN32) | ||||
| #	include <windows.h> | ||||
| @ -71,6 +72,18 @@ | ||||
| #	define free_str_with_mbs(fs,mbs,str) QSE_MMGR_FREE((fs)->mmgr,str) | ||||
| #endif | ||||
|  | ||||
| #if defined(QSE_FS_CHAR_IS_MCHAR) | ||||
| #	define canon_fspath(path,canon,flags) qse_canonmbspath(path,canon,flags) | ||||
| #	define get_fspath_core(fspath) qse_getmbspathcore(fspath) | ||||
| #	define IS_FSPATHSEP(x) QSE_ISPATHMBSEP(x) | ||||
| #	define QSE_FS_T(x) QSE_MT(x) | ||||
| #else | ||||
| #	define canon_fspath(fspath,canon,flags) qse_canonwcspath(fspath,canon,flags) | ||||
| #	define get_fspath_core(fspath) qse_getwcspathcore(fspath) | ||||
| #	define IS_FSPATHSEP(x) QSE_ISPATHWCSEP(x) | ||||
| #	define QSE_FS_T(x) QSE_WT(x) | ||||
| #endif | ||||
|  | ||||
| #if defined(__cplusplus) | ||||
| extern "C" { | ||||
| #endif | ||||
| @ -95,6 +108,16 @@ qse_fs_char_t* qse_fs_makefspathforwcs ( | ||||
| 	const qse_wchar_t* path | ||||
| ); | ||||
|  | ||||
| qse_fs_char_t* qse_fs_dupfspathformbs ( | ||||
| 	qse_fs_t*          fs, | ||||
| 	const qse_mchar_t* path | ||||
| ); | ||||
|  | ||||
| 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, | ||||
|  | ||||
| @ -26,6 +26,10 @@ | ||||
|  | ||||
| #include <qse/cmn/path.h> | ||||
|  | ||||
| /* TODO: support the \\?\ prefix and the \\.\ prefix on windows  | ||||
|  *       support \\?\UNC\server\path which is equivalent to \\server\path.  | ||||
|  * */ | ||||
|  | ||||
| /* ------------------------------------------------------------------ */ | ||||
| /*  MBS IMPLEMENTATION                                                */ | ||||
| /* ------------------------------------------------------------------ */ | ||||
| @ -40,6 +44,7 @@ | ||||
| 	  (s[0] >= QSE_MT('a') && s[0] <= QSE_MT('z'))) && \ | ||||
| 	 s[1] == QSE_MT(':')) | ||||
|  | ||||
|  | ||||
| int qse_ismbsabspath (const qse_mchar_t* path) | ||||
| { | ||||
| 	if (IS_MSEP(path[0])) return 1; | ||||
| @ -48,7 +53,7 @@ int qse_ismbsabspath (const qse_mchar_t* path) | ||||
| 	 * but the path within the drive is kind of relative */ | ||||
| 	if (IS_MDRIVE(path)) return 1; | ||||
| #endif | ||||
|      return 0; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int qse_ismbsdrivepath (const qse_mchar_t* path) | ||||
| @ -75,6 +80,25 @@ int qse_ismbsdrivecurpath (const qse_mchar_t* path) | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| 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 defined(_WIN32) | ||||
| 	else if (IS_MSEP(*ptr) && IS_MSEP(*(ptr + 1)) && !IS_MSEP_OR_MNIL(*(ptr + 2))) | ||||
| 	{ | ||||
| 		/* UNC Path */ | ||||
| 		ptr += 2; | ||||
| 		do { ptr++; } while (!IS_MSEP_OR_MNIL(*ptr)); | ||||
| 		if (IS_MSEP(*ptr)) return ptr; | ||||
| 	} | ||||
| 	#endif | ||||
| /* TOOD: \\server\XXX \\.\XXX \\?\XXX \\?\UNC\server\XXX */ | ||||
| 	 | ||||
| #endif | ||||
| 	return path; | ||||
| } | ||||
|  | ||||
| qse_size_t qse_canonmbspath (const qse_mchar_t* path, qse_mchar_t* canon, int flags) | ||||
| { | ||||
| 	const qse_mchar_t* ptr; | ||||
| @ -390,6 +414,23 @@ int qse_iswcsdrivecurpath (const qse_wchar_t* path) | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| 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 defined(_WIN32) | ||||
| 	else if (IS_WSEP(*ptr) && IS_WSEP(*(ptr + 1)) && !IS_WSEP_OR_WNIL(*(ptr + 2))) | ||||
| 	{ | ||||
| 		/* UNC Path */ | ||||
| 		ptr += 2; | ||||
| 		do { ptr++; } while (!IS_WSEP_OR_WNIL(*ptr)); | ||||
| 		if (IS_WSEP(*ptr)) return ptr; | ||||
| 	} | ||||
| 	#endif | ||||
| #endif | ||||
| 	return path; | ||||
| } | ||||
|  | ||||
| qse_size_t qse_canonwcspath (const qse_wchar_t* path, qse_wchar_t* canon, int flags) | ||||
| { | ||||
| 	const qse_wchar_t* ptr; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user