implemented qse_fio_chmod() for win32 and unix

- on win32, it is a best effort implemention.
- it gets the volume name from a handle and use SetFileAttributes().
fixed the problem of wrongly detecting objdump.
- place AC_PROG_LIBTOOL after any AC_CHECK_TOOL.
- otherwise, AC_PROG_LIBTOOL overrides the value of tools checked.
This commit is contained in:
hyung-hwan 2008-12-27 02:52:47 +00:00
parent 359beea51e
commit 39c4afe129
24 changed files with 1322 additions and 675 deletions

View File

@ -121,6 +121,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -131,7 +132,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -99,6 +99,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -109,7 +110,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -132,6 +132,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -142,7 +143,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -114,6 +114,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -124,7 +125,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -113,6 +113,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -123,7 +124,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

1654
qse/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -18,17 +18,21 @@ AC_PROG_CXX
dnl checks if the C++ compiler exists in PATH.
AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_CHECK_TOOL(RANLIB, ranlib)
AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(RANLIB, ranlib)
AC_CHECK_TOOL(STRIP, strip)
AC_CHECK_TOOL(OBJDUMP, objdump)
AC_CHECK_TOOL(NM, nm)
AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(GREP, grep)
AC_CHECK_TOOL(RM, rm)
AC_CHECK_TOOL(SED, sed)
AC_CHECK_TOOL(CJ, gcj)
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
dnl overrides the default CFLAGS setting
#if test "$ac_test_CFLAGS" = "set"
#then
@ -70,6 +74,13 @@ dnl make visible the 64bit interface to the file system
CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -DQSE_HAVE_CONFIG_H"
CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE -DQSE_HAVE_CONFIG_H"
case "$host" in
*-*-mingw*|*-*-cygwin*)
#CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0400"
platform_win32=yes
esac
AM_CONDITIONAL(WIN32, test "${platform_win32}" = "yes" )
dnl Checks for the math library (is -lm needed?)
AC_CHECK_LIBM
AC_SUBST(LIBM, $LIBM)
@ -327,6 +338,7 @@ echo
echo "-[SUMMARY]---------------------------------------------------------------"
echo "Configured for ${host}"
echo " Build mode : ${BUILD_MODE}"
echo " Source directory: ${srcdir}"
echo " Installation directory: ${prefix}"
echo " C compiler: ${CC} ${CFLAGS}"
echo " C++ compiler: ${CXX} ${CXXFLAGS}"

View File

