diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index 7e2d1228..be5437ce 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -1,5 +1,5 @@ /* - * $Id: fio.h 504 2011-07-11 16:31:33Z hyunghwan.chung $ + * $Id: fio.h 550 2011-08-14 15:59:55Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -235,6 +235,12 @@ qse_ssize_t qse_fio_flush ( /** * The qse_fio_chmod() function changes the file mode. + * + * @note + * On _WIN32, this function is implemented on the best-effort basis and + * returns an error on the following conditions: + * - The file size is 0. + * - The file is opened without #QSE_FIO_READ. */ int qse_fio_chmod ( qse_fio_t* fio, diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 8b9246a3..805260d9 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1,5 +1,5 @@ /* - * $Id: str.h 549 2011-08-14 09:07:31Z hyunghwan.chung $ + * $Id: str.h 550 2011-08-14 15:59:55Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -1341,16 +1341,28 @@ qse_wchar_t* qse_wcsxnbeg ( qse_size_t len2 ); +qse_mchar_t* qse_mbscasebeg ( + const qse_mchar_t* str, + const qse_mchar_t* sub +); + +qse_wchar_t* qse_wcscasebeg ( + const qse_wchar_t* str, + const qse_wchar_t* sub +); + #ifdef QSE_CHAR_IS_MCHAR # define qse_strbeg(str,sub) qse_mbsbeg(str,sub) # define qse_strxbeg(str,len,sub) qse_mbsxbeg(str,len,sub) # define qse_strnbeg(str,sub,len) qse_mbsnbeg(str,sub,len) # define qse_strxnbeg(str,len1,sub,len2) qse_mbsxnbeg(str,len1,sub,len2) +# define qse_strcasebeg(str,sub) qse_mbscasebeg(str,sub) #else # define qse_strbeg(str,sub) qse_wcsbeg(str,sub) # define qse_strxbeg(str,len,sub) qse_wcsxbeg(str,len,sub) # define qse_strnbeg(str,sub,len) qse_wcsnbeg(str,sub,len) # define qse_strxnbeg(str,len1,sub,len2) qse_wcsxnbeg(str,len1,sub,len2) +# define qse_strcasebeg(str,sub) qse_wcscasebeg(str,sub) #endif /** diff --git a/qse/lib/cmn/env.c b/qse/lib/cmn/env.c index 91a37c7e..0914fff8 100644 --- a/qse/lib/cmn/env.c +++ b/qse/lib/cmn/env.c @@ -23,8 +23,6 @@ #include #include "mem.h" -#include - #if defined(_WIN32) # include #endif diff --git a/qse/lib/cmn/fio.c b/qse/lib/cmn/fio.c index cf3f82af..8f7a1113 100644 --- a/qse/lib/cmn/fio.c +++ b/qse/lib/cmn/fio.c @@ -1,5 +1,5 @@ /* - * $Id: fio.c 452 2011-05-04 15:11:23Z hyunghwan.chung $ + * $Id: fio.c 550 2011-08-14 15:59:55Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -650,7 +650,7 @@ static int get_devname_from_handle ( /* create a file mapping object */ map = CreateFileMapping ( handle, - NULL, + NULL, PAGE_READONLY, 0, 1, @@ -684,10 +684,10 @@ static int get_volname_from_handle ( { if (get_devname_from_handle (handle, buf, len) == -1) return -1; - if (_tcsnicmp(QSE_T("\\Device\\LanmanRedirector\\"), buf, 25) == 0) + if (qse_strcasebeg (buf, QSE_T("\\Device\\LanmanRedirector\\"))) { - buf[0] = QSE_T('\\'); - _tcscpy (&buf[1], &buf[24]); + /*buf[0] = QSE_T('\\');*/ + qse_strcpy (&buf[1], &buf[24]); } else { @@ -712,14 +712,14 @@ static int get_volname_from_handle ( drv[2] = QSE_T('\0'); if (QueryDosDevice (drv, path, QSE_COUNTOF(path))) { - qse_size_t pl = _tcslen(path); - qse_size_t bl = _tcslen(buf); + qse_size_t pl = qse_strlen(path); + qse_size_t bl = qse_strlen(buf); if (bl > pl && buf[pl] == QSE_T('\\') && - _tcsnicmp(path, buf, pl) == 0) + qse_strxncasecmp(buf, pl, path, pl) == 0) { buf[0] = drv[0]; buf[1] = QSE_T(':'); - _tcscpy (&buf[2], &buf[pl]); + qse_strcpy (&buf[2], &buf[pl]); break; } } @@ -741,6 +741,8 @@ int qse_fio_chmod (qse_fio_t* fio, int mode) /* 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. + * if GENERIC_READ is not set in CreateFile, CreateFileMapping fails. + * so if this fio is opened without QSE_FIO_READ, this function fails. */ if (get_volname_from_handle ( fio->handle, name, QSE_COUNTOF(name)) == -1) return -1; diff --git a/qse/lib/cmn/opt.c b/qse/lib/cmn/opt.c index 8942bd33..af9307a9 100644 --- a/qse/lib/cmn/opt.c +++ b/qse/lib/cmn/opt.c @@ -1,5 +1,5 @@ /* - * $Id: opt.c 462 2011-05-18 14:36:40Z hyunghwan.chung $ + * $Id: opt.c 550 2011-08-14 15:59:55Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -55,10 +55,6 @@ * -------------------------------------------------------------------------- */ -#include -#include -#include - #define BADCH QSE_T('?') #define BADARG QSE_T(':') #define EMSG QSE_T("") diff --git a/qse/lib/cmn/str_beg.c b/qse/lib/cmn/str_beg.c index 0b5c8b4b..4b42ad40 100644 --- a/qse/lib/cmn/str_beg.c +++ b/qse/lib/cmn/str_beg.c @@ -1,5 +1,5 @@ /* - * $Id: str_beg.c 443 2011-04-25 14:56:05Z hyunghwan.chung $ + * $Id: str_beg.c 550 2011-08-14 15:59:55Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -19,6 +19,7 @@ */ #include +#include qse_mchar_t* qse_mbsbeg (const qse_mchar_t* str, const qse_mchar_t* sub) { @@ -83,6 +84,18 @@ qse_mchar_t* qse_mbsxnbeg ( return (qse_mchar_t*)str; } +qse_mchar_t* qse_mbscasebeg (const qse_mchar_t* str, const qse_mchar_t* sub) +{ + while (*sub != QSE_MT('\0')) + { + if (QSE_TOMUPPER(*str) != QSE_TOMUPPER(*sub)) return QSE_NULL; + str++; sub++; + } + + /* returns the pointer to the next character of the match */ + return (qse_mchar_t*)str; +} + qse_wchar_t* qse_wcsbeg (const qse_wchar_t* str, const qse_wchar_t* sub) { while (*sub != QSE_WT('\0')) @@ -146,3 +159,14 @@ qse_wchar_t* qse_wcsxnbeg ( return (qse_wchar_t*)str; } +qse_wchar_t* qse_wcscasebeg (const qse_wchar_t* str, const qse_wchar_t* sub) +{ + while (*sub != QSE_WT('\0')) + { + if (QSE_TOWUPPER(*str) != QSE_TOWUPPER(*sub)) return QSE_NULL; + str++; sub++; + } + + /* returns the pointer to the next character of the match */ + return (qse_wchar_t*)str; +} diff --git a/qse/samples/cmn/fio.c b/qse/samples/cmn/fio.c index 3c66a3c1..1fee2efe 100644 --- a/qse/samples/cmn/fio.c +++ b/qse/samples/cmn/fio.c @@ -80,6 +80,15 @@ static int test1 (void) n = qse_fio_write (fio, x2, qse_mbslen(x2)); qse_printf (QSE_T("written %d bytes\n"), (int)n); + if (qse_fio_chmod (fio, QSE_FIO_RUSR|QSE_FIO_RGRP) <= -1) + { + qse_printf (QSE_T("failed to change mode\n")); + } + else + { + qse_printf (QSE_T("changed mode\n")); + } + qse_fio_close (fio); return 0; @@ -187,7 +196,17 @@ static int test2 (void) qse_printf (QSE_T("file offset at %lld\n"), (long long)off); } - qse_fio_chmod (fio, QSE_FIO_RUSR|QSE_FIO_RGRP); + /* on _WIN32, this will fail as this file is opened without + * QSE_FIO_READ. */ + if (qse_fio_chmod (fio, QSE_FIO_RUSR|QSE_FIO_RGRP) <= -1) + { + qse_printf (QSE_T("failed to change mode\n")); + } + else + { + qse_printf (QSE_T("changed mode\n")); + } + qse_fio_close (fio); return 0; diff --git a/qse/samples/cmn/xma.c b/qse/samples/cmn/xma.c index 87312560..d84e09f0 100644 --- a/qse/samples/cmn/xma.c +++ b/qse/samples/cmn/xma.c @@ -165,7 +165,7 @@ static int test5 () return -1; } - xmammgr.xma = xma1; + xmammgr.ctx = xma1; xma2 = qse_xma_open (&xmammgr, 0, 500000L); if (xma1 == QSE_NULL)