PerlIO * PerlIOWin32_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *params, int flags) { PerlIOWin32 *os = PerlIOSelf(f,PerlIOWin32); HANDLE proc = GetCurrentProcess(); HANDLE new_h; if (DuplicateHandle(proc, os->h, proc, &new_h, 0, FALSE, DUPLICATE_SAME_ACCESS)) { char mode[8]; int fd = win32_open_osfhandle((intptr_t) new_h, PerlIOUnix_oflags(PerlIO_modestr(o,mode))); if (fd >= 0) { f = PerlIOBase_dup(aTHX_ f, o, params, flags); if (f) { PerlIOWin32 *fs = PerlIOSelf(f,PerlIOWin32); fs->h = new_h; fs->fd = fd; fs->refcnt = 1; fdtable[fd] = fs; if (fd > max_open_fd) max_open_fd = fd; } else { win32_close(fd); } } else { CloseHandle(new_h); } } return f; }
void file_close(void * fd) { #ifdef WIN32 win32_close(fd); #else unix_close(fd); #endif }
DIR *opendir(void *x, const char *filename) { DIR *dp; char *filespec; struct _stat buffer; int index, fd, allocated; if (-1 == (fd = win32_open_ex(x, filename, _O_RDONLY, &buffer))) { return NULL; } if (!S_ISDIR(buffer.st_mode)) { errno = ENOTDIR; return NULL; } allocated = strlen(filename) + 2 + 1; filespec = mem_new_n(*filename, allocated); if (0 != strcpy_s(filespec, allocated, filename)) { free(filespec); return NULL; } index = strlen(filespec) - 1; if (index >= 0 && (filespec[index] == '/' || (filespec[index] == '\\' && (index == 0 || !IsDBCSLeadByte(filespec[index-1]))))) { filespec[index] = '\0'; } if (0 != strncat_s(filespec, allocated, "\\*", sizeof("\\*") - 1)) { free(filespec); return NULL; } dp = mem_new(*dp); dp->offset = 0; dp->finished = 0; if ((dp->handle = FindFirstFileA(filespec, &(dp->fileinfo))) == INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); if (err == ERROR_NO_MORE_FILES || err == ERROR_FILE_NOT_FOUND) { dp->finished = 1; } else { free(dp); free(filespec); win32_close(x, fd); return NULL; } } dp->fd = fd; dp->dir = mem_dup(filename); free(filespec); return dp; }
void audio_close (AUDIO_OUT *audio_out) { #if defined (__linux__) linux_close (audio_out) ; #elif (defined (__MACH__) && defined (__APPLE__)) macosx_close (audio_out) ; #elif (defined (sun) && defined (unix)) solaris_close (audio_out) ; #elif (defined (_WIN32) || defined (WIN32)) win32_close (audio_out) ; #else #warning "*** Playing sound not yet supported on this platform." #warning "*** Please feel free to submit a patch." printf ("Error : Playing sound not yet supported on this platform.\n") ; return ; #endif return ; } /* audio_close */
IV PerlIOWin32_close(pTHX_ PerlIO *f) { PerlIOWin32 *s = PerlIOSelf(f,PerlIOWin32); if (s->refcnt == 1) { IV code = 0; #if 0 /* This does not do pipes etc. correctly */ if (!CloseHandle(s->h)) { s->h = INVALID_HANDLE_VALUE; return -1; } #else PerlIOBase(f)->flags &= ~PERLIO_F_OPEN; return win32_close(s->fd); #endif } return 0; }