#include <stdarg.h>
#include <float.h>
-#define CROAK croak
-#define WARN warn
-
#define EXECF_EXEC 1
#define EXECF_SPAWN 2
#define EXECF_SPAWN_NOWAIT 3
#else
#define fixcmd(x)
#endif
-
-#if 1
-/* was #ifndef PERLDLL, but the #else stuff doesn't work on NT
- * GSAR 97/03/13
- */
fixcmd(cmd);
#ifdef __BORLANDC__ /* workaround a Borland stdio bug */
win32_fflush(stdout);
win32_fflush(stderr);
#endif
return win32_popen(cmd, mode);
-#else
-/*
- * There seems to be some problems for the _popen call in a DLL
- * this trick at the moment seems to work but it is never test
- * on NT yet
- *
- */
-# ifdef __cplusplus
-#define EXT_C_FUNC extern "C"
-# else
-#define EXT_C_FUNC extern
-# endif
-
- EXT_C_FUNC int __cdecl _set_osfhnd(int fh, long value);
- EXT_C_FUNC void __cdecl _lock_fhandle(int);
- EXT_C_FUNC void __cdecl _unlock_fhandle(int);
-
- BOOL fSuccess;
- PerlIO *pf; /* to store the _popen return value */
- int tm = 0; /* flag indicating tDllExport or binary mode */
- int fhNeeded, fhInherited, fhDup;
- int ineeded, iinherited;
- DWORD dwDup;
- int phdls[2]; /* I/O handles for pipe */
- HANDLE hPIn, hPOut, hPErr,
- hSaveStdin, hSaveStdout, hSaveStderr,
- hPNeeded, hPInherited, hPDuped;
-
- /* first check for errors in the arguments */
- if ( (cmd == NULL) || (mode == NULL)
- || ((*mode != 'w') && (*mode != _T('r'))) )
- goto error1;
-
- if ( *(mode + 1) == _T('t') )
- tm = O_TEXT;
- else if ( *(mode + 1) == _T('b') )
- tm = O_BINARY;
- else
- tm = (*mode == 'w' ? O_BINARY : O_TEXT);
-
-
- fixcmd(cmd);
- if (&win32stdio != pIOSubSystem)
- return win32_popen(cmd, mode);
-
-#ifdef EFG
- if ( _pipe( phdls, 1024, tm ) == -1 )
-#else
- if ( win32_pipe( phdls, 1024, tm ) == -1 )
-#endif
- goto error1;
-
- /* save the current situation */
- hSaveStdin = GetStdHandle(STD_INPUT_HANDLE);
- hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- hSaveStderr = GetStdHandle(STD_ERROR_HANDLE);
-
- if (*mode == _T('w')) {
- ineeded = 1;
- dwDup = STD_INPUT_HANDLE;
- iinherited = 0;
- }
- else {
- ineeded = 0;
- dwDup = STD_OUTPUT_HANDLE;
- iinherited = 1;
- }
-
- fhNeeded = phdls[ineeded];
- fhInherited = phdls[iinherited];
-
- fSuccess = DuplicateHandle(GetCurrentProcess(),
- (HANDLE) stolen_get_osfhandle(fhNeeded),
- GetCurrentProcess(),
- &hPNeeded,
- 0,
- FALSE, /* not inherited */
- DUPLICATE_SAME_ACCESS);
-
- if (!fSuccess)
- goto error2;
-
- fhDup = stolen_open_osfhandle((long) hPNeeded, tm);
- win32_dup2(fhDup, fhNeeded);
- win32_close(fhDup);
-
-#ifdef AAA
- /* Close the Out pipe, child won't need it */
- hPDuped = (HANDLE) stolen_get_osfhandle(fhNeeded);
-
- _lock_fhandle(fhNeeded);
- _set_osfhnd(fhNeeded, (long)hPNeeded); /* put in ours duplicated one */
- _unlock_fhandle(fhNeeded);
-
- CloseHandle(hPDuped); /* close the handle first */
-#endif
-
- if (!SetStdHandle(dwDup, (HANDLE) stolen_get_osfhandle(fhInherited)))
- goto error2;
-
- /*
- * make sure the child see the same stderr as the calling program
- */
- if (!SetStdHandle(STD_ERROR_HANDLE,
- (HANDLE)stolen_get_osfhandle(win32_fileno(win32_stderr()))))
- goto error2;
-
- pf = win32_popen(cmd, mode); /* ask _popen to do the job */
-
- /* restore to where we were */
- SetStdHandle(STD_INPUT_HANDLE, hSaveStdin);
- SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout);
- SetStdHandle(STD_ERROR_HANDLE, hSaveStderr);
-
- /* we don't need it any more, that's for the child */
- win32_close(fhInherited);
-
- if (NULL == pf) {
- /* something wrong */
- win32_close(fhNeeded);
- goto error1;
- }
- else {
- /*
- * here we steal the file handle in pf and stuff ours in
- */
- win32_dup2(fhNeeded, win32_fileno(pf));
- win32_close(fhNeeded);
- }
- return (pf);
-
-error2:
- win32_close(fhNeeded);
- win32_close(fhInherited);
-
-error1:
- return (NULL);
-
-#endif
}
long
idx = strlen(FindData.cFileName)+1;
New(1304, p->start, idx, char);
if(p->start == NULL) {
- CROAK("opendir: malloc failed!\n");
+ croak("opendir: malloc failed!\n");
}
strcpy(p->start, FindData.cFileName);
/* if(downcase)
*/
Renew(p->start, idx+len+1, char);
if(p->start == NULL) {
- CROAK("opendir: malloc failed!\n");
+ croak("opendir: malloc failed!\n");
}
strcpy(&p->start[idx], FindData.cFileName);
/* if (downcase)
HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
if (hProcess == NULL) {
- CROAK("kill process failed!\n");
+ croak("kill process failed!\n");
}
else {
if (!TerminateProcess(hProcess, sig))
- CROAK("kill process failed!\n");
+ croak("kill process failed!\n");
CloseHandle(hProcess);
}
return 0;
int
ioctl(int i, unsigned int u, char *data)
{
- CROAK("ioctl not implemented!\n");
+ croak("ioctl not implemented!\n");
return -1;
}
#endif
}
int
-stolen_open_osfhandle(long handle, int flags)
+win32_open_osfhandle(long handle, int flags)
{
return pIOSubSystem->pfn_open_osfhandle(handle, flags);
}
long
-stolen_get_osfhandle(int fd)
+win32_get_osfhandle(int fd)
{
return pIOSubSystem->pfn_get_osfhandle(fd);
}
-
-
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
extern int my_fclose(FILE *pf);
return o;
}
-#if defined(_DLL) || defined(__BORLANDC__)
+#if defined(_DLL) || !defined(_MSC_VER)
/* It may or may not be fixed (ok on NT), but DLL runtime
does not export the functions used in the workround
*/
#if defined(_WIN32) && !defined(WIN95_OSFHANDLE_FIXED) && defined(_M_IX86)
-# ifdef __cplusplus
-#define EXT_C_FUNC extern "C"
-# else
-#define EXT_C_FUNC extern
-# endif
-
-EXT_C_FUNC int __cdecl _alloc_osfhnd(void);
-EXT_C_FUNC int __cdecl _set_osfhnd(int fh, long value);
-EXT_C_FUNC void __cdecl _lock_fhandle(int);
-EXT_C_FUNC void __cdecl _unlock_fhandle(int);
-EXT_C_FUNC void __cdecl _unlock(int);
+EXTERN_C int __cdecl _alloc_osfhnd(void);
+EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
+EXTERN_C void __cdecl _lock_fhandle(int);
+EXTERN_C void __cdecl _unlock_fhandle(int);
+EXTERN_C void __cdecl _unlock(int);
#if (_MSC_VER >= 1000)
typedef struct {
#endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
} ioinfo;
-EXT_C_FUNC ioinfo * __pioinfo[];
+EXTERN_C ioinfo * __pioinfo[];
#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
#define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
/***
-*int _patch_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
+*int my_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
*
*Purpose:
* This function allocates a free C Runtime file handle and associates
*
*******************************************************************************/
-int
+static int
my_open_osfhandle(long osfhandle, int flags)
{
int fh;
return fh; /* return handle */
}
-#else
-int __cdecl
-my_open_osfhandle(long osfhandle, int flags)
-{
- return _open_osfhandle(osfhandle, flags);
-}
+#define _open_osfhandle my_open_osfhandle
#endif /* _M_IX86 */
-long
-my_get_osfhandle( int filehandle )
-{
- return _get_osfhandle(filehandle);
-}
-
-#ifdef __BORLANDC__
-#define _chdir chdir
-#endif
-
/* simulate flock by locking a range on the file */
-
#define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
#define LK_LEN 0xffff0000
int i = -1;
HANDLE fh;
- fh = (HANDLE)my_get_osfhandle(fd);
+ fh = (HANDLE)_get_osfhandle(fd);
memset(&o, 0, sizeof(o));
switch(oper) {
read, /* (*pfunc_read)(int fd, void *buf, unsigned int cnt); */
write, /* (*pfunc_write)(int fd, const void *buf, unsigned int cnt); */
dummy_globalmode, /* (*pfunc_globalmode)(int mode) */
- my_open_osfhandle,
- my_get_osfhandle,
+ _open_osfhandle,
+ _get_osfhandle,
spawnvp,
mkdir,
rmdir,
EXT void* win32_realloc(void *block, size_t size);
EXT void win32_free(void *block);
-
-
/*
* these two are win32 specific but still io related
*/
-int stolen_open_osfhandle(long handle, int flags);
-long stolen_get_osfhandle(int fd);
+EXT int win32_open_osfhandle(long handle, int flags);
+EXT long win32_get_osfhandle(int fd);
EXT PWIN32_IOSUBSYSTEM SetIOSubSystem(void *piosubsystem);
#define eof(fd) win32_eof(fd)
#define read(fd,b,s) win32_read(fd,b,s)
#define write(fd,b,s) win32_write(fd,b,s)
-#define _open_osfhandle stolen_open_osfhandle
-#define _get_osfhandle stolen_get_osfhandle
+#define _open_osfhandle win32_open_osfhandle
+#define _get_osfhandle win32_get_osfhandle
#define spawnvp win32_spawnvp
#define mkdir win32_mkdir
#define rmdir win32_rmdir