enhanced fio.c for DOS

This commit is contained in:
hyung-hwan 2011-05-05 09:11:23 +00:00
parent 574f373cf0
commit 26bae0b0fb
3 changed files with 125 additions and 36 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: fio.h 441 2011-04-22 14:28:43Z hyunghwan.chung $ * $Id: fio.h 452 2011-05-04 15:11:23Z hyunghwan.chung $
* *
Copyright 2006-2011 Chung, Hyung-Hwan. Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -85,6 +85,8 @@ enum qse_fio_mode_t
/* <os2def.h> => typedef LHANDLE HFILE; /* <os2def.h> => typedef LHANDLE HFILE;
typedef unsigned long LHANDLE; */ typedef unsigned long LHANDLE; */
typedef unsigned long qse_fio_hnd_t; typedef unsigned long qse_fio_hnd_t;
#elif defined(__DOS__)
typedef int qse_fio_hnd_t;
#else #else
typedef int qse_fio_hnd_t; typedef int qse_fio_hnd_t;
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: fio.c 451 2011-05-03 14:00:38Z hyunghwan.chung $ * $Id: fio.c 452 2011-05-04 15:11:23Z hyunghwan.chung $
* *
Copyright 2006-2011 Chung, Hyung-Hwan. Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -30,6 +30,9 @@
# define INCL_DOSFILEMGR # define INCL_DOSFILEMGR
# define INCL_DOSERRORS # define INCL_DOSERRORS
# include <os2.h> # include <os2.h>
#elif defined(__DOS__)
# include <io.h>
# include <fcntl.h>
#else #else
# include "syscall.h" # include "syscall.h"
# include <sys/types.h> # include <sys/types.h>
@ -252,9 +255,57 @@ qse_fio_t* qse_fio_init (
if (ret != NO_ERROR) return QSE_NULL; if (ret != NO_ERROR) return QSE_NULL;
} }
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */
return QSE_NULL; if (flags & QSE_FIO_HANDLE)
{
handle = *(qse_fio_hnd_t*)path;
}
else
{
int oflags = 0;
int permission = 0;
#ifdef QSE_CHAR_IS_MCHAR
const qse_mchar_t* path_mb = path;
#else
qse_mchar_t path_mb[_MAX_PATH];
if (qse_wcstombs_strict (path,
path_mb, QSE_COUNTOF(path_mb)) == -1) return QSE_NULL;
#endif
if (flags & QSE_FIO_APPEND)
{
if ((flags & QSE_FIO_READ)) oflags |= O_RDWR;
else oflags |= O_WRONLY;
oflags |= O_APPEND;
}
else
{
if ((flags & QSE_FIO_READ) &&
(flags & QSE_FIO_WRITE)) oflags |= O_RDWR;
else if (flags & QSE_FIO_READ) oflags |= O_RDONLY;
else if (flags & QSE_FIO_WRITE) oflags |= O_WRONLY;
}
if (flags & QSE_FIO_CREATE) oflags |= O_CREAT;
if (flags & QSE_FIO_TRUNCATE) oflags |= O_TRUNC;
if (flags & QSE_FIO_EXCLUSIVE) oflags |= O_EXCL;
oflags |= O_BINARY | O_NOINHERIT;
if (mode & QSE_FIO_RUSR) permission |= S_IREAD;
if (mode & QSE_FIO_WUSR) permission |= S_IWRITE;
handle = open (
path_mb,
oflags,
permission
);
if (handle <= -1) return QSE_NULL;
}
#else #else
if (flags & QSE_FIO_HANDLE) if (flags & QSE_FIO_HANDLE)
@ -332,8 +383,7 @@ qse_fio_t* qse_fio_init (
#elif defined(__OS2__) #elif defined(__OS2__)
DosClose (handle); DosClose (handle);
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */ close (handle);
;
#else #else
QSE_CLOSE (handle); QSE_CLOSE (handle);
#endif #endif
@ -356,8 +406,7 @@ void qse_fio_fini (qse_fio_t* fio)
#elif defined(__OS2__) #elif defined(__OS2__)
DosClose (fio->handle); DosClose (fio->handle);
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */ close (fio->handle);
;
#else #else
QSE_CLOSE (fio->handle); QSE_CLOSE (fio->handle);
#endif #endif
@ -427,10 +476,14 @@ qse_fio_off_t qse_fio_seek (
return ((qse_fio_off_t)pos.ulHi << 32) | pos.ulLo; return ((qse_fio_off_t)pos.ulHi << 32) | pos.ulLo;
#elif defined(__DOS__) #elif defined(__DOS__)
static int seek_map[] =
{
SEEK_SET,
SEEK_CUR,
SEEK_END
};
/* UNSUPPORTED */ return lseek (fio->handle, offset, seek_map[origin]);
return -1;
#else #else
static int seek_map[] = static int seek_map[] =
{ {
@ -484,8 +537,8 @@ int qse_fio_truncate (qse_fio_t* fio, qse_fio_off_t size)
return (ret == NO_ERROR)? 0: -1; return (ret == NO_ERROR)? 0: -1;
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */
return -1; return chsize (fio->handle, size);
#else #else
return QSE_FTRUNCATE (fio->handle, size); return QSE_FTRUNCATE (fio->handle, size);
@ -495,19 +548,26 @@ int qse_fio_truncate (qse_fio_t* fio, qse_fio_off_t size)
static qse_ssize_t fio_read (qse_fio_t* fio, void* buf, qse_size_t size) static qse_ssize_t fio_read (qse_fio_t* fio, void* buf, qse_size_t size)
{ {
#if defined(_WIN32) #if defined(_WIN32)
DWORD count; DWORD count;
if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD); if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD);
if (ReadFile(fio->handle, buf, (DWORD)size, &count, QSE_NULL) == FALSE) return -1; if (ReadFile (fio->handle,
buf, (DWORD)size, &count, QSE_NULL) == FALSE) return -1;
return (qse_ssize_t)count; return (qse_ssize_t)count;
#elif defined(__OS2__) #elif defined(__OS2__)
ULONG count; ULONG count;
if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG); if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG);
if (DosRead (fio->handle, buf, (ULONG)size, &count) != NO_ERROR) return -1; if (DosRead (fio->handle,
buf, (ULONG)size, &count) != NO_ERROR) return -1;
return (qse_ssize_t)count; return (qse_ssize_t)count;
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */
return -1; if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
return read (fio->handle, buf, size);
#else #else
if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t); if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
return QSE_READ (fio->handle, buf, size); return QSE_READ (fio->handle, buf, size);
@ -527,20 +587,28 @@ static qse_ssize_t fio_write (qse_fio_t* fio, const void* data, qse_size_t size)
#if defined(_WIN32) #if defined(_WIN32)
DWORD count; DWORD count;
if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD); if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD);
if (WriteFile(fio->handle, data, (DWORD)size, &count, QSE_NULL) == FALSE) return -1; if (WriteFile (fio->handle,
data, (DWORD)size, &count, QSE_NULL) == FALSE) return -1;
return (qse_ssize_t)count; return (qse_ssize_t)count;
#elif defined(__OS2__) #elif defined(__OS2__)
ULONG count; ULONG count;
if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG); if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG);
if (DosWrite(fio->handle, (PVOID)data, (ULONG)size, &count) != NO_ERROR) return -1; if (DosWrite(fio->handle,
(PVOID)data, (ULONG)size, &count) != NO_ERROR) return -1;
return (qse_ssize_t)count; return (qse_ssize_t)count;
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */
return -1; if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
return write (fio->handle, data, size);
#else #else
if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t); if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
return QSE_WRITE (fio->handle, data, size); return QSE_WRITE (fio->handle, data, size);
#endif #endif
} }
@ -667,6 +735,7 @@ static int get_volname_from_handle (
int qse_fio_chmod (qse_fio_t* fio, int mode) int qse_fio_chmod (qse_fio_t* fio, int mode)
{ {
#if defined(_WIN32) #if defined(_WIN32)
int flags = FILE_ATTRIBUTE_NORMAL; int flags = FILE_ATTRIBUTE_NORMAL;
qse_char_t name[MAX_PATH]; qse_char_t name[MAX_PATH];
@ -678,12 +747,15 @@ int qse_fio_chmod (qse_fio_t* fio, int mode)
if (!(mode & QSE_FIO_WUSR)) flags = FILE_ATTRIBUTE_READONLY; if (!(mode & QSE_FIO_WUSR)) flags = FILE_ATTRIBUTE_READONLY;
return (SetFileAttributes (name, flags) == FALSE)? -1: 0; return (SetFileAttributes (name, flags) == FALSE)? -1: 0;
#elif defined(__OS2__) #elif defined(__OS2__)
int flags = FILE_NORMAL; int flags = FILE_NORMAL;
FILESTATUS3L stat; FILESTATUS3L stat;
ULONG size = QSE_SIZEOF(stat); ULONG size = QSE_SIZEOF(stat);
if (DosQueryFileInfo (fio->handle, FIL_STANDARDL, &stat, size) != NO_ERROR) return -1; if (DosQueryFileInfo (fio->handle,
FIL_STANDARDL, &stat, size) != NO_ERROR) return -1;
if (!(mode & QSE_FIO_WUSR)) flags = FILE_READONLY; if (!(mode & QSE_FIO_WUSR)) flags = FILE_READONLY;
@ -691,8 +763,17 @@ int qse_fio_chmod (qse_fio_t* fio, int mode)
return (DosSetFileInfo (fio->handle, FIL_STANDARDL, &stat, size) != NO_ERROR)? -1: 0; return (DosSetFileInfo (fio->handle, FIL_STANDARDL, &stat, size) != NO_ERROR)? -1: 0;
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */
int permission = 0;
if (mode & QSE_FIO_RUSR) permission |= S_IREAD;
if (mode & QSE_FIO_WUSR) permission |= S_IWRITE;
/* TODO: fchmod not available. find a way to do this
return fchmod (fio->handle, permission); */
return -1; return -1;
#else #else
return QSE_FCHMOD (fio->handle, mode); return QSE_FCHMOD (fio->handle, mode);
#endif #endif
@ -701,15 +782,21 @@ int qse_fio_chmod (qse_fio_t* fio, int mode)
int qse_fio_sync (qse_fio_t* fio) int qse_fio_sync (qse_fio_t* fio)
{ {
#if defined(_WIN32) #if defined(_WIN32)
return (FlushFileBuffers (fio->handle) == FALSE)? -1: 0; return (FlushFileBuffers (fio->handle) == FALSE)? -1: 0;
#elif defined(__OS2__) #elif defined(__OS2__)
return (DosResetBuffer (fio->handle) == NO_ERROR)? 0: -1; return (DosResetBuffer (fio->handle) == NO_ERROR)? 0: -1;
#elif defined(__DOS__) #elif defined(__DOS__)
/* UNSUPPORTED */
return -1; return fsync (fio->handle);
#else #else
return QSE_FSYNC (fio->handle); return QSE_FSYNC (fio->handle);
#endif #endif
} }

View File

@ -148,11 +148,11 @@ release/os2/lib/scm/qsescm.tgt
VComponent VComponent
34 34
WRect WRect
3100 2490
1440 146
5700 5700
4240 4240
0 1
0 0
35 35
WFileName WFileName
@ -264,7 +264,7 @@ WRect
80 80
5700 5700
4240 4240
0 1
0 0
56 56
WFileName WFileName
@ -296,7 +296,7 @@ WRect
880 880
5700 5700
4240 4240
0 1
0 0
62 62
WFileName WFileName
@ -308,16 +308,16 @@ debug/os2/cmd/awk/qseawk.tgt
VComponent VComponent
64 64
WRect WRect
430 1070
2480 760
5700 5700
4240 4240
0 1
0 0
65 65
WFileName WFileName
30 30
debug/dos32/lib/cmn/qsecmn.tgt debug/dos32/lib/cmn/qsecmn.tgt
0 0
3 7
63 33