diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index 86b589f1..8c556edf 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -1,5 +1,5 @@ /* - * $Id: fio.h 340 2010-08-01 13:13:38Z hyunghwan.chung $ + * $Id: fio.h 396 2011-03-14 15:40:35Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -78,9 +78,13 @@ enum qse_fio_mode_t QSE_FIO_XOTH = 00001 /* can be executed by others */ }; -#ifdef _WIN32 +#if defined (_WIN32) /* => typedef PVOID HANDLE; */ typedef void* qse_fio_hnd_t; +#elif defined(__OS2__) + /* => typedef LHANDLE HFILE; + typedef unsigned long LHANDLE; */ + typedef unsigned long qse_fio_hnd_t; #else typedef int qse_fio_hnd_t; #endif diff --git a/qse/include/qse/conf_os2.h b/qse/include/qse/conf_os2.h new file mode 100644 index 00000000..88550344 --- /dev/null +++ b/qse/include/qse/conf_os2.h @@ -0,0 +1,44 @@ +/* + * $Id: conf_msw.h 287 2009-09-15 10:01:02Z hyunghwan.chung $ + * + Copyright 2006-2009 Chung, Hyung-Hwan. + This file is part of QSE. + + QSE is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + QSE is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with QSE. If not, see . + */ + +#define QSE_ENDIAN_LITTLE + +#define QSE_SIZEOF_CHAR 1 +#define QSE_SIZEOF_SHORT 2 +#define QSE_SIZEOF_INT 4 + +#define QSE_SIZEOF_LONG 4 + +#define QSE_SIZEOF_LONG_LONG 0 +#define QSE_SIZEOF___INT8 1 +#define QSE_SIZEOF___INT16 2 +#define QSE_SIZEOF___INT32 4 +#define QSE_SIZEOF___INT64 8 +#define QSE_SIZEOF___INT96 0 +#define QSE_SIZEOF___INT128 0 + +#define QSE_SIZEOF_VOID_P 4 +#define QSE_SIZEOF_FLOAT 4 +#define QSE_SIZEOF_DOUBLE 8 +#define QSE_SIZEOF_LONG_DOUBLE 16 +#define QSE_SIZEOF_WCHAR_T 2 + +#define QSE_SIZEOF_OFF64_T 0 +#define QSE_SIZEOF_OFF_T 4 diff --git a/qse/include/qse/types.h b/qse/include/qse/types.h index a37fe40e..59cd9038 100644 --- a/qse/include/qse/types.h +++ b/qse/include/qse/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h 389 2011-02-25 15:26:16Z hyunghwan.chung $ + * $Id: types.h 396 2011-03-14 15:40:35Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -36,6 +36,8 @@ # include #elif defined(vms) || defined(__vms) # include +#elif defined(OS2) || defined(__OS2__) +# include #else # error unsupported operating system #endif @@ -398,6 +400,10 @@ typedef int qse_mcint_t; # define QSE_CHAR_IS_WCHAR typedef qse_wchar_t qse_char_t; typedef qse_wcint_t qse_cint_t; +#elif defined(__OS2__) +# define QSE_CHAR_IS_MCHAR + typedef qse_mchar_t qse_char_t; + typedef qse_mcint_t qse_cint_t; #else # if defined(QSE_CHAR_IS_MCHAR) typedef qse_mchar_t qse_char_t; diff --git a/qse/lib/cmn/assert.c b/qse/lib/cmn/assert.c index 84e5d6c2..9131e2a5 100644 --- a/qse/lib/cmn/assert.c +++ b/qse/lib/cmn/assert.c @@ -31,8 +31,10 @@ # include #endif -#ifdef _WIN32 -# include +#if defined(_WIN32) +# include +#elif defined(__OS2__) +# include #else # include "syscall.h" #endif @@ -147,8 +149,10 @@ void qse_assert_failed ( qse_sio_puts (QSE_SIO_ERR, QSE_T("================================================================================\n")); qse_sio_flush (QSE_SIO_ERR); -#ifdef _WIN32 - ExitProcess (1); +#if defined(_WIN32) + ExitProcess (1); +#elif defined(__OS2__) + DosExit (EXIT_PROCESS, 1); #else QSE_KILL (QSE_GETPID(), SIGABRT); QSE_EXIT (1); diff --git a/qse/lib/cmn/chr_cnv.c b/qse/lib/cmn/chr_cnv.c index a07f2943..ab27dcf2 100644 --- a/qse/lib/cmn/chr_cnv.c +++ b/qse/lib/cmn/chr_cnv.c @@ -1,5 +1,5 @@ /* - * $Id: chr_cnv.c 323 2010-04-05 12:50:01Z hyunghwan.chung $ + * $Id: chr_cnv.c 396 2011-03-14 15:40:35Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -20,12 +20,22 @@ #include #include "mem.h" + +#if !defined(QSE_HAVE_CONFIG_H) +# if defined(_WIN32) || defined(__OS2__) +# define HAVE_WCHAR_H +# define HAVE_STDLIB_H +# define HAVE_MBRLEN +# define HAVE_MBRTOWC +# define HAVE_WCRTOMB +# endif +#endif #ifdef HAVE_WCHAR_H -#include +# include #endif #ifdef HAVE_STDLIB_H -#include +# include #endif qse_size_t qse_mblen (const qse_mchar_t* mb, qse_size_t mblen) diff --git a/qse/lib/cmn/dll.c b/qse/lib/cmn/dll.c index e5ec58d8..57a210bc 100644 --- a/qse/lib/cmn/dll.c +++ b/qse/lib/cmn/dll.c @@ -1,5 +1,5 @@ /* - * $Id: dll.c 354 2010-09-03 12:50:08Z hyunghwan.chung $ + * $Id: dll.c 396 2011-03-14 15:40:35Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -107,7 +107,8 @@ int qse_dll_getscale (qse_dll_t* dll) void qse_dll_setscale (qse_dll_t* dll, int scale) { QSE_ASSERTX (scale > 0 && scale <= QSE_TYPE_MAX(qse_byte_t), - "The scale should be larger than 0 and less than or equal to the maximum value that the qse_byte_t type can hold"); + "The scale should be larger than 0 and less than or equal to the maximum value that the qse_byte_t type can hold" + ); if (scale <= 0) scale = 1; if (scale > QSE_TYPE_MAX(qse_byte_t)) scale = QSE_TYPE_MAX(qse_byte_t); diff --git a/qse/lib/cmn/fio.c b/qse/lib/cmn/fio.c index 45569cfb..b82a7a5e 100644 --- a/qse/lib/cmn/fio.c +++ b/qse/lib/cmn/fio.c @@ -1,5 +1,5 @@ /* - * $Id: fio.c 348 2010-08-26 06:26:28Z hyunghwan.chung $ + * $Id: fio.c 396 2011-03-14 15:40:35Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. This file is part of QSE. @@ -22,10 +22,12 @@ #include #include "mem.h" -#ifdef _WIN32 +#if defined(_WIN32) # include # include -# include +# include +#elif defined(__OS2__) +# include #else # include "syscall.h" # include @@ -86,7 +88,7 @@ qse_fio_t* qse_fio_init ( QSE_MEMSET (fio, 0, QSE_SIZEOF(*fio)); fio->mmgr = mmgr; -#ifdef _WIN32 +#if defined(_WIN32) if (flags & QSE_FIO_HANDLE) { handle = *(qse_fio_hnd_t*)path; @@ -156,7 +158,61 @@ qse_fio_t* qse_fio_init ( } } - /* TODO: support more features on WIN32 - TEMPORARY, DELETE_ON_CLOSE */ + /* TODO: support more features on WIN32 - TEMPORARY, DELETE_ON_CLOSE */ + +#elif defined(__OS2__) + + if (flags & QSE_FIO_HANDLE) + { + handle = *(qse_fio_hnd_t*)path; + } + else + { + APIRET ret; + ULONG action_taken = 0; + ULONG open_action, open_mode; + + if (flags & QSE_FIO_CREATE) + { + if (flags & QSE_FIO_EXCLUSIVE) + { + open_action = OPEN_ACTION_FAIL_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW; + } + else if (flags & QSE_FIO_TRUNCATE) + { + open_action = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW; + } + else + { + open_action = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS; + } + } + else if (flags & QSE_FIO_TRUNCATE) + { + open_action = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; + } + else + { + open_action = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; + } + + open_mode = OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE; + if ((flags & QSE_FIO_READ) && + (flags & QSE_FIO_WRITE)) open_mode |= OPEN_ACCESS_READWRITE; + else if (flags & QSE_FIO_READ) open_mode |= OPEN_ACCESS_READONLY; + else if (flags & QSE_FIO_WRITE) open_mode |= OPEN_ACCESS_WRITEONLY; + + ret = DosOpenL ( + path, /* file name */ + &handle, /* file handle */ + &action_taken, /* store action taken */ + (LONGLONG)0, /* size */ + FILE_NORMAL, /* attribute */ + open_action, /* action if it exists */ + open_mode /* open mode */ + 0L + ); + } #else if (flags & QSE_FIO_HANDLE) @@ -226,10 +282,12 @@ qse_fio_t* qse_fio_init ( QSE_CATCH_ERR (tio) { - #ifdef _WIN32 - CloseHandle (handle); + #if defined(_WIN32) + CloseHandle (handle); + #elif defined(__OS2__) + DosClose (handle); #else - QSE_CLOSE (handle); + QSE_CLOSE (handle); #endif return QSE_NULL; } @@ -245,8 +303,10 @@ qse_fio_t* qse_fio_init ( void qse_fio_fini (qse_fio_t* fio) { if (fio->tio != QSE_NULL) qse_tio_close (fio->tio); -#ifdef _WIN32 - CloseHandle (fio->handle); +#if defined(_WIN32) + CloseHandle (fio->handle); +#elif defined(__OS2__) + DosClose (fio->handle); #else QSE_CLOSE (fio->handle); #endif @@ -265,7 +325,7 @@ void qse_fio_sethandle (qse_fio_t* fio, qse_fio_hnd_t handle) qse_fio_off_t qse_fio_seek ( qse_fio_t* fio, qse_fio_off_t offset, qse_fio_ori_t origin) { -#ifdef _WIN32 +#if defined(_WIN32) static int seek_map[] = { FILE_BEGIN, @@ -294,12 +354,13 @@ qse_fio_off_t qse_fio_seek ( } return (qse_fio_off_t)x.QuadPart; - */ - + */ +#elif defined(__OS2__) +# error NOT IMPLEMENTED #else static int seek_map[] = { - SEEK_SET, + SEEK_SET, SEEK_CUR, SEEK_END }; @@ -336,7 +397,12 @@ int qse_fio_truncate (qse_fio_t* fio, qse_fio_off_t size) if (SetFilePointerEx(fio->handle,x,NULL,FILE_BEGIN) == FALSE || SetEndOfFile(fio->handle) == FALSE) return -1; - return 0; + return 0; +#elif defined(__OS2__) + APIRET ret; + /* the file must have the write access for it to succeed */ + ret = DosSetFileSizeL (fio->handle, 0); + return (ret == NO_ERROR)? 0: -1; #else return QSE_FTRUNCATE (fio->handle, size); #endif @@ -344,11 +410,13 @@ 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) { -#ifdef _WIN32 +#if defined(_WIN32) DWORD count; if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD); if (ReadFile(fio->handle, buf, size, &count, QSE_NULL) == FALSE) return -1; - return (qse_ssize_t)count; + return (qse_ssize_t)count; +#elif defined(__OS2__) +# error NOT IMPLEMENTED #else if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t); return QSE_READ (fio->handle, buf, size); @@ -365,11 +433,13 @@ qse_ssize_t qse_fio_read (qse_fio_t* fio, void* buf, qse_size_t size) static qse_ssize_t fio_write (qse_fio_t* fio, const void* data, qse_size_t size) { -#ifdef _WIN32 +#if defined(_WIN32) DWORD count; if (size > QSE_TYPE_MAX(DWORD)) size = QSE_TYPE_MAX(DWORD); if (WriteFile(fio->handle, data, size, &count, QSE_NULL) == FALSE) return -1; - return (qse_ssize_t)count; + return (qse_ssize_t)count; +#elif defined(__OS2__) +# error NOT IMPLEMENTED #else if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t); return QSE_WRITE (fio->handle, data, size); @@ -386,8 +456,8 @@ qse_ssize_t qse_fio_write (qse_fio_t* fio, const void* data, qse_size_t size) qse_ssize_t qse_fio_flush (qse_fio_t* fio) { - if (fio->tio == QSE_NULL) return 0; - return qse_tio_flush (fio->tio); + if (fio->tio == QSE_NULL) return 0; + return qse_tio_flush (fio->tio); } @@ -435,7 +505,6 @@ static int get_devname_from_handle ( static int get_volname_from_handle ( HANDLE handle, qse_char_t* buf, qse_size_t len) { - if (get_devname_from_handle (handle, buf, len) == -1) return -1; if (_tcsnicmp(QSE_T("\\Device\\LanmanRedirector\\"), buf, 25) == 0) @@ -488,18 +557,20 @@ static int get_volname_from_handle ( int qse_fio_chmod (qse_fio_t* fio, int mode) { -#ifdef _WIN32 +#if defined(_WIN32) int flags = FILE_ATTRIBUTE_NORMAL; qse_char_t name[MAX_PATH]; /* it is a best effort implementation. if the file size is 0, - * it can't even get the file name from the handle and thus fails. */ - + * it can't even get the file name from the handle and thus fails. + */ if (get_volname_from_handle ( fio->handle, name, QSE_COUNTOF(name)) == -1) return -1; 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__) +# error NOT IMPLEMENTED #else return QSE_FCHMOD (fio->handle, mode); #endif @@ -507,8 +578,10 @@ int qse_fio_chmod (qse_fio_t* fio, int mode) int qse_fio_sync (qse_fio_t* fio) { -#ifdef _WIN32 - return (FlushFileBuffers (fio->handle) == FALSE)? -1: 0; +#if defined(_WIN32) + return (FlushFileBuffers (fio->handle) == FALSE)? -1: 0; +#elif defined(__OS2__) + return (DosResetBuffer (fio->handle) == NO_ERROR)? 0: -1; #else return QSE_FSYNC (fio->handle); #endif @@ -536,28 +609,28 @@ int qse_fio_unlock (qse_fio_t* fio, qse_fio_lck_t* lck, int flags) static qse_ssize_t fio_input (int cmd, void* arg, void* buf, qse_size_t size) { - qse_fio_t* fio = (qse_fio_t*)arg; - QSE_ASSERT (fio != QSE_NULL); - if (cmd == QSE_TIO_IO_DATA) + qse_fio_t* fio = (qse_fio_t*)arg; + QSE_ASSERT (fio != QSE_NULL); + if (cmd == QSE_TIO_IO_DATA) { return fio_read (fio, buf, size); } /* take no actions for OPEN and CLOSE as they are handled * by fio */ - return 0; + return 0; } static qse_ssize_t fio_output (int cmd, void* arg, void* buf, qse_size_t size) { - qse_fio_t* fio = (qse_fio_t*)arg; - QSE_ASSERT (fio != QSE_NULL); - if (cmd == QSE_TIO_IO_DATA) + qse_fio_t* fio = (qse_fio_t*)arg; + QSE_ASSERT (fio != QSE_NULL); + if (cmd == QSE_TIO_IO_DATA) { return fio_write (fio, buf, size); } /* take no actions for OPEN and CLOSE as they are handled * by fio */ - return 0; + return 0; }