added qse_fs_delete() still primitive

This commit is contained in:
hyung-hwan 2012-02-21 12:54:42 +00:00
parent f2d767064e
commit 64fbfed781
7 changed files with 220 additions and 47 deletions

View File

@ -724,10 +724,7 @@ int sed_main (int argc, qse_char_t* argv[])
if (tmpl_tmpfile) if (tmpl_tmpfile)
{ {
/* qse_fs_delete (fs, tmpl_tmpfile);
TODO:
qse_fs_remove (fs, tmpl_tmpfile);
*/
QSE_MMGR_FREE (qse_sed_getmmgr(sed), tmpl_tmpfile); QSE_MMGR_FREE (qse_sed_getmmgr(sed), tmpl_tmpfile);
} }
print_exec_error (sed); print_exec_error (sed);

View File

@ -164,6 +164,11 @@ int qse_fs_move (
const qse_char_t* newpath const qse_char_t* newpath
); );
int qse_fs_delete (
qse_fs_t* fs,
const qse_char_t* path
);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -43,7 +43,6 @@ struct fop_t
{ {
int flags; int flags;
#if defined(_WIN32) #if defined(_WIN32)
/* nothing yet */ /* nothing yet */
#elif defined(__OS2__) #elif defined(__OS2__)
@ -255,7 +254,7 @@ int qse_fs_move (
{ {
/* both source and destination are the same. /* both source and destination are the same.
* this operation is not allowed */ * this operation is not allowed */
fs->errnum = QSE_FS_EPERM; fs->errnum = QSE_FS_EACCES;
goto oops; goto oops;
} }
@ -281,7 +280,6 @@ int qse_fs_move (
fs->errnum = QSE_FS_ENOMEM; fs->errnum = QSE_FS_ENOMEM;
goto oops; goto oops;
} }
qse_printf (QSE_T("new_path2 => [%hs]\n"), fop.new_path2);
} }
else else
{ {
@ -314,7 +312,7 @@ qse_printf (QSE_T("new_path2 => [%hs]\n"), fop.new_path2);
if (!S_ISDIR(fop.old_stat.st_mode)) if (!S_ISDIR(fop.old_stat.st_mode))
{ {
/* copy a single file */ /* copy a single file */
qse_printf (QSE_T("TODO: cross-device copy....\n")); /* ............ */
} }
#if 0 #if 0
@ -351,3 +349,165 @@ oops:
#endif #endif
} }
typedef struct del_op_t del_op_t;
struct del_op_t
{
#if defined(_WIN32)
/* nothing */
#elif defined(__OS2__)
qse_mchar_t* path;
#elif defined(__DOS__)
qse_mchar_t* path;
#else
qse_mchar_t* path;
#endif
};
int qse_fs_delete (qse_fs_t* fs, const qse_char_t* path)
{
/* TODO: improve this function to support fs->curdir ... etc
* delete directory ... etc */
#if defined(_WIN32)
if (DeleteFile (path) == FALSE)
{
fs->errnum = qse_fs_syserrtoerrnum (fs, GetLastError());
return -1;
}
return 0;
#elif defined(__OS2__)
/* ------------------------------------------------------ */
APIRET rc;
del_op_t dop;
QSE_MEMSET (&dop, 0, QSE_SIZEOF(dop));
#if defined(QSE_CHAR_IS_MCHAR)
dop.path = path;
#else
dop.path = qse_wcstombsdup (path, fs->mmgr);
if (dop.path == QSE_NULL)
{
fs->errnum = QSE_FS_ENOMEM;
goto oops;
}
#endif
rc = DosDelete (dop.path);
if (rc != NO_ERROR)
{
fs->errnum = qse_fs_syserrtoerrnum (fs, rc);
goto oops;
}
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
QSE_MMGR_FREE (fs->mmgr, dop.path);
#endif
return 0;
/* ------------------------------------------------------ */
oops:
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
if (dop.path) QSE_MMGR_FREE (fs->mmgr, dop.path);
#endif
return -1;
#elif defined(__DOS__)
/* ------------------------------------------------------ */
del_op_t dop;
QSE_MEMSET (&dop, 0, QSE_SIZEOF(dop));
#if defined(QSE_CHAR_IS_MCHAR)
dop.path = path;
#else
dop.path = qse_wcstombsdup (path, fs->mmgr);
if (dop.path == QSE_NULL)
{
fs->errnum = QSE_FS_ENOMEM;
goto oops;
}
#endif
if (unlink (dop.path) <= -1)
{
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
goto oops;
}
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
QSE_MMGR_FREE (fs->mmgr, dop.path);
#endif
return 0;
oops:
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
if (dop.path) QSE_MMGR_FREE (fs->mmgr, dop.path);
#endif
return -1;
/* ------------------------------------------------------ */
#else
/* ------------------------------------------------------ */
del_op_t dop;
QSE_MEMSET (&dop, 0, QSE_SIZEOF(dop));
#if defined(QSE_CHAR_IS_MCHAR)
dop.path = path;
#else
dop.path = qse_wcstombsdup (path, fs->mmgr);
if (dop.path == QSE_NULL)
{
fs->errnum = QSE_FS_ENOMEM;
goto oops;
}
#endif
if (QSE_UNLINK (dop.path) <= -1)
{
fs->errnum = qse_fs_syserrtoerrnum (fs, errno);
goto oops;
}
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
QSE_MMGR_FREE (fs->mmgr, dop.path);
#endif
return 0;
oops:
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
if (dop.path) QSE_MMGR_FREE (fs->mmgr, dop.path);
#endif
return -1;
/* ------------------------------------------------------ */
#endif
}

