diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2002-05-02 16:10:15 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2002-05-02 16:10:15 +0000 |
commit | 30753f56c8bbfb209552e904d9d76202413ebf24 (patch) | |
tree | f1367b5515daeaafd99537e249f3c261df74b41a /win32 | |
parent | 1e8a8f599308436d6e164543b54e022d0b1a9177 (diff) | |
download | perl-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
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 52 |
1 files changed, 52 insertions, 0 deletions
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) { |