summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2002-05-02 16:10:15 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2002-05-02 16:10:15 +0000
commit30753f56c8bbfb209552e904d9d76202413ebf24 (patch)
treef1367b5515daeaafd99537e249f3c261df74b41a
parent1e8a8f599308436d6e164543b54e022d0b1a9177 (diff)
downloadperl-30753f56c8bbfb209552e904d9d76202413ebf24.tar.gz
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
-rw-r--r--perlio.c4
-rw-r--r--win32/win32.c52
2 files changed, 56 insertions, 0 deletions
diff --git a/perlio.c b/perlio.c
index 57c70410e7..bcfa2568e2 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 ba8c637211..4669d3ab07 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)
{