From: Nick Ing-Simmons Date: Thu, 2 May 2002 16:10:15 +0000 (+0000) Subject: Win32 builds and mostly works for non-USE_PERLIO non-USE_IMP_SYS case. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=30753f56c8bbfb209552e904d9d76202413ebf24;p=p5sagit%2Fp5-mst-13.2.git Win32 builds and mostly works for non-USE_PERLIO non-USE_IMP_SYS case. - move body of fdupopen() from perlhost.h to win32.h as win32_fdupopen() - use it in perlio.c p4raw-id: //depot/perlio@16349 --- diff --git a/perlio.c b/perlio.c index 57c7041..bcfa256 100644 --- a/perlio.c +++ b/perlio.c @@ -192,6 +192,9 @@ PerlIO_fdupopen(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags) #ifdef PERL_IMPLICIT_SYS return PerlSIO_fdupopen(f); #else +#ifdef WIN32 + return win32_fdupopen(f); +#else if (f) { int fd = PerlLIO_dup(PerlIO_fileno(f)); if (fd >= 0) { @@ -212,6 +215,7 @@ PerlIO_fdupopen(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags) #endif return NULL; #endif +#endif } diff --git a/win32/win32.c b/win32/win32.c index ba8c637..4669d3a 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4036,6 +4036,58 @@ win32_get_osfhandle(int fd) return (intptr_t)_get_osfhandle(fd); } +FILE * +win32_fdupopen(FILE *pf) +{ + FILE* pfdup; + fpos_t pos; + char mode[3]; + int fileno = win32_dup(win32_fileno(pf)); + + /* open the file in the same mode */ +#ifdef __BORLANDC__ + if((pf)->flags & _F_READ) { + mode[0] = 'r'; + mode[1] = 0; + } + else if((pf)->flags & _F_WRIT) { + mode[0] = 'a'; + mode[1] = 0; + } + else if((pf)->flags & _F_RDWR) { + mode[0] = 'r'; + mode[1] = '+'; + mode[2] = 0; + } +#else + if((pf)->_flag & _IOREAD) { + mode[0] = 'r'; + mode[1] = 0; + } + else if((pf)->_flag & _IOWRT) { + mode[0] = 'a'; + mode[1] = 0; + } + else if((pf)->_flag & _IORW) { + mode[0] = 'r'; + mode[1] = '+'; + mode[2] = 0; + } +#endif + + /* it appears that the binmode is attached to the + * file descriptor so binmode files will be handled + * correctly + */ + pfdup = win32_fdopen(fileno, mode); + + /* move the file pointer to the same position */ + if (!fgetpos(pf, &pos)) { + fsetpos(pfdup, &pos); + } + return pfdup; +} + DllExport void* win32_dynaload(const char* filename) {