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)
{
/*
TODO:
qse_fs_remove (fs, tmpl_tmpfile);
*/
qse_fs_delete (fs, tmpl_tmpfile);
QSE_MMGR_FREE (qse_sed_getmmgr(sed), tmpl_tmpfile);
}
print_exec_error (sed);

View File

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

View File

@ -43,7 +43,6 @@ struct fop_t
{
int flags;
#if defined(_WIN32)
/* nothing yet */
#elif defined(__OS2__)
@ -255,7 +254,7 @@ int qse_fs_move (
{
/* both source and destination are the same.
* this operation is not allowed */
fs->errnum = QSE_FS_EPERM;
fs->errnum = QSE_FS_EACCES;
goto oops;
}
@ -281,7 +280,6 @@ int qse_fs_move (
fs->errnum = QSE_FS_ENOMEM;
goto oops;
}
qse_printf (QSE_T("new_path2 => [%hs]\n"), fop.new_path2);
}
else
{
@ -314,7 +312,7 @@ qse_printf (QSE_T("new_path2 => [%hs]\n"), fop.new_path2);
if (!S_ISDIR(fop.old_stat.st_mode))
{
/* copy a single file */
qse_printf (QSE_T("TODO: cross-device copy....\n"));
/* ............ */
}
#if 0
@ -351,3 +349,165 @@ oops:
#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;
#elif defined(__DOS__)
# include <errno.h>
# include <io.h>
# include <stdio.h> /* for rename() */
typedef int qse_fs_syserr_t;
#else
# include "syscall.h"

View File

@ -1232,7 +1232,7 @@ create_process:
pio->errnum = syserr_to_errnum (pserr);
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);
goto oops;

View File

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

View File

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