adding code into pio.c for win32
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: fio.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
|
||||
* $Id: fio.c 193 2009-06-08 13:09:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -267,7 +267,7 @@ qse_fio_off_t qse_fio_seek (
|
||||
};
|
||||
LARGE_INTEGER x, y;
|
||||
|
||||
QSE_ASSERT (AES_SIZEOF(offset) <= AES_SIZEOF(x.QuadPart));
|
||||
QSE_ASSERT (QSE_SIZEOF(offset) <= QSE_SIZEOF(x.QuadPart));
|
||||
|
||||
x.QuadPart = offset;
|
||||
if (SetFilePointerEx (fio->handle, x, &y, seek_map[origin]) == FALSE)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: pio.c 168 2009-05-30 01:19:46Z hyunghwan.chung $
|
||||
* $Id: pio.c 193 2009-06-08 13:09:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -89,12 +89,59 @@ qse_pio_t* qse_pio_init (
|
||||
};
|
||||
int i, minidx = -1, maxidx = -1;
|
||||
|
||||
#ifdef _WIN32
|
||||
SECURITY_ATTRIBUTES secattr;
|
||||
#endif
|
||||
|
||||
QSE_MEMSET (pio, 0, QSE_SIZEOF(*pio));
|
||||
pio->mmgr = mmgr;
|
||||
|
||||
#ifdef _WIN32
|
||||
/* TODO: XXXXXXXXXXXXXXXXX */
|
||||
http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx
|
||||
/* http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx */
|
||||
|
||||
secattr.nLength = QSE_SIZEOF(secattr);
|
||||
secattr.bInheritHandle = TRUE;
|
||||
secattr.lpSecurityDescriptor = NULL;
|
||||
|
||||
if (flags & QSE_PIO_WRITEIN)
|
||||
{
|
||||
if (CreatePipe (
|
||||
&handle[0], &handle[1],
|
||||
&secattr, 0) == FALSE) goto oops;
|
||||
|
||||
if (SetHandleInformation (
|
||||
handle[0], HANDLE_FLAG_INHERIT, 0) == FALSE) goto oops;
|
||||
|
||||
minidx = 0; maxidx = 1;
|
||||
}
|
||||
|
||||
if (flags & QSE_PIO_READOUT)
|
||||
{
|
||||
if (CreatePipe (
|
||||
&handle[2], &handle[3],
|
||||
&secattr, 0) == FALSE) goto oops;
|
||||
|
||||
if (SetHandleInformation (
|
||||
handle[3], HANDLE_FLAG_INHERIT, 0) == FALSE) goto oops;
|
||||
|
||||
if (minidx == -1) minidx = 2;
|
||||
maxidx = 3;
|
||||
}
|
||||
|
||||
if (flags & QSE_PIO_READERR)
|
||||
{
|
||||
if (CreatePipe (
|
||||
&handle[4], &handle[5],
|
||||
&secattr, 0) == FALSE) goto oops;
|
||||
|
||||
if (SetHandleInformation (
|
||||
handle[5], HANDLE_FLAG_INHERIT, 0) == FALSE) goto oops;
|
||||
|
||||
if (minidx == -1) minidx = 4;
|
||||
maxidx = 5;
|
||||
}
|
||||
|
||||
/* TODO: .... */
|
||||
#else
|
||||
|
||||
if (flags & QSE_PIO_WRITEIN)
|
||||
@ -383,7 +430,11 @@ http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx
|
||||
|
||||
oops:
|
||||
for (i = 0; i < QSE_COUNTOF(tio); i++) qse_tio_close (tio[i]);
|
||||
#if _WIN32
|
||||
for (i = minidx; i < maxidx; i++) CloseHandle (handle[i]);
|
||||
#else
|
||||
for (i = minidx; i < maxidx; i++) QSE_CLOSE (handle[i]);
|
||||
#endif
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
@ -571,7 +622,11 @@ void qse_pio_end (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
|
||||
if (pio->pin[hid].handle != QSE_PIO_HND_NIL)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CloseHandle (pio->pin[hid].handle);
|
||||
#else
|
||||
QSE_CLOSE (pio->pin[hid].handle);
|
||||
#endif
|
||||
pio->pin[hid].handle = QSE_PIO_HND_NIL;
|
||||
}
|
||||
}
|
||||
@ -579,7 +634,7 @@ void qse_pio_end (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
int qse_pio_wait (qse_pio_t* pio)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD ec;
|
||||
DWORD ecode, w;
|
||||
|
||||
if (pio->child == QSE_PIO_PID_NIL)
|
||||
{
|
||||
@ -588,12 +643,48 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
return -1;
|
||||
}
|
||||
|
||||
WaitForSingleObject (pio->child, -1);
|
||||
if (GetExitCodeProcess (pio->child, &ec) == FALSE) ....
|
||||
w = WaitForSingleObject (pio->child,
|
||||
((pio->flags & QSE_PIO_WAIT_NOBLOCK)? 0: INFINITE)
|
||||
);
|
||||
if (w == WAIT_TIMEOUT)
|
||||
{
|
||||
/* the child process is still alive */
|
||||
return 255 + 1;
|
||||
}
|
||||
if (w != WAIT_OBJECT_0)
|
||||
{
|
||||
/* WAIT_FAILED, WAIT_ABANDONED */
|
||||
pio->errnum = QSE_PIO_ESUBSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_ASSERT (w == WAIT_OBJECT_0);
|
||||
|
||||
if (GetExitCodeProcess (pio->child, &ecode) == FALSE)
|
||||
{
|
||||
/* close the handle anyway to prevent further
|
||||
* errors when this function is called again */
|
||||
CloseHandle (pio->child);
|
||||
pio->child = QSE_PIO_PID_NIL;
|
||||
|
||||
pio->errnum = QSE_PIO_ESUBSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* close handle here to emulate waitpid() as much as possible. */
|
||||
CloseHandle (pio->child);
|
||||
pio->child = QSE_PIO_PID_NIL;
|
||||
|
||||
if (ecode == STILL_ACTIVE)
|
||||
{
|
||||
/* this should not happen as the control reaches here
|
||||
* only when WaitforSingleObject() is successful.
|
||||
* if it happends, close the handle and return an error */
|
||||
pio->errnum = QSE_PIO_ESUBSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ecode;
|
||||
#else
|
||||
int opt = 0;
|
||||
int ret = -1;
|
||||
@ -656,7 +747,7 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
else
|
||||
{
|
||||
/* not interested in WIFSTOPPED & WIFCONTINUED.
|
||||
* in fact, this else block should not be reached
|
||||
* in fact, this else-block should not be reached
|
||||
* as WIFEXITED or WIFSIGNALED must be true.
|
||||
* anyhow, just set the return value to 0. */
|
||||
ret = 0;
|
||||
@ -690,7 +781,7 @@ int qse_pio_kill (qse_pio_t* pio)
|
||||
n = TerminateProcess (pio->child, 255 + 1 + 9);
|
||||
if (n == FALSE)
|
||||
{
|
||||
pio->errnum = QSE_PIO_SYSCALL;
|
||||
pio->errnum = QSE_PIO_ESUBSYS;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: syscall.h 187 2009-06-07 05:03:44Z hyunghwan.chung $
|
||||
* $Id: syscall.h 193 2009-06-08 13:09:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -42,6 +42,9 @@
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_UTIME_H
|
||||
# include <utime.h>
|
||||
#endif
|
||||
|
||||
#if defined(QSE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
# include <sys/syscall.h>
|
||||
@ -196,16 +199,28 @@
|
||||
#endif
|
||||
|
||||
#ifdef SYS_gettimeofday
|
||||
# define QSE_GETTIMEOFDAY(tv,tz) syscall(SYS_gettimeofday, tv, tz)
|
||||
# define QSE_GETTIMEOFDAY(tv,tz) syscall(SYS_gettimeofday,tv,tz)
|
||||
#else
|
||||
# define QSE_GETTIMEOFDAY(tv,tz) gettimeofday(tv,tz)
|
||||
#endif
|
||||
|
||||
#ifdef SYS_settimeofday
|
||||
# define QSE_SETTIMEOFDAY(tv,tz) syscall(SYS_settimeofday, tv, tz)
|
||||
# define QSE_SETTIMEOFDAY(tv,tz) syscall(SYS_settimeofday,tv,tz)
|
||||
#else
|
||||
# define QSE_SETTIMEOFDAY(tv,tz) settimeofday(tv,tz)
|
||||
#endif
|
||||
|
||||
#ifdef SYS_utime
|
||||
# define QSE_UTIME(file,t) syscall(SYS_utime,file,t)
|
||||
#else
|
||||
# define QSE_UTIME(file,t) utime(file,t)
|
||||
#endif
|
||||
|
||||
#ifdef SYS_utimes
|
||||
# define QSE_UTIMES(file,t) syscall(SYS_utimes,file,t)
|
||||
#else
|
||||
# define QSE_UTIMES(file,t) utimes(file,t)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user