added more code for OS/2 file operations

This commit is contained in:
hyung-hwan 2011-03-15 21:40:39 +00:00
parent f84872aee3
commit 3822b48eea
7 changed files with 109 additions and 42 deletions

View File

@ -45,13 +45,20 @@
#if defined(_WIN32) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
# if defined(QSE_CHAR_IS_MCHAR) # if defined(QSE_CHAR_IS_MCHAR)
# define qse_main main # define qse_main main
# define QSE_ACHAR_IS_MCHAR
typedef qse_mchar_t qse_achar_t; typedef qse_mchar_t qse_achar_t;
# else # else
# define qse_main wmain # define qse_main wmain
# define QSE_ACHAR_IS_WCHAR
typedef qse_wchar_t qse_achar_t; typedef qse_wchar_t qse_achar_t;
# endif # endif
#elif defined(__OS2__)
# define qse_main main
# define QSE_ACHAR_IS_MCHAR
typedef qse_mchar_t qse_achar_t;
#else #else
# define qse_main main # define qse_main main
# define QSE_ACHAR_IS_MCHAR
typedef qse_mchar_t qse_achar_t; typedef qse_mchar_t qse_achar_t;
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: conf_msw.h 287 2009-09-15 10:01:02Z hyunghwan.chung $ * $Id: conf_msw.h 397 2011-03-15 03:40:39Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -45,7 +45,7 @@ _M_X64 x64 platform
#define QSE_SIZEOF_LONG 4 #define QSE_SIZEOF_LONG 4
/*#endif*/ /*#endif*/
#if defined(__POCC__) || defined(__DMC__) #if defined(__POCC__) || defined(__DMC__) || defined(__GNUC__)
/* pelles c with no microsoft extension */ /* pelles c with no microsoft extension */
#define QSE_SIZEOF_LONG_LONG 8 #define QSE_SIZEOF_LONG_LONG 8
@ -53,7 +53,6 @@ _M_X64 x64 platform
#define QSE_SIZEOF___INT16 0 #define QSE_SIZEOF___INT16 0
#define QSE_SIZEOF___INT32 0 #define QSE_SIZEOF___INT32 0
#define QSE_SIZEOF___INT64 0 #define QSE_SIZEOF___INT64 0
#define QSE_SIZEOF___INT96 0
#define QSE_SIZEOF___INT128 0 #define QSE_SIZEOF___INT128 0
#else #else
#define QSE_SIZEOF_LONG_LONG 0 #define QSE_SIZEOF_LONG_LONG 0
@ -62,7 +61,6 @@ _M_X64 x64 platform
#define QSE_SIZEOF___INT16 2 #define QSE_SIZEOF___INT16 2
#define QSE_SIZEOF___INT32 4 #define QSE_SIZEOF___INT32 4
#define QSE_SIZEOF___INT64 8 #define QSE_SIZEOF___INT64 8
#define QSE_SIZEOF___INT96 0
#define QSE_SIZEOF___INT128 0 #define QSE_SIZEOF___INT128 0
#endif #endif

View File

@ -26,13 +26,25 @@
#define QSE_SIZEOF_LONG 4 #define QSE_SIZEOF_LONG 4
#define QSE_SIZEOF_LONG_LONG 0 #if defined(__GNUC__)
#define QSE_SIZEOF___INT8 1 # define QSE_SIZEOF_LONG_LONG 8
#define QSE_SIZEOF___INT16 2 # define QSE_SIZEOF___INT8 0
#define QSE_SIZEOF___INT32 4 # define QSE_SIZEOF___INT16 0
#define QSE_SIZEOF___INT64 8 # define QSE_SIZEOF___INT32 0
#define QSE_SIZEOF___INT96 0 # define QSE_SIZEOF___INT64 0
#define QSE_SIZEOF___INT128 0 # define QSE_SIZEOF___INT128 0
#else
# if defined(__WATCOMC__)
# define QSE_SIZEOF_LONG_LONG 8
# else
# define QSE_SIZEOF_LONG_LONG 0
# endif
# define QSE_SIZEOF___INT8 1
# define QSE_SIZEOF___INT16 2
# define QSE_SIZEOF___INT32 4
# define QSE_SIZEOF___INT64 8
# define QSE_SIZEOF___INT128 0
#endif
#define QSE_SIZEOF_VOID_P 4 #define QSE_SIZEOF_VOID_P 4
#define QSE_SIZEOF_FLOAT 4 #define QSE_SIZEOF_FLOAT 4
@ -41,4 +53,4 @@
#define QSE_SIZEOF_WCHAR_T 2 #define QSE_SIZEOF_WCHAR_T 2
#define QSE_SIZEOF_OFF64_T 0 #define QSE_SIZEOF_OFF64_T 0
#define QSE_SIZEOF_OFF_T 4 #define QSE_SIZEOF_OFF_T 8

