2011-11-20 16:24:11 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2011-11-20 16:24:11 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2011-11-20 16:24:11 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2011-11-20 16:24:11 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-29 03:55:42 +00:00
|
|
|
#include "fs-prv.h"
|
2011-12-31 15:24:48 +00:00
|
|
|
#include <qse/cmn/mbwc.h>
|
2011-12-02 16:05:16 +00:00
|
|
|
#include <qse/cmn/path.h>
|
2012-01-17 16:45:01 +00:00
|
|
|
#include <qse/cmn/str.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include "../cmn/mem-prv.h"
|
2011-11-20 16:24:11 +00:00
|
|
|
|
2011-11-23 15:11:22 +00:00
|
|
|
/*
|
|
|
|
OVERWRITE AND FORCE handled by callback???
|
|
|
|
QSE_FS_MOVE_UPDATE
|
|
|
|
QSE_FS_MOVE_BACKUP_SIMPLE
|
|
|
|
QSE_FS_MOVE_BACKUP_NUMBERED
|
|
|
|
*/
|
2011-12-02 16:05:16 +00:00
|
|
|
enum fop_flag_t
|
|
|
|
{
|
|
|
|
FOP_OLD_STAT = (1 << 0),
|
|
|
|
FOP_NEW_STAT = (1 << 1),
|
|
|
|
|
|
|
|
FOP_CROSS_DEV = (1 << 2)
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fop_t
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
2012-02-21 09:23:51 +00:00
|
|
|
/* nothing yet */
|
|
|
|
#elif defined(__OS2__)
|
2014-12-03 15:27:45 +00:00
|
|
|
qse_fs_char_t* old_path;
|
|
|
|
qse_fs_char_t* new_path;
|
2012-02-21 09:23:51 +00:00
|
|
|
#elif defined(__DOS__)
|
2014-12-03 15:27:45 +00:00
|
|
|
qse_fs_char_t* old_path;
|
|
|
|
qse_fs_char_t* new_path;
|
2011-12-02 16:05:16 +00:00
|
|
|
#else
|
2014-12-03 15:27:45 +00:00
|
|
|
qse_fs_char_t* old_path;
|
|
|
|
qse_fs_char_t* new_path;
|
|
|
|
qse_fs_char_t* new_path2;
|
2012-02-21 09:23:51 +00:00
|
|
|
|
2014-12-03 15:27:45 +00:00
|
|
|
#if defined(HAVE_LSTAT)
|
2012-02-21 09:23:51 +00:00
|
|
|
qse_lstat_t old_stat;
|
|
|
|
qse_lstat_t new_stat;
|
2014-12-03 15:27:45 +00:00
|
|
|
#else
|
|
|
|
qse_stat_t old_stat;
|
|
|
|
qse_stat_t new_stat;
|
|
|
|
#endif
|
2011-12-02 16:05:16 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct fop_t fop_t;
|
2011-11-23 15:11:22 +00:00
|
|
|
|
2014-12-03 15:27:45 +00:00
|
|
|
int qse_fs_move (qse_fs_t* fs, const qse_char_t* oldpath, const qse_char_t* newpath)
|
2011-11-20 16:24:11 +00:00
|
|
|
{
|
2012-02-21 09:23:51 +00:00
|
|
|
|
2011-11-20 16:24:11 +00:00
|
|
|
#if defined(_WIN32)
|
2012-02-21 09:23:51 +00:00
|
|
|
/* ------------------------------------------------------ */
|
2011-11-20 16:24:11 +00:00
|
|
|
/* TODO: improve it... */
|
|
|
|
|
|
|
|
/* TODO: support cross-volume move, move by copy/delete, etc ... */
|
|
|
|
if (MoveFile (oldpath, newpath) == FALSE)
|
|
|
|
{
|
|
|
|
DWORD e = GetLastError();
|
|
|
|
if (e == ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
DeleteFile (newpath);
|
|
|
|
if (MoveFile (oldpath, newpath) == FALSE)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, e);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-02-21 09:23:51 +00:00
|
|
|
/* ------------------------------------------------------ */
|
2011-11-20 16:24:11 +00:00
|
|
|
|
|
|
|
#elif defined(__OS2__)
|
2012-02-21 09:23:51 +00:00
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
|
|
|
/* TODO: improve it */
|
|
|
|
int ret = 0;
|
|
|
|
fop_t fop;
|
|
|
|
|
|
|
|
QSE_MEMSET (&fop, 0, QSE_SIZEOF(fop));
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
fop.old_path = oldpath;
|
|
|
|
fop.new_path = newpath;
|
|
|
|
#else
|
2012-10-18 06:52:03 +00:00
|
|
|
fop.old_path = qse_wcstombsdup (oldpath, QSE_NULL, fs->mmgr);
|
|
|
|
fop.new_path = qse_wcstombsdup (newpath, QSE_NULL, fs->mmgr);
|
2012-02-21 09:23:51 +00:00
|
|
|
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
|
|
|
{
|
|
|
|
fs->errnum = QSE_FS_ENOMEM;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
APIRET rc;
|
|
|
|
|
|
|
|
rc = DosMove (fop.old_path, fop.new_path);
|
2012-08-31 13:00:33 +00:00
|
|
|
if (rc == ERROR_ALREADY_EXISTS || rc == ERROR_ACCESS_DENIED)
|
2012-02-21 09:23:51 +00:00
|
|
|
{
|
|
|
|
DosDelete (fop.new_path);
|
|
|
|
rc = DosMove (fop.old_path, fop.new_path);
|
|
|
|
}
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, rc);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* nothing special */
|
|
|
|
#else
|
|
|
|
if (fop.old_path) QSE_MMGR_FREE (fs->mmgr, fop.old_path);
|
|
|
|
if (fop.new_path) QSE_MMGR_FREE (fs->mmgr, fop.new_path);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
2011-11-20 16:24:11 +00:00
|
|
|
#elif defined(__DOS__)
|
|
|
|
|
2012-02-21 09:23:51 +00:00
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
/* TODO: improve it */
|
2011-12-02 16:05:16 +00:00
|
|
|
fop_t fop;
|
2012-02-21 09:23:51 +00:00
|
|
|
int ret = 0;
|
2011-11-20 16:24:11 +00:00
|
|
|
|
2011-12-02 16:05:16 +00:00
|
|
|
QSE_MEMSET (&fop, 0, QSE_SIZEOF(fop));
|
2011-11-23 15:11:22 +00:00
|
|
|
|
2012-02-21 09:23:51 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
2011-12-02 16:05:16 +00:00
|
|
|
fop.old_path = oldpath;
|
|
|
|
fop.new_path = newpath;
|
2012-02-21 09:23:51 +00:00
|
|
|
#else
|
2012-10-18 06:52:03 +00:00
|
|
|
fop.old_path = qse_wcstombsdup (oldpath, QSE_NULL, fs->mmgr);
|
|
|
|
fop.new_path = qse_wcstombsdup (newpath, QSE_NULL, fs->mmgr);
|
2012-02-21 09:23:51 +00:00
|
|
|
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
|
|
|
{
|
|
|
|
fs->errnum = QSE_FS_ENOMEM;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
if (rename (fop.old_path, fop.new_path) <= -1)
|
|
|
|
{
|
|
|
|
/* FYI, rename() on watcom seems to set
|
|
|
|
* errno to EACCES when the new path exists. */
|
|
|
|
|
|
|
|
unlink (fop.new_path);
|
|
|
|
if (rename (fop.old_path, fop.new_path) <= -1)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
/* nothing special */
|
|
|
|
#else
|
|
|
|
if (fop.old_path) QSE_MMGR_FREE (fs->mmgr, fop.old_path);
|
|
|
|
if (fop.new_path) QSE_MMGR_FREE (fs->mmgr, fop.new_path);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
2011-11-20 16:24:11 +00:00
|
|
|
#else
|
2012-02-21 09:23:51 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
fop_t fop;
|
|
|
|
QSE_MEMSET (&fop, 0, QSE_SIZEOF(fop));
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
2019-06-12 07:07:18 +00:00
|
|
|
fop.old_path = (qse_char_t*)oldpath;
|
|
|
|
fop.new_path = (qse_char_t*)newpath;
|
2012-02-21 09:23:51 +00:00
|
|
|
#else
|
2019-06-12 07:07:18 +00:00
|
|
|
fop.old_path = qse_wcstombsdup(oldpath, QSE_NULL, fs->mmgr);
|
|
|
|
fop.new_path = qse_wcstombsdup(newpath, QSE_NULL, fs->mmgr);
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
2011-11-20 16:24:11 +00:00
|
|
|
{
|
|
|
|
fs->errnum = QSE_FS_ENOMEM;
|
|
|
|
goto oops;
|
|
|
|
}
|
2012-02-21 09:23:51 +00:00
|
|
|
#endif
|
2011-11-20 16:24:11 +00:00
|
|
|
|
|
|
|
/* TOOD: implement confirmatio
|
|
|
|
if (overwrite_callback is set)
|
|
|
|
{
|
|
|
|
checkif the the mbsnewpat exists.
|
|
|
|
if (it exists)
|
|
|
|
{
|
|
|
|
call fs->confirm_overwrite_callback (....)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2011-12-02 16:05:16 +00:00
|
|
|
/* use lstat because we need to move the symbolic link
|
|
|
|
* itself if the file is a symbolic link */
|
2014-11-18 16:10:12 +00:00
|
|
|
#if defined(HAVE_LSTAT)
|
2011-12-02 16:05:16 +00:00
|
|
|
if (QSE_LSTAT (fop.old_path, &fop.old_stat) == -1)
|
2014-11-18 16:10:12 +00:00
|
|
|
#else
|
|
|
|
if (QSE_STAT (fop.old_path, &fop.old_stat) == -1) /* is this ok to use stat? */
|
|
|
|
#endif
|
2011-11-23 15:11:22 +00:00
|
|
|
{
|
2011-12-02 16:05:16 +00:00
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
|
|
|
|
goto oops;
|
2011-11-23 15:11:22 +00:00
|
|
|
}
|
2011-12-02 16:05:16 +00:00
|
|
|
else fop.flags |= FOP_OLD_STAT;
|
2011-11-23 15:11:22 +00:00
|
|
|
|
2014-11-18 16:10:12 +00:00
|
|
|
#if defined(HAVE_LSTAT)
|
2011-12-02 16:05:16 +00:00
|
|
|
if (QSE_LSTAT (fop.new_path, &fop.new_stat) == -1)
|
2014-11-18 16:10:12 +00:00
|
|
|
#else
|
|
|
|
if (QSE_STAT (fop.new_path, &fop.new_stat) == -1)
|
|
|
|
#endif
|
2011-11-23 15:11:22 +00:00
|
|
|
{
|
|
|
|
if (errno == ENOENT)
|
|
|
|
{
|
|
|
|
/* entry doesn't exist */
|
|
|
|
}
|
|
|
|
}
|
2011-12-02 16:05:16 +00:00
|
|
|
else fop.flags |= FOP_NEW_STAT;
|
2011-11-23 15:11:22 +00:00
|
|
|
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.flags & FOP_NEW_STAT)
|
2011-11-20 16:24:11 +00:00
|
|
|
{
|
2011-12-02 16:05:16 +00:00
|
|
|
/* destination file exits */
|
|
|
|
if (fop.old_stat.st_dev != fop.new_stat.st_dev)
|
2011-11-20 16:24:11 +00:00
|
|
|
{
|
2011-12-02 16:05:16 +00:00
|
|
|
/* cross-device */
|
|
|
|
fop.flags |= FOP_CROSS_DEV;
|
2011-11-20 16:24:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.old_stat.st_ino == fop.new_stat.st_ino)
|
|
|
|
{
|
|
|
|
/* both source and destination are the same.
|
|
|
|
* this operation is not allowed */
|
2012-02-21 12:54:42 +00:00
|
|
|
fs->errnum = QSE_FS_EACCES;
|
2011-12-02 16:05:16 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: destination should point to an actual file or directory for this check to work */
|
|
|
|
/* TOOD: ask to overwrite the source */
|
|
|
|
if (S_ISDIR(fop.new_stat.st_mode))
|
|
|
|
{
|
|
|
|
/* the destination is a directory. move the source file
|
|
|
|
* into the destination directory */
|
2019-06-12 07:07:18 +00:00
|
|
|
const qse_char_t* arr[4];
|
2011-12-02 16:05:16 +00:00
|
|
|
|
|
|
|
arr[0] = newpath;
|
|
|
|
arr[1] = QSE_T("/");
|
|
|
|
arr[2] = qse_basename(oldpath);
|
|
|
|
arr[3] = QSE_NULL;
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
2019-06-12 07:07:18 +00:00
|
|
|
fop.new_path2 = qse_stradup(arr, QSE_NULL, fs->mmgr);
|
2011-12-02 16:05:16 +00:00
|
|
|
#else
|
2019-06-12 07:07:18 +00:00
|
|
|
fop.new_path2 = qse_wcsatombsdup(arr, QSE_NULL, fs->mmgr);
|
2011-12-02 16:05:16 +00:00
|
|
|
#endif
|
|
|
|
if (fop.new_path2 == QSE_NULL)
|
|
|
|
{
|
|
|
|
fs->errnum = QSE_FS_ENOMEM;
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* the destination file is not directory, unlink first
|
|
|
|
* TODO: but is this necessary? RENAME will do it */
|
|
|
|
QSE_UNLINK (fop.new_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(fop.flags & FOP_CROSS_DEV))
|
|
|
|
{
|
|
|
|
/* TODO: make it better to be able to move non-empty diretories
|
|
|
|
improve it to be able to move by copy/delete across volume */
|
|
|
|
if (QSE_RENAME (fop.old_path, fop.new_path) == -1)
|
|
|
|
{
|
|
|
|
if (errno != EXDEV)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
fop.flags |= FOP_CROSS_DEV;
|
2011-11-20 16:24:11 +00:00
|
|
|
}
|
2011-12-02 16:05:16 +00:00
|
|
|
else goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSE_ASSERT (fop.flags & FOP_CROSS_DEV);
|
|
|
|
|
|
|
|
if (!S_ISDIR(fop.old_stat.st_mode))
|
|
|
|
{
|
|
|
|
/* copy a single file */
|
2012-02-21 12:54:42 +00:00
|
|
|
/* ............ */
|
2011-12-02 16:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!recursive)
|
|
|
|
{
|
2014-11-26 15:14:24 +00:00
|
|
|
fs->errnum = QSE_FS_E....;
|
2011-12-02 16:05:16 +00:00
|
|
|
goto oops;
|
2011-11-20 16:24:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 16:05:16 +00:00
|
|
|
copy recursively...
|
|
|
|
#endif
|
|
|
|
|
2012-02-21 09:23:51 +00:00
|
|
|
|
2011-12-02 16:05:16 +00:00
|
|
|
done:
|
2012-02-21 09:23:51 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.new_path2) QSE_MMGR_FREE (fs->mmgr, fop.new_path2);
|
2012-02-21 09:23:51 +00:00
|
|
|
#else
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.new_path2) QSE_MMGR_FREE (fs->mmgr, fop.new_path2);
|
|
|
|
QSE_MMGR_FREE (fs->mmgr, fop.old_path);
|
|
|
|
QSE_MMGR_FREE (fs->mmgr, fop.new_path);
|
2012-02-21 09:23:51 +00:00
|
|
|
#endif
|
2011-11-20 16:24:11 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
oops:
|
2012-02-21 09:23:51 +00:00
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.new_path2) QSE_MMGR_FREE (fs->mmgr, fop.new_path2);
|
2012-02-21 09:23:51 +00:00
|
|
|
#else
|
2011-12-02 16:05:16 +00:00
|
|
|
if (fop.new_path2) QSE_MMGR_FREE (fs->mmgr, fop.new_path2);
|
|
|
|
if (fop.old_path) QSE_MMGR_FREE (fs->mmgr, fop.old_path);
|
|
|
|
if (fop.new_path) QSE_MMGR_FREE (fs->mmgr, fop.new_path);
|
2012-02-21 09:23:51 +00:00
|
|
|
#endif
|
2011-11-20 16:24:11 +00:00
|
|
|
return -1;
|
2012-02-21 09:23:51 +00:00
|
|
|
/* ------------------------------------------------------ */
|
2011-11-20 16:24:11 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2012-02-21 12:54:42 +00:00
|
|
|
|
2014-12-11 16:03:58 +00:00
|
|
|
#if 0
|
2014-12-03 15:27:45 +00:00
|
|
|
static int move_file_in_fs (qse_fs_t* fs, const qse_fs_char_t* oldpath, const qse_fs_char_t* newpath, int flags)
|
|
|
|
{
|
|
|
|
#if defined(_WIN32)
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
|
|
|
if (MoveFile (oldpath, newpath) == FALSE)
|
|
|
|
{
|
|
|
|
DWORD e = GetLastError();
|
|
|
|
if (e == ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
DeleteFile (newpath);
|
|
|
|
if (MoveFile (oldpath, newpath) == FALSE)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, e);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
|
|
|
#elif defined(__OS2__)
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
|
|
|
/* TODO: improve it */
|
|
|
|
APIRET rc;
|
|
|
|
|
|
|
|
rc = DosMove (oldpath, newpath);
|
|
|
|
if (rc == ERROR_ALREADY_EXISTS || rc == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
DosDelete (fop.new_path);
|
|
|
|
rc = DosMove (oldpath, newpath);
|
|
|
|
}
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, rc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
|
|
|
#elif defined(__DOS__)
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
if (rename (oldpath, newpath) <= -1)
|
|
|
|
{
|
|
|
|
/* FYI, rename() on watcom seems to set
|
|
|
|
* errno to EACCES when the new path exists. */
|
|
|
|
|
|
|
|
unlink (newpath);
|
|
|
|
if (rename (oldpath, newpath) <= -1)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (!(flags & QSE_FS_CPFILE_REPLACE))
|
|
|
|
{
|
|
|
|
qse_lstat_t st;
|
|
|
|
if (QSE_LSTAT (newpath, &st) >= 0)
|
|
|
|
{
|
|
|
|
fs->errnum = QSE_FS_EEXIST;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QSE_RENAME (oldpath, newpath) == -1)
|
|
|
|
{
|
|
|
|
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2014-12-11 16:03:58 +00:00
|
|
|
|
|
|
|
#endif
|