summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1997-11-12 05:31:28 +0000
committerGurusamy Sarathy <gsar@cpan.org>1997-11-12 05:31:28 +0000
commit65e48ea94f536920f95a77a3a652fd45c687b28a (patch)
tree5380b603d001d30969302e65ab22492edd5c7849
parent235db74f0c7445cd9b5ee77346db17e180d32b93 (diff)
downloadperl-65e48ea94f536920f95a77a3a652fd45c687b28a.tar.gz
Fix various win32 code blemishes:
- s/stolen/win32/g - s/(CROAK|WARN)/lc($1)/eg - remove deadcode from most places p4raw-id: //depot/win32/perl@241
-rw-r--r--win32/makedef.pl2
-rw-r--r--win32/win32.c161
-rw-r--r--win32/win32io.c50
-rw-r--r--win32/win32iop.h10
4 files changed, 26 insertions, 197 deletions
diff --git a/win32/makedef.pl b/win32/makedef.pl
index 8925a2c57c..31686d26b8 100644
--- a/win32/makedef.pl
+++ b/win32/makedef.pl
@@ -395,6 +395,8 @@ win32_malloc
win32_calloc
win32_realloc
win32_free
+win32_open_osfhandle
+win32_get_osfhandle
win32stdio
Perl_win32_init
RunPerl
diff --git a/win32/win32.c b/win32/win32.c
index e10bf2b463..6d04d4a28d 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -30,9 +30,6 @@
#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
@@ -168,156 +165,12 @@ my_popen(char *cmd, char *mode)
#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
@@ -566,7 +419,7 @@ opendir(char *filename)
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)
@@ -586,7 +439,7 @@ opendir(char *filename)
*/
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)
@@ -725,11 +578,11 @@ kill(int pid, int sig)
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;
@@ -743,7 +596,7 @@ kill(int pid, int sig)
int
ioctl(int i, unsigned int u, char *data)
{
- CROAK("ioctl not implemented!\n");
+ croak("ioctl not implemented!\n");
return -1;
}
#endif
@@ -1363,13 +1216,13 @@ win32_free(void *block)
}
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);
}
diff --git a/win32/win32io.c b/win32/win32io.c
index e4d0bd86c8..b4aacf1101 100644
--- a/win32/win32io.c
+++ b/win32/win32io.c
@@ -1,5 +1,3 @@
-
-
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
extern int my_fclose(FILE *pf);
@@ -64,7 +62,7 @@ dummy_globalmode(int mode)
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
*/
@@ -73,17 +71,11 @@ dummy_globalmode(int mode)
#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 {
@@ -96,7 +88,7 @@ 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)
@@ -117,7 +109,7 @@ extern char _osfile[];
#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
@@ -137,7 +129,7 @@ extern char _osfile[];
*
*******************************************************************************/
-int
+static int
my_open_osfhandle(long osfhandle, int flags)
{
int fh;
@@ -174,28 +166,12 @@ my_open_osfhandle(long osfhandle, int flags)
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
@@ -206,7 +182,7 @@ my_flock(int fd, int oper)
int i = -1;
HANDLE fh;
- fh = (HANDLE)my_get_osfhandle(fd);
+ fh = (HANDLE)_get_osfhandle(fd);
memset(&o, 0, sizeof(o));
switch(oper) {
@@ -289,8 +265,8 @@ WIN32_IOSUBSYSTEM win32stdio = {
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,
diff --git a/win32/win32iop.h b/win32/win32iop.h
index c5f718ac36..fd97d66e6c 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -104,13 +104,11 @@ EXT void* win32_calloc(size_t numitems, size_t size);
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);
@@ -187,8 +185,8 @@ END_EXTERN_C
#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