View File

@ -29,6 +29,8 @@
typedef APIRET qse_fs_syserr_t; typedef APIRET qse_fs_syserr_t;
#elif defined(__DOS__) #elif defined(__DOS__)
# include <errno.h> # include <errno.h>
# include <io.h>
# include <stdio.h> /* for rename() */
typedef int qse_fs_syserr_t; typedef int qse_fs_syserr_t;
#else #else
# include "syscall.h" # include "syscall.h"

View File

@ -1232,7 +1232,7 @@ create_process:
pio->errnum = syserr_to_errnum (pserr); pio->errnum = syserr_to_errnum (pserr);
goto oops; goto oops;
} }
if ((pserr = posix_spawn_file_actions_adddup2 (&fa, handle[0]), 0) != 0) if ((pserr = posix_spawn_file_actions_adddup2 (&fa, handle[0], 0)) != 0)
{ {
pio->errnum = syserr_to_errnum (pserr); pio->errnum = syserr_to_errnum (pserr);
goto oops; goto oops;

View File

@ -67,103 +67,112 @@ qsecmn qsesed
0 0
17 17
WVList WVList
1
18
ActionStates
19
WString
12
Local &Debug
20
WVList
0 0
-1 -1
1 1
1 1
0 0
18 21
WPickList WPickList
2 2
19 22
MItem MItem
3 3
*.c *.c
20 23
WString WString
4 4
COBJ COBJ
21 24
WVList WVList
3 3
22 25
MVState MVState
23 26
WString WString
3 3
WCC WCC
24 27
WString WString
25 25
o?2??Include directories: o?2??Include directories:
1 1
25 28
WString WString
54 54
"$(%watcom)/h;$(%watcom)/h/os2;../../../../../include" "$(%watcom)/h;$(%watcom)/h/os2;../../../../../include"
0 0
26 29
MVState MVState
27 30
WString WString
3 3
WCC WCC
28 31
WString WString
23 23
?????Macro definitions: ?????Macro definitions:
1 1
29 32
WString WString
15 15
QSE_BUILD_DEBUG QSE_BUILD_DEBUG
0 0
30 33
MCState MCState
31 34
WString WString
3 3
WCC WCC
32 35
WString WString
29 29
?????Emit Browser information ?????Emit Browser information
1 1
1 1
33 36
WVList WVList
0 0
-1 -1
1 1
1 1
0 0
34 37
MItem MItem
28 28
../../../../../cmd/sed/sed.c ../../../../../cmd/sed/sed.c
35 38
WString WString
4 4
COBJ COBJ
36 39
WVList WVList
1 1
37 40
MCState MCState
38 41
WString WString
3 3
WCC WCC
39 42
WString WString
29 29
?????Emit Browser information ?????Emit Browser information
1 1
1 1
40 43
WVList WVList
0 0
19 22
1 1
1 1
0 0

View File

@ -5,7 +5,7 @@ VpeMain
1 1
WRect WRect
390 390
40 26
9320 9320
9680 9680
2 2
@ -154,8 +154,8 @@ WRect
WFileName WFileName
28 28
debug/os2/lib/cmn/qsecmn.tgt debug/os2/lib/cmn/qsecmn.tgt
8 0
12 4
36 36
VComponent VComponent
37 37
@ -164,14 +164,14 @@ WRect
2360 2360
5700 5700
4240 4240
1 0
0 0
38 38
WFileName WFileName
28 28
debug/os2/lib/sed/qsesed.tgt debug/os2/lib/sed/qsesed.tgt
0 0
0 3
39 39
VComponent VComponent
40 40
@ -224,8 +224,8 @@ debug/win32/lib/awk/qseawk.tgt
VComponent VComponent
49 49
WRect WRect
2480 330
360 413
5700 5700
4240 4240
1 1
@ -240,8 +240,8 @@ debug/os2/cmd/awk/qseawk.tgt
VComponent VComponent
52 52
WRect WRect
1730 2430
1080 920
5700 5700
4240 4240
0 0
@ -251,7 +251,7 @@ WFileName
30 30
debug/dos32/lib/cmn/qsecmn.tgt debug/dos32/lib/cmn/qsecmn.tgt
0 0
3 0
54 54
VComponent VComponent
55 55
@ -308,14 +308,14 @@ WRect
0 0
5700 5700
4240 4240
1 0
0 0
65 65
WFileName WFileName
30 30
debug/dos32/lib/sed/qsesed.tgt debug/dos32/lib/sed/qsesed.tgt
0 0
0 5
66 66
VComponent VComponent
67 67
@ -324,7 +324,7 @@ WRect
560 560
5700 5700
4240 4240
1 0
0 0
68 68
WFileName WFileName
@ -340,7 +340,7 @@ WRect
0 0
5700 5700
4240 4240
1 0
0 0
71 71
WFileName WFileName