@ -102,6 +102,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -112,7 +113,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -111,6 +111,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -121,7 +122,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -103,6 +103,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -113,7 +114,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -101,6 +101,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -111,7 +112,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -11,20 +11,22 @@
enum qse_fio_open_flag_t
{
/* treat the file name pointer as a handle pointer */
QSE_FIO_HANDLE = (1 << 0),
QSE_FIO_HANDLE = (1 << 0),
QSE_FIO_READ = (1 << 1),
QSE_FIO_WRITE = (1 << 2),
QSE_FIO_APPEND = (1 << 3),
QSE_FIO_READ = (1 << 1),
QSE_FIO_WRITE = (1 << 2),
QSE_FIO_APPEND = (1 << 3),
QSE_FIO_CREATE = (1 << 4),
QSE_FIO_TRUNCATE = (1 << 5),
QSE_FIO_EXCLUSIVE = (1 << 6),
QSE_FIO_SYNC = (1 << 7),
QSE_FIO_CREATE = (1 << 4),
QSE_FIO_TRUNCATE = (1 << 5),
QSE_FIO_EXCLUSIVE = (1 << 6),
QSE_FIO_SYNC = (1 << 7),
/* for ms windows only */
QSE_FIO_NOSHRD = (1 << 16),
QSE_FIO_NOSHWR = (1 << 17)
/* for WIN32 only. harmless(no effect) when used on other platforms */
QSE_FIO_NOSHRD = (1 << 16),
QSE_FIO_NOSHWR = (1 << 17),
QSE_FIO_RANDOM = (1 << 18), /* hint that access be random */
QSE_FIO_SEQUENTIAL = (1 << 19) /* hint that access is sequential */
};
/* seek origin */
@ -35,9 +37,25 @@ enum qse_fio_seek_origin_t
QSE_FIO_END = 2
};
enum qse_fio_mode_t
{
QSE_FIO_SUID = 04000, /* set UID */
QSE_FIO_SGID = 02000, /* set GID */
QSE_FIO_SVTX = 01000, /* sticky bit */
QSE_FIO_RUSR = 00400, /* can be read by owner */
QSE_FIO_WUSR = 00200, /* can be written by owner */
QSE_FIO_XUSR = 00100, /* can be executed by owner */
QSE_FIO_RGRP = 00040, /* can be read by group */
QSE_FIO_WGRP = 00020, /* can be written by group */
QSE_FIO_XGRP = 00010, /* can be executed by group */
QSE_FIO_ROTH = 00004, /* can be read by others */
QSE_FIO_WOTH = 00002, /* can be written by others */
QSE_FIO_XOTH = 00001 /* can be executed by others */
};
#ifdef _WIN32
/* <winnt.h> typedef PVOID HANDLE; */
typedef void* qse_fio_hnd_t;
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* qse_fio_hnd_t;
#else
typedef int qse_fio_hnd_t;
#endif
@ -66,9 +84,9 @@ extern "C" {
* qse_fio_open - open a file
*
* DESCRIPTION
* To open a file, you should set the flags with at least one of
* To open a file, you should set the flags with at least one of
* QSE_FIO_READ, QSE_FIO_WRITE, QSE_FIO_APPEND.
*
*
* SYNOPSIS
*/
qse_fio_t* qse_fio_open (
@ -83,7 +101,7 @@ qse_fio_t* qse_fio_open (
/****f* qse.fio/qse_fio_close
* NAME
* qse_fio_close - close a file
*
*
* SYNOPSIS
*/
void qse_fio_close (
@ -108,7 +126,7 @@ qse_fio_hnd_t qse_fio_gethandle (
);
/****f* qse.cmn.fio/qse_fio_sethandle
* SYNOPSIS
* NAME
* qse_fio_sethandle - set the file handle
* WARNING
* Avoid using this function if you don't know what you are doing.
@ -145,6 +163,16 @@ qse_ssize_t qse_fio_write (
qse_size_t size
);
/****f* qse.cmn.fio/qse_fio_chmod
* NAME
* ase_fio_chmod - change the file mode
* SYNOPSIS
*/
int qse_fio_chmod (
qse_fio_t* fio,
int mode
);
#ifdef __cplusplus
}
#endif

View File

@ -101,6 +101,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -111,7 +112,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -101,6 +101,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -111,7 +112,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -101,6 +101,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -111,7 +112,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -1,6 +1,6 @@
/*
* $Id: main.h 463 2008-12-09 06:52:03Z baconevi $
*
*
* {License}
*/
@ -28,7 +28,7 @@ extern "C" {
#endif
int qse_runmain (int argc, qse_achar_t* argv[], int(*mf) (int,qse_char_t*[]));
/* TODO - qse_runmain with env */
/* TODO - qse_runmain with env, namely, qse_runmaine */
#ifdef __cplusplus
}

View File

@ -99,6 +99,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -109,7 +110,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -138,6 +138,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -148,7 +149,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -11,3 +11,7 @@ libqsecmn_la_SOURCES = mem.h chr.h \
misc.c
libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
if WIN32
libqsecmn_la_LIBADD = -lpsapi
endif

View File

@ -50,7 +50,7 @@ am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsecmn_la_LIBADD =
libqsecmn_la_DEPENDENCIES =
am_libqsecmn_la_OBJECTS = mem.lo chr.lo chr_cnv.lo rex.lo str_bas.lo \
str_cnv.lo str_dyn.lo lda.lo map.lo sll.lo dll.lo opt.lo \
fio.lo sio.lo tio.lo tio_get.lo tio_put.lo time.lo misc.lo
@ -120,6 +120,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -130,7 +131,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
@ -208,6 +211,7 @@ libqsecmn_la_SOURCES = mem.h chr.h \
misc.c
libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
@WIN32_TRUE@libqsecmn_la_LIBADD = -lpsapi
all: all-am
.SUFFIXES:

View File

@ -7,6 +7,8 @@
#ifdef _WIN32
#include <windows.h>
#include <psapi.h>
#include <tchar.h>
#else
#include <sys/types.h>
#include <unistd.h>
@ -19,7 +21,7 @@
#endif
qse_fio_t* qse_fio_open (
qse_mmgr_t* mmgr, qse_size_t ext,
qse_mmgr_t* mmgr, qse_size_t ext,
const qse_char_t* path, int flags, int mode)
{
qse_fio_t* fio;
@ -31,7 +33,7 @@ qse_fio_t* qse_fio_open (
QSE_ASSERTX (mmgr != QSE_NULL,
"Set the memory manager with QSE_MMGR_SETDFL()");
if (mmgr == QSE_NULL) return QSE_NULL;
if (mmgr == QSE_NULL) return QSE_NULL;
}
fio = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_fio_t) + ext);
@ -71,11 +73,11 @@ qse_fio_t* qse_fio_init (
DWORD desired_access = 0;
DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
DWORD creation_disposition = 0;
DWORD attributes = FILE_ATTRIBUTE_NORMAL;
DWORD flag_and_attr = FILE_ATTRIBUTE_NORMAL;
if (flags & QSE_FIO_APPEND)
if (flags & QSE_FIO_APPEND)
{
/* this is not officialy documented for CreateFile.
/* this is not officially documented for CreateFile.
* ZwCreateFile (kernel) seems to document it */
desired_access |= FILE_APPEND_DATA;
}
@ -86,41 +88,52 @@ qse_fio_t* qse_fio_init (
desired_access |= GENERIC_WRITE;
}
if (flags & QSE_FIO_READ) desired_access |= GENERIC_READ;
if (flags & QSE_FIO_CREATE)
if (flags & QSE_FIO_CREATE)
{
creation_disposition =
creation_disposition =
(flags & QSE_FIO_EXCLUSIVE)? CREATE_NEW:
(flags & QSE_FIO_TRUNCATE)? CREATE_ALWAYS: OPEN_ALWAYS;
}
else if (flags & QSE_FIO_TRUNCATE)
else if (flags & QSE_FIO_TRUNCATE)
{
creation_disposition = TRUNCATE_EXISTING;
}
else creation_disposition = OPEN_EXISTING;
if (flags & QSE_FIO_NOSHRD) share_mode &= ~FILE_SHARE_READ;
if (flags & QSE_FIO_NOSHWR) share_mode &= ~FILE_SHARE_WRITE;
if (flags & QSE_FIO_SYNC) attributes |= FILE_FLAG_WRITE_THROUGH;
/* TODO: handle mode... set attribuets */
handle = CreateFile (path,
desired_access, share_mode, QSE_NULL,
creation_disposition, attributes, 0);
if (flags & QSE_FIO_NOSHRD)
share_mode &= ~FILE_SHARE_READ;
if (flags & QSE_FIO_NOSHWR)
share_mode &= ~FILE_SHARE_WRITE;
if (!(mode & QSE_FIO_WUSR))
flag_and_attr = FILE_ATTRIBUTE_READONLY;
if (flags & QSE_FIO_SYNC)
flag_and_attr |= FILE_FLAG_WRITE_THROUGH;
/* these two are just hints to OS */
if (flags & QSE_FIO_RANDOM)
flag_and_attr |= FILE_FLAG_RANDOM_ACCESS;
if (flags & QSE_FIO_SEQUENTIAL)
flag_and_attr |= FILE_FLAG_SEQUENTIAL_SCAN;
handle = CreateFile (path,
desired_access, share_mode, QSE_NULL,
creation_disposition, flag_and_attr, 0);
}
if (handle == INVALID_HANDLE_VALUE) return QSE_NULL;
{
DWORD file_type = GetFileType(handle);
if (file_type == FILE_TYPE_UNKNOWN)
if (file_type == FILE_TYPE_UNKNOWN)
{
CloseHandle (handle);
return QSE_NULL;
}
}
/* TODO: a lot more */
/* TODO: support more features on WIN32 - TEMPORARY, DELETE_ON_CLOSE */
#else
if (flags & QSE_FIO_HANDLE)
@ -134,7 +147,7 @@ qse_fio_t* qse_fio_init (
const qse_mchar_t* path_mb = path;
#else
qse_mchar_t path_mb[PATH_MAX + 1];
if (qse_wcstombs_strict (path,
if (qse_wcstombs_strict (path,
path_mb, QSE_COUNTOF(path_mb)) == -1) return QSE_NULL;
#endif
/*
@ -143,7 +156,7 @@ qse_fio_t* qse_fio_init (
* wa -> WRONLY | APPEND
* a -> WRONLY | APPEND
*/
if (flags & QSE_FIO_APPEND)
if (flags & QSE_FIO_APPEND)
{
if ((flags & QSE_FIO_READ)) desired_access |= O_RDWR;
else desired_access |= O_WRONLY;
@ -151,7 +164,7 @@ qse_fio_t* qse_fio_init (
}
else
{
if ((flags & QSE_FIO_READ) &&
if ((flags & QSE_FIO_READ) &&
(flags & QSE_FIO_WRITE)) desired_access |= O_RDWR;
else if (flags & QSE_FIO_READ) desired_access |= O_RDONLY;
else if (flags & QSE_FIO_WRITE) desired_access |= O_WRONLY;
@ -208,27 +221,28 @@ qse_fio_off_t qse_fio_seek (
qse_fio_t* fio, qse_fio_off_t offset, qse_fio_ori_t origin)
{
#ifdef _WIN32
static int seek_map[] =
static int seek_map[] =
{
FILE_BEGIN,
FILE_CURRENT,
FILE_END
FILE_END
};
LARGE_INTEGER x, y;
QSE_ASSERT (AES_SIZEOF(offset) <= AES_SIZEOF(x.QuadPart));
x.QuadPart = offset;
if (SetFilePointerEx (fio->handle, x, &y, seek_map[origin]) == FALSE)
if (SetFilePointerEx (fio->handle, x, &y, seek_map[origin]) == FALSE)
{
return (qse_fio_off_t)-1;
}
return (qse_fio_off_t)y.QuadPart;
/*
x.QuadPart = offset;
x.LowPart = SetFilePointer (fio->handle, x.LowPart, &x.HighPart, seek_map[origin]);
x.LowPart = SetFilePointer (
fio->handle, x.LowPart, &x.HighPart, seek_map[origin]);
if (x.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
{
return (qse_fio_off_t)-1;
@ -238,7 +252,7 @@ qse_fio_off_t qse_fio_seek (
*/
#else
static int seek_map[] =
static int seek_map[] =
{
SEEK_SET,
SEEK_CUR,
@ -248,9 +262,9 @@ qse_fio_off_t qse_fio_seek (
#if !defined(_LP64) && defined(SYS__llseek)
loff_t tmp;
if (syscall (SYS__llseek, fio->handle,
if (syscall (SYS__llseek, fio->handle,
(unsigned long)(offset>>32),
(unsigned long)(offset&0xFFFFFFFFlu),
(unsigned long)(offset&0xFFFFFFFFlu),
&tmp,
seek_map[origin]) == -1)
{
@ -281,7 +295,6 @@ int qse_fio_truncate (qse_fio_t* fio, qse_fio_off_t size)
return 0;
#else
#if !defined(_LP64) && defined(SYS_ftruncate64)
return syscall (SYS_ftruncate64, fio->handle, size);
#elif defined(SYS_ftruncate)
@ -303,7 +316,7 @@ qse_ssize_t qse_fio_read (qse_fio_t* fio, void* buf, qse_size_t size)
return (qse_ssize_t)count;
#else
if (size > QSE_TYPE_MAX(size_t)) size = QSE_TYPE_MAX(size_t);
#ifdef SYS_read
#ifdef SYS_read
return syscall (SYS_read, fio->handle, buf, size);
#else
return read (fio->handle, buf, size);
@ -327,3 +340,122 @@ qse_ssize_t qse_fio_write (qse_fio_t* fio, const void* data, qse_size_t size)
#endif
#endif
}
#ifdef _WIN32
static int get_devname_from_handle (
HANDLE handle, qse_char_t* buf, qse_size_t len)
{
BOOL bSuccess = FALSE;
HANDLE map = NULL;
void* mem = NULL;
DWORD olen;
/* create a file mapping object */
map = CreateFileMapping (
handle,
NULL,
PAGE_READONLY,
0,
1,
NULL
);
if (map == NULL) return -1;
/* create a file mapping to get the file name. */
mem = MapViewOfFile (map, FILE_MAP_READ, 0, 0, 1);
if (mem == NULL)
{
CloseHandle (map);
return -1;
}
olen = GetMappedFileName (GetCurrentProcess(), mem, buf, len);
if (olen == 0)
{
UnmapViewOfFile (mem);
CloseHandle (map);
return -1;
}
UnmapViewOfFile (mem);
CloseHandle (map);
return 0;
}
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)
{
buf[0] = QSE_T('\\');
_tcscpy (&buf[1], &buf[24]);
}
else
{
DWORD n;
qse_char_t drives[128];
n = GetLogicalDriveStrings (QSE_COUNTOF(drives), drives);
if (n == 0 /* error */ ||
n > QSE_COUNTOF(drives) /* buffer small */)
{
return -1;
}
while (n > 0)
{
qse_char_t drv[3];
qse_char_t path[MAX_PATH];
drv[0] = drives[--n];
drv[1] = QSE_T(':');
drv[2] = QSE_T('\0');
if (QueryDosDevice (drv, path, QSE_COUNTOF(path)))
{
qse_size_t pl = _tcslen(path);
qse_size_t bl = _tcslen(buf);
if (bl > pl && buf[pl] == QSE_T('\\') &&
_tcsnicmp(path, buf, pl) == 0)
{
buf[0] = drv[0];
buf[1] = QSE_T(':');
_tcscpy (&buf[2], &buf[pl]);
break;
}
}
}
}
/* if the match is not found, the device name is returned
* without translation */
return 0;
}
#endif
int qse_fio_chmod (qse_fio_t* fio, int mode)
{
#ifdef _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. */
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;
#else
#if defined(SYS_fchmod)
return syscall (SYS_fchmod, fio->handle, mode);
#else
return fchmod (fio->handle, mode);
#endif
#endif
}

View File

@ -120,6 +120,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -130,7 +131,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -118,6 +118,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -128,7 +129,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@

View File

@ -118,6 +118,7 @@ JAR = @JAR@
JAR_PATH = @JAR_PATH@
JAVAC = @JAVAC@
JAVAC_PATH = @JAVAC_PATH@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
@ -128,7 +129,9 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@