added glob handling to qse_fs_cpfile()
This commit is contained in:
		| @ -46,7 +46,7 @@ struct cpfile_t | ||||
| typedef struct cpfile_t cpfile_t; | ||||
|  | ||||
|  | ||||
| static int merge_dstdir_and_file (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| static int merge_dstdir_and_srcbase (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| { | ||||
| 	qse_fs_char_t* fstmp; | ||||
|  | ||||
| @ -65,8 +65,7 @@ static int merge_dstdir_and_file (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| 	qse_fs_freefspath (fs, QSE_NULL, cpfile->dst_fspath); | ||||
| 	cpfile->dst_fspath = fstmp; | ||||
|  | ||||
| /* TODO: check on the flags to getattrsys()... */ | ||||
| 	if (qse_fs_getattrsys (fs, cpfile->dst_fspath, &cpfile->dst_attr, 0) <= -1)  | ||||
| 	if (qse_fs_getattrsys (fs, cpfile->dst_fspath, &cpfile->dst_attr, QSE_FS_GETATTR_SYMLINK) <= -1)  | ||||
| 	{ | ||||
| 		/* attribute on the new destination is not available */ | ||||
| 		cpfile->flags &= ~CPFILE_DST_ATTR; | ||||
| @ -77,6 +76,7 @@ static int merge_dstdir_and_file (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| 		cpfile->flags |= CPFILE_DST_ATTR; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	cpfile->flags |= CPFILE_DST_FSPATH_MERGED; | ||||
| 	return 0; | ||||
| } | ||||
| @ -168,8 +168,12 @@ static int copy_file_in_fs (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| 	/* ------------------------------------------------------ */ | ||||
|  | ||||
| #else | ||||
| 	 | ||||
|  | ||||
| 	if ((cpfile->flags & QSE_FS_CPFILE_SYMLINK) && cpfile->src_attr.islnk) | ||||
| 	{ | ||||
| 		/* the source file is a symbolic link and the SYMLINK option is on.*/ | ||||
|  | ||||
| 		qse_fs_char_t* tmpbuf; | ||||
|  | ||||
| 		/* TODO: use a static buffer is size is small enough */ | ||||
| @ -179,29 +183,67 @@ static int copy_file_in_fs (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| 			fs->errnum = QSE_FS_ENOMEM; | ||||
| 			return -1; | ||||
| 		} | ||||
| 		QSE_MEMSET (tmpbuf, 0, QSE_SIZEOF(*tmpbuf) * (cpfile->src_attr.size + 1)); | ||||
|  | ||||
| 		if (QSE_READLINK (cpfile->src_fspath, tmpbuf, cpfile->src_attr.size) <= -1 || | ||||
| 		    QSE_SYMLINK (tmpbuf, cpfile->dst_fspath) <= -1) | ||||
| 		if (QSE_READLINK (cpfile->src_fspath, tmpbuf, cpfile->src_attr.size) <= -1) | ||||
| 		{ | ||||
| 			QSE_MMGR_FREE (fs->mmgr, tmpbuf); | ||||
| 			fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 			QSE_MMGR_FREE (fs->mmgr, tmpbuf); | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		if (QSE_SYMLINK (tmpbuf, cpfile->dst_fspath) <= -1) | ||||
| 		{ | ||||
| 			if (cpfile->flags & QSE_FS_CPFILE_FORCE) | ||||
| 			{ | ||||
| 				QSE_UNLINK (cpfile->dst_fspath); | ||||
| 				if (QSE_SYMLINK (tmpbuf, cpfile->dst_fspath) <= -1) | ||||
| 				{ | ||||
| 					fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 					goto oops_1; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (fs->cbs.cp) | ||||
| 		{ | ||||
| 			qse_char_t* srcpath = QSE_NULL, * dstpath = QSE_NULL; | ||||
| 			int x = 1; | ||||
|  | ||||
| 			srcpath = (qse_char_t*)make_str_with_fspath (fs, cpfile->src_fspath); | ||||
| 			dstpath = (qse_char_t*)make_str_with_fspath (fs, cpfile->dst_fspath); | ||||
|  | ||||
| 			if (srcpath && dstpath) | ||||
| 			{ | ||||
| 				x = fs->cbs.cp (fs, srcpath, dstpath, cpfile->src_attr.size, cpfile->src_attr.size); | ||||
| 			} | ||||
|  | ||||
| 			if (srcpath) free_str_with_fspath (fs, cpfile->src_fspath, srcpath); | ||||
| 			if (dstpath) free_str_with_fspath (fs, cpfile->dst_fspath, dstpath); | ||||
|  | ||||
| 			if (x <= -1) goto oops_1; | ||||
| 		} | ||||
|  | ||||
| 		QSE_MMGR_FREE (fs->mmgr, tmpbuf); | ||||
| 		return 0; | ||||
|  | ||||
| 	oops_1: | ||||
| 		if (tmpbuf) QSE_MMGR_FREE (fs->mmgr, tmpbuf); | ||||
| 		return -1; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		int in = -1, out = -1; | ||||
| 		qse_ssize_t in_len, out_len; | ||||
| 		qse_uint8_t* bp; | ||||
| 		qse_uintmax_t bytes_copied = 0; | ||||
| 		qse_char_t* srcpath = QSE_NULL, * dstpath = QSE_NULL; | ||||
|  | ||||
| 		in = QSE_OPEN (cpfile->src_fspath, O_RDONLY, 0); | ||||
| 		if (in <= -1) | ||||
| 		{ | ||||
| 			fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 			goto oops; | ||||
| 			goto oops_2; | ||||
| 		} | ||||
|  | ||||
| 		out = QSE_OPEN (cpfile->dst_fspath, O_CREAT | O_WRONLY | O_TRUNC, cpfile->src_attr.mode); | ||||
| @ -211,112 +253,73 @@ static int copy_file_in_fs (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| 			QSE_UNLINK (cpfile->dst_fspath); | ||||
| 			out = QSE_OPEN (cpfile->dst_fspath, O_CREAT | O_WRONLY | O_TRUNC, cpfile->src_attr.mode);  | ||||
| 		} | ||||
|  | ||||
| 		if (out <= -1) | ||||
| 		{ | ||||
| 			fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 			goto oops; | ||||
| 			goto oops_2; | ||||
| 		} | ||||
|  | ||||
| 		if (fs->cbs.cp) | ||||
| 		{ | ||||
| 			srcpath = (qse_char_t*)make_str_with_fspath (fs, cpfile->src_fspath); | ||||
| 			dstpath = (qse_char_t*)make_str_with_fspath (fs, cpfile->dst_fspath); | ||||
| 		} | ||||
|  | ||||
| 		while (1) | ||||
| 		{ | ||||
| /* TODO: use vmspliace() and family for faster copying... */ | ||||
| 			in_len = QSE_READ (in, fs->cpbuf, QSE_SIZEOF(fs->cpbuf)); | ||||
| 			if (in_len <= 0) break; | ||||
|  | ||||
| 	/* TODO: call progress callback */ | ||||
| 			if (in_len <= 0)  | ||||
| 			{ | ||||
| 				if (bytes_copied == 0 && srcpath && dstpath) | ||||
| 				{ | ||||
| 					if (fs->cbs.cp (fs, srcpath, dstpath, cpfile->src_attr.size, bytes_copied) <= -1) goto oops_2; | ||||
| 				} | ||||
| 				break; | ||||
| 			} | ||||
|  | ||||
| 			bp = fs->cpbuf; | ||||
| 			while (in_len > 0) | ||||
| 			{ | ||||
| 				out_len = QSE_WRITE (out, bp, in_len); | ||||
| 				if (out_len <= -1) goto oops; | ||||
| 				if (out_len <= -1) goto oops_2; | ||||
| 				bp += out_len; | ||||
| 				in_len -= out_len; | ||||
| 				bytes_copied += out_len; | ||||
| 			} | ||||
|  | ||||
| 			if (srcpath && dstpath) | ||||
| 			{ | ||||
| 				if (fs->cbs.cp (fs, srcpath, dstpath, cpfile->src_attr.size, bytes_copied) <= -1) goto oops_2; | ||||
| /* TODO: skip, ignore, etc... */ | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (cpfile->flags & QSE_FS_CPFILE_PRESERVE) | ||||
| 		{ | ||||
| 		#if defined(HAVE_FUTIMENS) && defined(HAVE_STRUCT_TIMESPEC) | ||||
| 			struct timespec ts[2]; | ||||
| 		#elif defined(HAVE_FUTIMES) | ||||
| 			struct timeval tv[2]; | ||||
| 		#elif defined(HAVE_UTIME) | ||||
| 			struct utimbuf ub; | ||||
| 		#elif defined(HAVE_UTIMES) | ||||
| 			struct timeval tv[2]; | ||||
| 		#endif | ||||
|  | ||||
| 			if (QSE_FCHOWN (out, cpfile->src_attr.uid, cpfile->src_attr.gid) <= -1 || | ||||
| 			    QSE_FCHMOD (out, cpfile->src_attr.mode) <= -1) | ||||
| 			if (qse_fs_setattronfd (fs, out, &cpfile->src_attr, QSE_FS_SETATTR_TIME | QSE_FS_SETATTR_OWNER | QSE_FS_SETATTR_MODE) <= -1) | ||||
| 			{ | ||||
| 				fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 				goto oops; | ||||
| 				if (fs->errnum == QSE_FS_ENOIMPL) | ||||
| 				{ | ||||
| 					if (qse_fs_setattrsys (fs, cpfile->dst_fspath, &cpfile->src_attr, QSE_FS_SETATTR_TIME | QSE_FS_SETATTR_OWNER | QSE_FS_SETATTR_MODE) <= -1) goto oops_2; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 		#if defined(HAVE_FUTIMENS) && defined(HAVE_STRUCT_TIMESPEC) | ||||
|  | ||||
| 			QSE_MEMSET (&ts, 0, QSE_SIZEOF(ts)); | ||||
| 			ts[0].tv_sec = cpfile->src_attr.atime.sec; | ||||
| 			ts[0].tv_nsec = cpfile->src_attr.atime.nsec; | ||||
| 			ts[1].tv_sec = cpfile->src_attr.mtime.sec; | ||||
| 			ts[1].tv_nsec = cpfile->src_attr.mtime.nsec; | ||||
| 			if (QSE_FUTIMENS (out, ts) <= -1) | ||||
| 			{ | ||||
| 				fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 		#elif defined(HAVE_FUTIMES) | ||||
|  | ||||
| 			QSE_MEMSET (&tv, 0, QSE_SIZEOF(tv)); | ||||
| 			tv[0].tv_sec = cpfile->src_attr.atime.sec; | ||||
| 			tv[0].tv_usec = QSE_NSEC_TO_USEC(cpfile->src_attr.atime.nsec); | ||||
| 			tv[1].tv_sec = cpfile->src_attr.mtime.sec; | ||||
| 			tv[1].tv_usec = QSE_NSEC_TO_USEC(cpfile->src_attr.mtime.nsec); | ||||
| 			if (QSE_FUTIMES (out, tv) <= -1) | ||||
| 			{ | ||||
| 				fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 		#elif defined(HAVE_UTIMES) | ||||
|  | ||||
| 			QSE_MEMSET (&tv, 0, QSE_SIZEOF(tv)); | ||||
| 			tv[0].tv_sec = cpfile->src_attr.atime.sec; | ||||
| 			tv[0].tv_usec = QSE_NSEC_TO_USEC(cpfile->src_attr.atime.nsec); | ||||
| 			tv[1].tv_sec = cpfile->src_attr.mtime.sec; | ||||
| 			tv[1].tv_usec = QSE_NSEC_TO_USEC(cpfile->src_attr.mtime.nsec); | ||||
| 			// work on the file name not on the file descriptor. | ||||
| 			if (QSE_UTIMES (cpfile->dst_fspath, tv) <= -1) | ||||
| 			{ | ||||
| 				fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 		#elif defined(HAVE_UTIME) | ||||
|  | ||||
| 			QSE_MEMSET (&ub, 0, QSE_SIZEOF(ub)); | ||||
| 			ub.actime = cpfile->src_attr.atime.sec; | ||||
| 			ub.modtime = cpfile->src_attr.mtime.sec; | ||||
| 			if (QSE_UTIME (cpfile->dst_fspath, &ub) <= -1) | ||||
| 			{ | ||||
| 				fs->errnum = qse_fs_syserrtoerrnum (fs, errno); | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 		#else | ||||
| 		#	error none of futimens, futimes, utime, utimes exist | ||||
| 		#endif | ||||
| 		} | ||||
|  | ||||
| 		QSE_CLOSE (out); | ||||
| 		QSE_CLOSE (in); | ||||
|  | ||||
| 		if (srcpath) free_str_with_fspath (fs, cpfile->src_fspath, srcpath); | ||||
| 		if (dstpath) free_str_with_fspath (fs, cpfile->dst_fspath, dstpath); | ||||
| 		return 0; | ||||
|  | ||||
| 	oops: | ||||
| 	oops_2: | ||||
| 		if (out >= 0) QSE_CLOSE (out); | ||||
| 		if (in >= 0) QSE_CLOSE (in); | ||||
|  | ||||
| 		if (srcpath) free_str_with_fspath (fs, cpfile->src_fspath, srcpath); | ||||
| 		if (dstpath) free_str_with_fspath (fs, cpfile->dst_fspath, dstpath); | ||||
| 		return -1; | ||||
| 	} | ||||
| #endif | ||||
| @ -326,9 +329,9 @@ static int prepare_cpfile (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| { | ||||
| 	/* error if the source file can't be stat'ed. | ||||
| 	 * ok if the destination file can't be stat'ed */ | ||||
| /* TODO: check on flags to getattrsys() */ | ||||
| 	if (qse_fs_getattrsys (fs, cpfile->src_fspath, &cpfile->src_attr, 0) <= -1) return -1; | ||||
| 	if (qse_fs_getattrsys (fs, cpfile->dst_fspath, &cpfile->dst_attr, 0) >= 0) cpfile->flags |= CPFILE_DST_ATTR; | ||||
| /* TODO: check if flags to getattrsys() is correct */ | ||||
| 	if (qse_fs_getattrsys (fs, cpfile->src_fspath, &cpfile->src_attr, QSE_FS_GETATTR_SYMLINK) <= -1) return -1; | ||||
| 	if (qse_fs_getattrsys (fs, cpfile->dst_fspath, &cpfile->dst_attr, QSE_FS_GETATTR_SYMLINK) >= 0) cpfile->flags |= CPFILE_DST_ATTR; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| @ -399,7 +402,7 @@ static int copy_file (qse_fs_t* fs, cpfile_t* cpfile) | ||||
| #else | ||||
| 	cpfile_t sub_cpfile; | ||||
| #endif | ||||
| 	qse_dir_t* dir; | ||||
| 	qse_dir_t* dir = QSE_NULL; | ||||
| 	qse_dir_errnum_t direrr; | ||||
| 	qse_dir_ent_t dirent; | ||||
| 	int x; | ||||
| @ -408,7 +411,6 @@ start_over: | ||||
| 	if (cpfile->src_attr.isdir) | ||||
| 	{ | ||||
| 		/* source is a directory */ | ||||
| 	copy_dir: | ||||
| 		if (cpfile->flags & CPFILE_DST_ATTR) | ||||
| 		{ | ||||
| 			if (!cpfile->dst_attr.isdir) | ||||
| @ -418,24 +420,17 @@ start_over: | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 			if (!(cpfile->flags & QSE_FS_CPFILE_NOTGTDIR) &&  | ||||
| 			    cpfile->dst_attr.isdir) | ||||
| 			/* the destination is also a directory */ | ||||
| 			if (cpfile->src_attr.ino == cpfile->dst_attr.ino && | ||||
| 			    cpfile->src_attr.dev == cpfile->dst_attr.dev) | ||||
| 			{ | ||||
| 				if (cpfile->flags & CPFILE_DST_FSPATH_MERGED) | ||||
| 				{ | ||||
| 					/* merge_dstdir_and_file() has been called already. | ||||
| 					 * no more getting into a subdirectory */ | ||||
| 					fs->errnum = QSE_FS_EISDIR; | ||||
| 					goto oops; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					/* arrange to copy a file into a directory */ | ||||
| 					if (merge_dstdir_and_file (fs, cpfile) <= -1) return -1; | ||||
| 					goto copy_dir; | ||||
| 				} | ||||
| 				/* cannot copy a directory to itself */ | ||||
| 				fs->errnum = QSE_FS_EINVAL; /* TODO: better error code */ | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 			if (merge_dstdir_and_srcbase (fs, cpfile) <= -1) goto oops; | ||||
|  | ||||
| 			/* | ||||
| 			if (!(cpfile->flags & QSE_FS_CPFILE_REPLACE)) | ||||
| 			{ | ||||
| @ -466,7 +461,11 @@ start_over: | ||||
| 			goto oops; | ||||
| 		} | ||||
|  | ||||
| 		if (qse_fs_sysmkdir (fs, cpfile->dst_fspath) <= -1) goto oops; | ||||
| 		if (qse_fs_mkdirsys (fs, cpfile->dst_fspath) <= -1)  | ||||
| 		{ | ||||
| 			/* it's ok if the destination directory already exists */ | ||||
| 			if (fs->errnum != QSE_FS_EEXIST) goto oops; | ||||
| 		} | ||||
|  | ||||
| 		while (1) | ||||
| 		{ | ||||
| @ -508,17 +507,12 @@ start_over: | ||||
| 			if (!sub_cpfile.src_fspath  || !sub_cpfile.dst_fspath || prepare_cpfile (fs, &sub_cpfile) <= -1) | ||||
| 			{ | ||||
| 				clear_cpfile (fs, &sub_cpfile); | ||||
| 				qse_dir_close (dir); | ||||
| 				return -1; | ||||
| 				goto oops; | ||||
| 			} | ||||
| 			x = copy_file (fs, &sub_cpfile); /* TODO: remove recursion */ | ||||
|  | ||||
| 			clear_cpfile (fs, &sub_cpfile); | ||||
| 			if (x <= -1) | ||||
| 			{ | ||||
| 				qse_dir_close (dir); | ||||
| 				return -1; | ||||
| 			} | ||||
| 			if (x <= -1) goto oops; | ||||
| 		#endif | ||||
| 		} | ||||
|  | ||||
| @ -532,6 +526,8 @@ start_over: | ||||
| 	copy_file: | ||||
| 		if (cpfile->flags & CPFILE_DST_ATTR)  | ||||
| 		{ | ||||
| 			/* attribute of the destination path is available */ | ||||
|  | ||||
| 			if (cpfile->src_attr.ino == cpfile->dst_attr.ino &&  | ||||
| 			    cpfile->src_attr.dev == cpfile->dst_attr.dev) | ||||
| 			{ | ||||
| @ -540,9 +536,9 @@ start_over: | ||||
| 				goto oops; | ||||
| 			} | ||||
|  | ||||
| 			if (!(cpfile->flags & QSE_FS_CPFILE_NOTGTDIR) &&  | ||||
| 			    cpfile->dst_attr.isdir) | ||||
| 			if (cpfile->dst_attr.isdir) | ||||
| 			{ | ||||
| #if 0 | ||||
| 				if (cpfile->flags & CPFILE_DST_FSPATH_MERGED) | ||||
| 				{ | ||||
| 					/* merge_dstdir_and_file() has been called already. | ||||
| @ -552,16 +548,19 @@ start_over: | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| #endif | ||||
| 					/* arrange to copy a file into a directory */ | ||||
| 					if (merge_dstdir_and_file (fs, cpfile) <= -1) return -1; | ||||
| 					if (merge_dstdir_and_srcbase (fs, cpfile) <= -1) return -1; | ||||
| 					goto copy_file; | ||||
| #if 0 | ||||
| 				} | ||||
| #endif | ||||
| 			} | ||||
|  | ||||
| 			if (!(cpfile->flags & QSE_FS_CPFILE_REPLACE)) | ||||
| 			{ | ||||
| 				fs->errnum = QSE_FS_EEXIST; | ||||
| 				return -1; | ||||
| 				goto oops; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| @ -580,7 +579,6 @@ start_over: | ||||
|  | ||||
| 	return 0; | ||||
|  | ||||
|  | ||||
| oops: | ||||
| #if defined(NO_RECURSION) | ||||
| 	while (fs->cfs) pop_cfs (fs, QSE_NULL, QSE_NULL); | ||||
| @ -589,243 +587,104 @@ oops: | ||||
| 	return -1; | ||||
| } | ||||
|  | ||||
| int qse_fs_cpfilembs (qse_fs_t* fs, const qse_mchar_t* srcpath, const qse_mchar_t* dstpath, int flags) | ||||
| /* ========================================================================= */ | ||||
|  | ||||
| struct glob_ctx_t | ||||
| { | ||||
| 	qse_fs_t* fs; | ||||
| 	int flags; | ||||
| 	void* dstpath; | ||||
| 	int wcs; | ||||
| }; | ||||
| typedef struct glob_ctx_t glob_ctx_t; | ||||
|  | ||||
| static int copy_file_for_glob (const void* path, void* ctx) | ||||
| { | ||||
| 	glob_ctx_t* gc = (glob_ctx_t*)ctx; | ||||
| 	cpfile_t cpfile; | ||||
| 	int ret; | ||||
|  | ||||
| 	QSE_MEMSET (&cpfile, 0, QSE_SIZEOF(cpfile)); | ||||
|  | ||||
| 	cpfile.flags = flags & QSE_FS_CPFILE_ALL; /* keep public flags only */ | ||||
| 	cpfile.flags = gc->flags & QSE_FS_CPFILE_ALL; /* keep public flags only */ | ||||
|  | ||||
| 	cpfile.src_fspath = (qse_fs_char_t*)qse_fs_dupfspathformbs (fs, srcpath); | ||||
| 	cpfile.dst_fspath = (qse_fs_char_t*)qse_fs_dupfspathformbs (fs, dstpath); | ||||
| 	if (!cpfile.src_fspath || !cpfile.dst_fspath || prepare_cpfile (fs, &cpfile) <= -1) goto oops; | ||||
| 	if (gc->wcs) | ||||
| 	{ | ||||
| 		cpfile.src_fspath = (qse_fs_char_t*)qse_fs_dupfspathforwcs (gc->fs, ((qse_wcstr_t*)path)->ptr); | ||||
| 		cpfile.dst_fspath = (qse_fs_char_t*)qse_fs_dupfspathforwcs (gc->fs, gc->dstpath); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		cpfile.src_fspath = (qse_fs_char_t*)qse_fs_dupfspathformbs (gc->fs, ((qse_mcstr_t*)path)->ptr); | ||||
| 		cpfile.dst_fspath = (qse_fs_char_t*)qse_fs_dupfspathformbs (gc->fs, gc->dstpath); | ||||
| 	} | ||||
| 	if (!cpfile.src_fspath || !cpfile.dst_fspath || prepare_cpfile (gc->fs, &cpfile) <= -1) goto oops; | ||||
|  | ||||
| 	ret = copy_file (fs, &cpfile); | ||||
| 	ret = copy_file (gc->fs, &cpfile); | ||||
|  | ||||
| 	clear_cpfile (gc->fs, &cpfile); | ||||
|  | ||||
| 	clear_cpfile (fs, &cpfile); | ||||
| 	return ret; | ||||
|  | ||||
| oops: | ||||
| 	clear_cpfile (fs, &cpfile); | ||||
| 	clear_cpfile (gc->fs, &cpfile); | ||||
| 	return -1; | ||||
| } | ||||
|  | ||||
| int qse_fs_cpfilembs (qse_fs_t* fs, const qse_mchar_t* srcpath, const qse_mchar_t* dstpath, int flags) | ||||
| { | ||||
| 	glob_ctx_t ctx; | ||||
|  | ||||
| 	ctx.fs = fs; | ||||
| 	ctx.flags = flags; | ||||
| 	ctx.dstpath = (void*)dstpath; | ||||
| 	ctx.wcs = 0; | ||||
|  | ||||
| 	if (flags & QSE_FS_CPFILE_GLOB) | ||||
| 	{ | ||||
| 		if (qse_globmbs (srcpath, copy_file_for_glob, &ctx, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr) <= -1) | ||||
| 		{ | ||||
| 			fs->errnum = QSE_FS_EGLOB; | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		return 0; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		qse_mcstr_t s; | ||||
| 		s.ptr = (qse_mchar_t*)srcpath; | ||||
| 		s.len = 0; /* not important */ | ||||
| 		/* let me use the glob callback function for simplicity */ | ||||
| 		return copy_file_for_glob (&s, &ctx); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int qse_fs_cpfilewcs (qse_fs_t* fs, const qse_wchar_t* srcpath, const qse_wchar_t* dstpath, int flags) | ||||
| { | ||||
| 	cpfile_t cpfile; | ||||
| 	int ret; | ||||
| 	glob_ctx_t ctx; | ||||
|  | ||||
| 	QSE_MEMSET (&cpfile, 0, QSE_SIZEOF(cpfile)); | ||||
| 	ctx.fs = fs; | ||||
| 	ctx.flags = flags; | ||||
| 	ctx.dstpath = (void*)dstpath; | ||||
| 	ctx.wcs = 1; | ||||
|  | ||||
| 	cpfile.flags = flags & QSE_FS_CPFILE_ALL; /* keep public flags only */ | ||||
|  | ||||
| 	cpfile.src_fspath = (qse_fs_char_t*)qse_fs_dupfspathforwcs (fs, srcpath); | ||||
| 	cpfile.dst_fspath = (qse_fs_char_t*)qse_fs_dupfspathforwcs (fs, dstpath); | ||||
| 	if (!cpfile.src_fspath || !cpfile.dst_fspath || prepare_cpfile (fs, &cpfile) <= -1) goto oops; | ||||
|  | ||||
| 	ret = copy_file (fs, &cpfile); | ||||
|  | ||||
| 	clear_cpfile (fs, &cpfile); | ||||
| 	return ret; | ||||
|  | ||||
| oops: | ||||
| 	clear_cpfile (fs, &cpfile); | ||||
| 	return -1; | ||||
| } | ||||
|  | ||||
|  | ||||
| #if 0 | ||||
| /* --------------------------------------------------------------------- */ | ||||
| /* | ||||
|  * Copyright (c) 1983 Regents of the University of California. | ||||
|  * All rights reserved.  The Berkeley software License Agreement | ||||
|  * specifies the terms and conditions for redistribution. | ||||
|  */ | ||||
|  | ||||
| static int copy (const char* from, const char* to) | ||||
| { | ||||
| 	int fold, fnew, n, exists; | ||||
| 	char *last, destname[MAXPATHLEN + 1], buf[MAXBSIZE]; | ||||
| 	struct stat stfrom, stto; | ||||
|  | ||||
| 	fold = open (from, O_RDONLY); | ||||
| 	if (fold < 0)  | ||||
| 	if (flags & QSE_FS_CPFILE_GLOB) | ||||
| 	{ | ||||
| 		return -1; | ||||
| 	} | ||||
| 		if (qse_globwcs (srcpath, copy_file_for_glob, &ctx, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr) <= -1) | ||||
| 		{ | ||||
| 			fs->errnum = QSE_FS_EGLOB; | ||||
| 			return -1; | ||||
| 		}  | ||||
|  | ||||
| 	if (fstat(fold, &stfrom) < 0) | ||||
| 		return 0; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		close(fold); | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	if (stat(to, &stto) >= 0 && (stto.st_mode&S_IFMT) == S_IFDIR)  | ||||
| 	{ | ||||
| 		last = rindex(from, '/'); | ||||
| 		if (last) last++; else last = from; | ||||
|  | ||||
| 		if (strlen(to) + strlen(last) >= sizeof(destname) - 1)  | ||||
| 		{ | ||||
| 			/* name too long */ | ||||
| 			close(fold); | ||||
| 			return(1); | ||||
| 		} | ||||
|  | ||||
| 		(void) sprintf(destname, "%s/%s", to, last); | ||||
| 		to = destname; | ||||
| 	} | ||||
|  | ||||
| 	if (rflag && (stfrom.st_mode&S_IFMT) == S_IFDIR)  | ||||
| 	{ | ||||
| 		int fixmode = 0;    /* cleanup mode after rcopy */ | ||||
|  | ||||
| 		close(fold); | ||||
| 		if (stat(to, &stto) < 0) | ||||
| 		{ | ||||
| 			if (mkdir(to, (stfrom.st_mode & 07777) | 0700) < 0) | ||||
| 			{ | ||||
| 				Perror(to); | ||||
| 				return (1); | ||||
| 			} | ||||
| 			fixmode = 1; | ||||
| 		} | ||||
| 		else if ((stto.st_mode&S_IFMT) != S_IFDIR) | ||||
| 		{ | ||||
| 		  fprintf(stderr, "cp: %s: Not a directory.\n", to); | ||||
| 		  return (1); | ||||
| 		} | ||||
| 		else if (pflag) | ||||
| 		{ | ||||
| 		  fixmode = 1; | ||||
| 		} | ||||
|  | ||||
| 		n = rcopy(from, to); | ||||
| 		if (fixmode) chmod(to, stfrom.st_mode & 07777); | ||||
| 		return (n); | ||||
| 	} | ||||
|  | ||||
| 	if ((stfrom.st_mode&S_IFMT) == S_IFDIR) | ||||
| 	   fprintf(stderr, | ||||
| 		  "cp: %s: Is a directory (copying as plain file).\n", | ||||
| 			 from); | ||||
|  | ||||
| 	exists = stat(to, &stto) == 0; | ||||
| 	if (exists)  | ||||
| 	{ | ||||
| 		if (stfrom.st_dev == stto.st_dev && stfrom.st_ino == stto.st_ino) | ||||
| 		{ | ||||
| 			fprintf(stderr, | ||||
| 			 "cp: %s and %s are identical (not copied).\n", from, to); | ||||
| 			close(fold); | ||||
| 			return (1); | ||||
| 		} | ||||
| 		if (iflag && isatty(fileno(stdin))) | ||||
| 		{ | ||||
| 			int i, c; | ||||
|  | ||||
| 			fprintf (stderr, "overwrite %s? ", to); | ||||
| 			i = c = getchar(); | ||||
|  | ||||
| 			while (c != '\n' && c != EOF) | ||||
| 			c = getchar(); | ||||
| 			if (i != 'y') | ||||
| 			{ | ||||
| 				close(fold); | ||||
| 				return(1); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	fnew = creat(to, stfrom.st_mode & 07777); | ||||
| 	if (fnew < 0) | ||||
| 	{ | ||||
| 		Perror(to); | ||||
| 		(void) close(fold); | ||||
| 		return(1); | ||||
| 	} | ||||
|  | ||||
| 	if (exists && pflag) | ||||
| 		fchmod(fnew, stfrom.st_mode & 07777); | ||||
|  | ||||
| 	for (;;) | ||||
| 	{ | ||||
| 		/* use vmsplice() to copy??? */ | ||||
| 		n = read(fold, buf, sizeof buf); | ||||
| 		if (n == 0) break; | ||||
|  | ||||
| 		if (n < 0)  | ||||
| 		{ | ||||
| 			Perror(from); | ||||
| 			close(fold); | ||||
| 			close(fnew); | ||||
| 			return (1); | ||||
| 		} | ||||
| 		if (write(fnew, buf, n) != n) | ||||
| 		{ | ||||
| 			Perror(to); | ||||
| 			close(fold); | ||||
| 			close(fnew); | ||||
| 			return (1); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	close(fold); | ||||
| 	close(fnew); | ||||
| 	if (pflag) return (setimes(to, &stfrom)); | ||||
| 	return (0); | ||||
| } | ||||
|  | ||||
| int rcopy(const char* from, const char* to) | ||||
| { | ||||
| 	DIR *fold = opendir(from); | ||||
| 	struct direct *dp; | ||||
| 	struct stat statb; | ||||
| 	int errs = 0; | ||||
| 	char fromname[MAXPATHLEN + 1]; | ||||
|  | ||||
| 	if (fold == 0 || (pflag && fstat(fold->dd_fd, &statb) < 0)) { | ||||
| 		Perror(from); | ||||
| 		return (1); | ||||
| 	} | ||||
| 	for (;;)  | ||||
| 	{ | ||||
| 		dp = readdir(fold); | ||||
| 		if (dp == 0)  | ||||
| 		{ | ||||
| 			closedir(fold); | ||||
| 			if (pflag) return (setimes(to, &statb) + errs); | ||||
| 			return (errs); | ||||
| 		} | ||||
| 		if (dp->d_ino == 0) continue; | ||||
| 		if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; | ||||
| 		if (strlen(from)+1+strlen(dp->d_name) >= sizeof fromname - 1) | ||||
| 		{ | ||||
| 			fprintf(stderr, "cp: %s/%s: Name too long.\n", from, dp->d_name); | ||||
| 			errs++; | ||||
| 			continue; | ||||
| 		} | ||||
|  | ||||
| 		sprintf(fromname, "%s/%s", from, dp->d_name); | ||||
| 		errs += copy(fromname, to); | ||||
| 		/* let me use the glob callback function for simplicity */ | ||||
| 		qse_wcstr_t s; | ||||
| 		s.ptr = (qse_wchar_t*)srcpath; | ||||
| 		s.len = 0; /* not important */ | ||||
| 		return copy_file_for_glob (&s, &ctx); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| static int setimes(const char* path, const struct stat* statp) | ||||
| { | ||||
| 	struct timeval tv[2]; | ||||
|  | ||||
| 	tv[0].tv_sec = statp->st_atime; | ||||
| 	tv[1].tv_sec = statp->st_mtime; | ||||
| 	tv[0].tv_usec = tv[1].tv_usec = 0; | ||||
| 	if (utimes(path, tv) < 0)  | ||||
| 	{ | ||||
| 		Perror(path); | ||||
| 		return (1); | ||||
| 	} | ||||
| 	return (0); | ||||
| } | ||||
|  | ||||
| #endif | ||||
|  | ||||
| @ -31,7 +31,7 @@ | ||||
|  * qse_dir_xxx() and qse_glob()  don't support mbs and wcs separately. | ||||
|  * while the functions here support them. */ | ||||
|  | ||||
| int qse_fs_sysrmfile (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| int qse_fs_rmfilesys (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| { | ||||
|  | ||||
| #if defined(_WIN32) | ||||
| @ -74,7 +74,7 @@ int qse_fs_sysrmfile (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int qse_fs_sysrmdir (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| int qse_fs_rmdirsys (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| { | ||||
| #if defined(_WIN32) | ||||
|  | ||||
| @ -127,10 +127,10 @@ static int delete_file (qse_fs_t* fs, const qse_char_t* path, int purge) | ||||
| 	qse_fs_char_t* fspath; | ||||
| 	int ret; | ||||
|  | ||||
| 	if (fs->cbs.del)  | ||||
| 	if (fs->cbs.rm)  | ||||
| 	{ | ||||
| 		int x; | ||||
| 		x = fs->cbs.del (fs, path); | ||||
| 		x = fs->cbs.rm (fs, path); | ||||
| 		if (x <= -1) return -1; | ||||
| 		if (x == 0) return 0; /* skipped */ | ||||
| 	} | ||||
| @ -138,7 +138,7 @@ static int delete_file (qse_fs_t* fs, const qse_char_t* path, int purge) | ||||
| 	fspath = qse_fs_makefspath(fs, path); | ||||
| 	if (!fspath) return -1; | ||||
|  | ||||
| 	ret = qse_fs_sysrmfile (fs, fspath); | ||||
| 	ret = qse_fs_rmfilesys (fs, fspath); | ||||
| 	qse_fs_freefspath (fs, path, fspath); | ||||
|  | ||||
| 	if (ret <= -1 && purge)  | ||||
| @ -176,7 +176,7 @@ static int delete_directory_nocbs (qse_fs_t* fs, const qse_char_t* path) | ||||
| 	fspath = qse_fs_makefspath(fs, path); | ||||
| 	if (!fspath) return -1; | ||||
|  | ||||
| 	ret = qse_fs_sysrmdir (fs, fspath); | ||||
| 	ret = qse_fs_rmdirsys (fs, fspath); | ||||
| 	qse_fs_freefspath (fs, path, fspath); | ||||
|  | ||||
| 	return ret; | ||||
| @ -184,10 +184,10 @@ static int delete_directory_nocbs (qse_fs_t* fs, const qse_char_t* path) | ||||
|  | ||||
| static int delete_directory (qse_fs_t* fs, const qse_char_t* path) | ||||
| { | ||||
| 	if (fs->cbs.del)  | ||||
| 	if (fs->cbs.rm)  | ||||
| 	{ | ||||
| 		int x; | ||||
| 		x = fs->cbs.del (fs, path); | ||||
| 		x = fs->cbs.rm (fs, path); | ||||
| 		if (x <= -1) return -1; | ||||
| 		if (x == 0) return 0; /* skipped */ | ||||
| 	} | ||||
| @ -281,7 +281,7 @@ static int delete_from_fs_with_mbs (qse_fs_t* fs, const qse_mchar_t* path, int d | ||||
| 	fspath = qse_fs_makefspathformbs (fs, path); | ||||
| 	if (!fspath) return -1; | ||||
|  | ||||
| 	if (fs->cbs.del) | ||||
| 	if (fs->cbs.rm) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
| 		int x; | ||||
| @ -293,7 +293,7 @@ static int delete_from_fs_with_mbs (qse_fs_t* fs, const qse_mchar_t* path, int d | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		x = fs->cbs.del (fs, xpath); | ||||
| 		x = fs->cbs.rm (fs, xpath); | ||||
|  | ||||
| 		free_str_with_mbs (fs, path, xpath); | ||||
|  | ||||
| @ -301,8 +301,8 @@ static int delete_from_fs_with_mbs (qse_fs_t* fs, const qse_mchar_t* path, int d | ||||
| 		if (x == 0) return 0; /* skipped */ | ||||
| 	} | ||||
|  | ||||
| 	ret = dir? qse_fs_sysrmdir (fs, fspath):  | ||||
| 	           qse_fs_sysrmfile (fs, fspath); | ||||
| 	ret = dir? qse_fs_rmdirsys (fs, fspath):  | ||||
| 	           qse_fs_rmfilesys (fs, fspath); | ||||
|  | ||||
| 	qse_fs_freefspathformbs (fs, path, fspath); | ||||
|  | ||||
| @ -314,7 +314,7 @@ static int delete_from_fs_with_wcs (qse_fs_t* fs, const qse_wchar_t* path, int d | ||||
| 	qse_fs_char_t* fspath; | ||||
| 	int ret; | ||||
|  | ||||
| 	if (fs->cbs.del) | ||||
| 	if (fs->cbs.rm) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
| 		int x; | ||||
| @ -326,7 +326,7 @@ static int delete_from_fs_with_wcs (qse_fs_t* fs, const qse_wchar_t* path, int d | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		x = fs->cbs.del (fs, xpath); | ||||
| 		x = fs->cbs.rm (fs, xpath); | ||||
|  | ||||
| 		free_str_with_wcs (fs, path, xpath); | ||||
|  | ||||
| @ -337,8 +337,8 @@ static int delete_from_fs_with_wcs (qse_fs_t* fs, const qse_wchar_t* path, int d | ||||
| 	fspath = qse_fs_makefspathforwcs (fs, path); | ||||
| 	if (!fspath) return -1; | ||||
|  | ||||
| 	ret = dir? qse_fs_sysrmdir (fs, fspath):  | ||||
| 	           qse_fs_sysrmfile (fs, fspath); | ||||
| 	ret = dir? qse_fs_rmdirsys (fs, fspath):  | ||||
| 	           qse_fs_rmfilesys (fs, fspath); | ||||
|  | ||||
| 	qse_fs_freefspathforwcs (fs, path, fspath); | ||||
|  | ||||
| @ -367,11 +367,11 @@ static int purge_path_for_glob (const qse_cstr_t* path, void* ctx) | ||||
|  | ||||
| /* --------------------------------------------------------------------- */ | ||||
|  | ||||
| int qse_fs_delfilembs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| int qse_fs_rmfilembs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| { | ||||
| 	int ret; | ||||
|  | ||||
| 	if (flags & QSE_FS_DELFILEMBS_GLOB) | ||||
| 	if (flags & QSE_FS_RMFILEMBS_GLOB) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| @ -382,7 +382,7 @@ int qse_fs_delfilembs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		if (flags & QSE_FS_DELFILEMBS_RECURSIVE) | ||||
| 		if (flags & QSE_FS_RMFILEMBS_RECURSIVE) | ||||
| 		{ | ||||
| 			ret = qse_glob (xpath, purge_path_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr); | ||||
| 		} | ||||
| @ -399,11 +399,11 @@ int qse_fs_delfilembs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 			return -1; | ||||
| 		} | ||||
| 	} | ||||
| 	else if (flags & QSE_FS_DELFILEMBS_RECURSIVE) | ||||
| 	else if (flags & QSE_FS_RMFILEMBS_RECURSIVE) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_deldirmbs() */ | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_rmdirmbs() */ | ||||
| 		xpath = (qse_char_t*)make_str_with_mbs (fs, path); | ||||
| 		if (!xpath) | ||||
| 		{ | ||||
| @ -423,11 +423,11 @@ int qse_fs_delfilembs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| int qse_fs_delfilewcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| int qse_fs_rmfilewcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| { | ||||
| 	int ret; | ||||
|  | ||||
| 	if (flags & QSE_FS_DELFILEWCS_GLOB) | ||||
| 	if (flags & QSE_FS_RMFILEWCS_GLOB) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| @ -438,7 +438,7 @@ int qse_fs_delfilewcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		if (flags & QSE_FS_DELFILEWCS_RECURSIVE) | ||||
| 		if (flags & QSE_FS_RMFILEWCS_RECURSIVE) | ||||
| 		{ | ||||
| 			ret = qse_glob (xpath, purge_path_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr); | ||||
| 		} | ||||
| @ -455,11 +455,11 @@ int qse_fs_delfilewcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| 			return -1; | ||||
| 		} | ||||
| 	} | ||||
| 	else if (flags & QSE_FS_DELFILEWCS_RECURSIVE) | ||||
| 	else if (flags & QSE_FS_RMFILEWCS_RECURSIVE) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_deldirwcs() */ | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_rmdirwcs() */ | ||||
| 		xpath = (qse_char_t*)make_str_with_wcs (fs, path); | ||||
| 		if (!xpath) | ||||
| 		{ | ||||
| @ -482,11 +482,11 @@ int qse_fs_delfilewcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
|  | ||||
| /* --------------------------------------------------------------------- */ | ||||
|  | ||||
| int qse_fs_deldirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| int qse_fs_rmdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| { | ||||
| 	int ret; | ||||
|  | ||||
| 	if (flags & QSE_FS_DELDIRMBS_GLOB) | ||||
| 	if (flags & QSE_FS_RMDIRMBS_GLOB) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| @ -497,7 +497,7 @@ int qse_fs_deldirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		if (flags & QSE_FS_DELDIRMBS_RECURSIVE) | ||||
| 		if (flags & QSE_FS_RMDIRMBS_RECURSIVE) | ||||
| 		{ | ||||
| 			ret = qse_glob (xpath, purge_path_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr); | ||||
| 		} | ||||
| @ -510,11 +510,11 @@ int qse_fs_deldirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
|  | ||||
| 		if (ret <= -1) fs->errnum = QSE_FS_EGLOB; | ||||
| 	} | ||||
| 	else if (flags & QSE_FS_DELDIRMBS_RECURSIVE) | ||||
| 	else if (flags & QSE_FS_RMDIRMBS_RECURSIVE) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_delfilembs() */ | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_rmfilembs() */ | ||||
| 		xpath = (qse_char_t*)make_str_with_mbs (fs, path); | ||||
| 		if (!xpath) | ||||
| 		{ | ||||
| @ -534,11 +534,11 @@ int qse_fs_deldirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| int qse_fs_deldirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| int qse_fs_rmdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| { | ||||
| 	int ret; | ||||
|  | ||||
| 	if (flags & QSE_FS_DELDIRWCS_GLOB) | ||||
| 	if (flags & QSE_FS_RMDIRWCS_GLOB) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| @ -549,7 +549,7 @@ int qse_fs_deldirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		if (flags & QSE_FS_DELDIRWCS_RECURSIVE) | ||||
| 		if (flags & QSE_FS_RMDIRWCS_RECURSIVE) | ||||
| 		{ | ||||
| 			ret = qse_glob (xpath, purge_path_for_glob, fs, DEFAULT_GLOB_FLAGS, fs->mmgr, fs->cmgr); | ||||
| 		} | ||||
| @ -562,11 +562,11 @@ int qse_fs_deldirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
|  | ||||
| 		if (ret <= -1) fs->errnum = QSE_FS_EGLOB; | ||||
| 	} | ||||
| 	else if (flags & QSE_FS_DELDIRWCS_RECURSIVE) | ||||
| 	else if (flags & QSE_FS_RMDIRWCS_RECURSIVE) | ||||
| 	{ | ||||
| 		qse_char_t* xpath; | ||||
|  | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_delfilewcs() */ | ||||
| 		/* if RECURSIVE is set, it's not differnt from qse_fs_rmfilewcs() */ | ||||
| 		xpath = (qse_char_t*)make_str_with_wcs (fs, path); | ||||
| 		if (!xpath) | ||||
| 		{ | ||||
|  | ||||
| @ -26,7 +26,7 @@ | ||||
|  | ||||
| #include "fs-prv.h" | ||||
|  | ||||
| int qse_fs_sysmkdir (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| int qse_fs_mkdirsys (qse_fs_t* fs, const qse_fs_char_t* fspath) | ||||
| { | ||||
|  | ||||
| #if defined(_WIN32) | ||||
| @ -120,12 +120,8 @@ static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath) | ||||
| 			c = *(p + 1); | ||||
| 			*(p + 1) = QSE_FS_T('\0'); | ||||
| 		#endif | ||||
| 			ret = qse_fs_sysmkdir (fs, fspath); | ||||
| 			if (ret <= -1 && fs->errnum != QSE_FS_EEXIST)  | ||||
| 			{ | ||||
| 				return -1; | ||||
| 				goto done; /* abort */ | ||||
| 			} | ||||
| 			ret = qse_fs_mkdirsys (fs, fspath); | ||||
| 			if (ret <= -1 && fs->errnum != QSE_FS_EEXIST) goto done; /* abort */ | ||||
| 		#if defined(_WIN32) || defined(__DOS__) || defined(__OS2__) | ||||
| 			*p = c; | ||||
| 		#else | ||||
| @ -134,7 +130,7 @@ static int make_directory_chain (qse_fs_t* fs, qse_fs_char_t* fspath) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (!IS_FSPATHSEP(*(p - 1))) ret = qse_fs_sysmkdir (fs, fspath); | ||||
| 	if (!IS_FSPATHSEP(*(p - 1))) ret = qse_fs_mkdirsys (fs, fspath); | ||||
|  | ||||
| done: | ||||
| 	return ret; | ||||
| @ -151,7 +147,7 @@ int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	if (flags & QSE_FS_MKDIRMBS_PARENT) | ||||
| 	if (flags & QSE_FS_MKDIR_PARENT) | ||||
| 	{ | ||||
| 		/* make_directory_chain changes the input path. | ||||
| 		 * ensure to create a modifiable string for it. */ | ||||
| @ -165,7 +161,7 @@ int qse_fs_mkdirmbs (qse_fs_t* fs, const qse_mchar_t* path, int flags) | ||||
| 		fspath = (qse_fs_char_t*)qse_fs_makefspathformbs (fs, path); | ||||
| 		if (!fspath) return -1; | ||||
|  | ||||
| 		ret = qse_fs_sysmkdir (fs, fspath); | ||||
| 		ret = qse_fs_mkdirsys (fs, fspath); | ||||
| 	} | ||||
|  | ||||
| 	qse_fs_freefspathformbs (fs, path, fspath); | ||||
| @ -184,7 +180,7 @@ int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	if (flags & QSE_FS_MKDIRWCS_PARENT) | ||||
| 	if (flags & QSE_FS_MKDIR_PARENT) | ||||
| 	{ | ||||
| 		/* make_directory_chain changes the input path. | ||||
| 		 * ensure to create a modifiable string for it. */ | ||||
| @ -198,7 +194,7 @@ int qse_fs_mkdirwcs (qse_fs_t* fs, const qse_wchar_t* path, int flags) | ||||
| 		fspath = (qse_fs_char_t*)qse_fs_makefspathforwcs (fs, path); | ||||
| 		if (!fspath) return -1; | ||||
|  | ||||
| 		ret = qse_fs_sysmkdir (fs, fspath); | ||||
| 		ret = qse_fs_mkdirsys (fs, fspath); | ||||
| 	} | ||||
|  | ||||
| 	qse_fs_freefspathforwcs (fs, path, fspath); | ||||
|  | ||||
| @ -66,11 +66,25 @@ | ||||
| #	define make_str_with_mbs(fs,mbs) (mbs) | ||||
| #	define free_str_with_wcs(fs,wcs,str) QSE_MMGR_FREE((fs)->mmgr,str) | ||||
| #	define free_str_with_mbs(fs,mbs,str)  | ||||
| #	if defined(QSE_FS_CHAR_IS_MCHAR) | ||||
| #	define make_str_with_fspath(fs,fspath) (fspath) | ||||
| #	define free_str_with_fspath(fs,mbs,str)  | ||||
| #	else | ||||
| #	define make_str_with_fspath(fs,wcs) qse_wcstombsdupwithcmgr(wcs,QSE_NULL,(fs)->mmgr,(fs)->cmgr) | ||||
| #	define free_str_with_fspath(fs,wcs,str) QSE_MMGR_FREE((fs)->mmgr,str) | ||||
| #	endif | ||||
| #else | ||||
| #	define make_str_with_wcs(fs,wcs) (wcs) | ||||
| #	define make_str_with_mbs(fs,mbs) qse_mbstowcsdupwithcmgr(mbs,QSE_NULL,(fs)->mmgr,(fs)->cmgr) | ||||
| #	define free_str_with_wcs(fs,wcs,str) | ||||
| #	define free_str_with_mbs(fs,mbs,str) QSE_MMGR_FREE((fs)->mmgr,str) | ||||
| #	if defined(QSE_FS_CHAR_IS_MCHAR) | ||||
| #	define make_str_with_fspath(fs,mbs) qse_mbstowcsdupwithcmgr(mbs,QSE_NULL,(fs)->mmgr,(fs)->cmgr) | ||||
| #	define free_str_with_fspath(fs,mbs,str) QSE_MMGR_FREE((fs)->mmgr,str) | ||||
| #	else | ||||
| #	define make_str_with_fspath(fs,fspath) (fspath) | ||||
| #	define free_str_with_fspath(fs,mbs,str)  | ||||
| #	endif | ||||
| #endif | ||||
|  | ||||
| #if defined(QSE_FS_CHAR_IS_MCHAR) | ||||
| @ -163,17 +177,17 @@ int qse_fs_syscpfile ( | ||||
| 	const qse_fs_char_t* dstpath | ||||
| ); | ||||
|  | ||||
| int qse_fs_sysmkdir ( | ||||
| int qse_fs_mkdirsys ( | ||||
| 	qse_fs_t*            fs, | ||||
| 	const qse_fs_char_t* fspath | ||||
| ); | ||||
|  | ||||
| int qse_fs_sysrmfile ( | ||||
| int qse_fs_rmfilesys ( | ||||
| 	qse_fs_t*            fs,  | ||||
| 	const qse_fs_char_t* fspath | ||||
| ); | ||||
|  | ||||
| int qse_fs_sysrmdir ( | ||||
| int qse_fs_rmdirsys ( | ||||
| 	qse_fs_t*            fs,  | ||||
| 	const qse_fs_char_t* fspath | ||||
| ); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user