View File

@ -1,5 +1,5 @@
/* /*
* $Id: conf_vms.h 287 2009-09-15 10:01:02Z hyunghwan.chung $ * $Id: conf_vms.h 397 2011-03-15 03:40:39Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -55,7 +55,6 @@
#define QSE_SIZEOF___INT64 0 #define QSE_SIZEOF___INT64 0
#endif #endif
#define QSE_SIZEOF___INT96 0
#define QSE_SIZEOF___INT128 0 #define QSE_SIZEOF___INT128 0
#if defined(vax) || defined(__vax) #if defined(vax) || defined(__vax)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: fio.c 396 2011-03-14 15:40:35Z hyunghwan.chung $ * $Id: fio.c 397 2011-03-15 03:40:39Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -27,6 +27,8 @@
# include <psapi.h> # include <psapi.h>
# include <tchar.h> # include <tchar.h>
#elif defined(__OS2__) #elif defined(__OS2__)
# define INCL_DOSFILEMGR
# define INCL_DOSERRORS
# include <os2.h> # include <os2.h>
#else #else
# include "syscall.h" # include "syscall.h"
@ -171,6 +173,10 @@ qse_fio_t* qse_fio_init (
APIRET ret; APIRET ret;
ULONG action_taken = 0; ULONG action_taken = 0;
ULONG open_action, open_mode; ULONG open_action, open_mode;
LONGLONG zero;
zero.ulLo = 0;
zero.ulHi = 0;
if (flags & QSE_FIO_CREATE) if (flags & QSE_FIO_CREATE)
{ {
@ -206,12 +212,14 @@ qse_fio_t* qse_fio_init (
path, /* file name */ path, /* file name */
&handle, /* file handle */ &handle, /* file handle */
&action_taken, /* store action taken */ &action_taken, /* store action taken */
(LONGLONG)0, /* size */ zero, /* size */
FILE_NORMAL, /* attribute */ FILE_NORMAL, /* attribute */
open_action, /* action if it exists */ open_action, /* action if it exists */
open_mode /* open mode */ open_mode, /* open mode */
0L 0L
); );
if (ret != NO_ERROR) return QSE_NULL;
} }
#else #else
@ -355,8 +363,26 @@ qse_fio_off_t qse_fio_seek (
return (qse_fio_off_t)x.QuadPart; return (qse_fio_off_t)x.QuadPart;
*/ */
#elif defined(__OS2__) #elif defined(__OS2__)
# error NOT IMPLEMENTED static int seek_map[] =
{
FILE_BEGIN,
FILE_CURRENT,
FILE_END
};
LONGLONG pos, newpos;
APIRET ret;
QSE_ASSERT (QSE_SIZEOF(offset) >= QSE_SIZEOF(pos));
pos.ulLo = (ULONG)(offset&0xFFFFFFFFlu);
pos.ulHi = (ULONG)(offset>>32);
ret = DosSetFilePtrL (fio->handle, pos, seek_map[origin], &newpos);
if (ret != NO_ERROR) return (qse_fio_off_t)-1;
return ((qse_fio_off_t)pos.ulHi << 32) | pos.ulLo;
#else #else
static int seek_map[] = static int seek_map[] =
{ {
@ -400,8 +426,13 @@ int qse_fio_truncate (qse_fio_t* fio, qse_fio_off_t size)
return 0; return 0;
#elif defined(__OS2__) #elif defined(__OS2__)
APIRET ret; APIRET ret;
LONGLONG sz;
/* the file must have the write access for it to succeed */ /* the file must have the write access for it to succeed */
ret = DosSetFileSizeL (fio->handle, 0);
sz.ulLo = (ULONG)(size&0xFFFFFFFFlu);
sz.ulHi = (ULONG)(size>>32);
ret = DosSetFileSizeL (fio->handle, sz);
return (ret == NO_ERROR)? 0: -1; return (ret == NO_ERROR)? 0: -1;
#else #else
return QSE_FTRUNCATE (fio->handle, size); return QSE_FTRUNCATE (fio->handle, size);
@ -413,10 +444,13 @@ 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, 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__)
# error NOT IMPLEMENTED ULONG count;
if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG);
if (DosRead (fio->handle, buf, (ULONG)size, &count) != NO_ERROR) return -1;
return (qse_ssize_t)count;
#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);
@ -436,10 +470,13 @@ 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, 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__)
# error NOT IMPLEMENTED ULONG count;
if (size > QSE_TYPE_MAX(ULONG)) size = QSE_TYPE_MAX(ULONG);
if (DosWrite(fio->handle, (PVOID)data, (ULONG)size, &count) != NO_ERROR) return -1;
return (qse_ssize_t)count;
#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);
@ -570,7 +607,16 @@ 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__)
# error NOT IMPLEMENTED int flags = FILE_NORMAL;
FILESTATUS3L stat;
ULONG size = QSE_SIZEOF(stat);
if (DosQueryFileInfo (fio->handle, FIL_STANDARDL, &stat, size) != NO_ERROR) return -1;
if (!(mode & QSE_FIO_WUSR)) flags = FILE_READONLY;
stat.attrFile = flags;
return (DosSetFileInfo (fio->handle, FIL_STANDARDL, &stat, size) != NO_ERROR)? -1: 0;
#else #else
return QSE_FCHMOD (fio->handle, mode); return QSE_FCHMOD (fio->handle, mode);
#endif #endif

View File

@ -27,12 +27,13 @@ int qse_runmain (
int argc, qse_achar_t* argv[], qse_runmain_handler_t handler) int argc, qse_achar_t* argv[], qse_runmain_handler_t handler)
{ {
setlocale (LC_ALL, ""); /* TODO: remove dependency on setlocale */ setlocale (LC_ALL, ""); /* TODO: remove dependency on setlocale */
if (QSE_SIZEOF(qse_achar_t) == QSE_SIZEOF(qse_char_t)) #if (defined(QSE_ACHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR)) || \
(defined(QSE_ACHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR))
{ {
return handler (argc, (qse_char_t**)argv); return handler (argc, (qse_char_t**)argv);
} }
else #else
{ {
int i, ret; int i, ret;
qse_char_t** v; qse_char_t** v;
@ -83,21 +84,22 @@ int qse_runmain (
} }
QSE_MMGR_FREE (mmgr, v); QSE_MMGR_FREE (mmgr, v);
return ret; return ret;
} #endif
} }
int qse_runmainwithenv ( int qse_runmainwithenv (
int argc, qse_achar_t* argv[], int argc, qse_achar_t* argv[],
qse_achar_t* envp[], qse_runmainwithenv_handler_t handler) qse_achar_t* envp[], qse_runmainwithenv_handler_t handler)
{ {
setlocale (LC_ALL, ""); /* TODO: remove dependency on setlocale */ setlocale (LC_ALL, ""); /* TODO: remove dependency on setlocale */
if (QSE_SIZEOF(qse_achar_t) == QSE_SIZEOF(qse_char_t)) #if (defined(QSE_ACHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR)) || \
(defined(QSE_ACHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR))
{ {
return handler (argc, (qse_char_t**)argv, (qse_char_t**)envp); return handler (argc, (qse_char_t**)argv, (qse_char_t**)envp);
} }
else #else
{ {
int i, ret, envc; int i, ret, envc;
qse_char_t** v; qse_char_t** v;
@ -156,5 +158,6 @@ int qse_runmainwithenv (
QSE_MMGR_FREE (mmgr, v); QSE_MMGR_FREE (mmgr, v);
return ret; return ret;
} }
#endif
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: pio.c 368 2010-11-03 14:24:29Z hyunghwan.chung $ * $Id: pio.c 397 2011-03-15 03:40:39Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -22,9 +22,11 @@
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include "mem.h" #include "mem.h"
#ifdef _WIN32 #if defined(_WIN32)
# include <windows.h> # include <windows.h>
# include <tchar.h> # include <tchar.h>
#elif defined(__OS2__)
# include <os2.h>
#else #else
# include "syscall.h" # include "syscall.h"
# include <fcntl.h> # include <fcntl.h>
@ -986,7 +988,7 @@ static qse_ssize_t pio_input (int cmd, void* arg, void* buf, qse_size_t size)
/* take no actions for OPEN and CLOSE as they are handled /* take no actions for OPEN and CLOSE as they are handled
* by pio */ * by pio */
return 0; return 0;
} }
static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size) static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size)
@ -1001,5 +1003,5 @@ static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size)
/* take no actions for OPEN and CLOSE as they are handled /* take no actions for OPEN and CLOSE as they are handled
* by pio */ * by pio */
return 0; return 0;
} }