3 * (c) 1995 Microsoft Corporation. All rights reserved.
4 * Developed by hip communications inc., http://info.hip.com/info/
5 * Portions (c) 1993 Intergraph Corporation. All rights reserved.
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Artistic License, as specified in the README file.
11 #define WIN32_LEAN_AND_MEAN
12 #define WIN32IO_IS_STDIO
17 #undef __attribute__ /* seems broken in 2.8.0 */
18 #define __attribute__(p)
26 /* ugliness to work around a buggy struct definition in lmwksta.h */
33 #endif /* __MINGW32__ */
35 /* #include "config.h" */
37 #define PERLIO_NOT_STDIO 0
38 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
47 extern CPerlObj* pPerl;
55 /* assert.h conflicts with #define of assert in perl.h */
62 #if defined(_MSC_VER) || defined(__MINGW32__)
63 #include <sys/utime.h>
69 /* Mingw32 defaults to globing command line
70 * So we turn it off like this:
77 #define EXECF_SPAWN_NOWAIT 3
79 #if defined(PERL_OBJECT)
80 #undef win32_get_privlib
81 #define win32_get_privlib g_win32_get_privlib
82 #undef win32_get_sitelib
83 #define win32_get_sitelib g_win32_get_sitelib
85 #define do_aspawn g_do_aspawn
87 #define do_spawn g_do_spawn
89 #define do_exec g_do_exec
91 #define getlogin g_getlogin
94 static DWORD os_id(void);
95 static void get_shell(void);
96 static long tokenize(char *str, char **dest, char ***destv);
97 int do_spawn2(char *cmd, int exectype);
98 static BOOL has_redirection(char *ptr);
99 static long filetime_to_clock(PFILETIME ft);
100 static BOOL filetime_from_time(PFILETIME ft, time_t t);
101 static char * get_emd_part(char *leading, char *trailing, ...);
102 static void remove_dead_process(HANDLE deceased);
104 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
105 static DWORD w32_platform = (DWORD)-1;
108 # ifdef USE_DECLSPEC_THREAD
109 __declspec(thread) char strerror_buffer[512];
110 __declspec(thread) char getlogin_buffer[128];
111 __declspec(thread) char w32_perllib_root[MAX_PATH+1];
112 # ifdef HAVE_DES_FCRYPT
113 __declspec(thread) char crypt_buffer[30];
116 # define strerror_buffer (thr->i.Wstrerror_buffer)
117 # define getlogin_buffer (thr->i.Wgetlogin_buffer)
118 # define w32_perllib_root (thr->i.Ww32_perllib_root)
119 # define crypt_buffer (thr->i.Wcrypt_buffer)
122 static char strerror_buffer[512];
123 static char getlogin_buffer[128];
124 static char w32_perllib_root[MAX_PATH+1];
125 # ifdef HAVE_DES_FCRYPT
126 static char crypt_buffer[30];
132 return (os_id() == VER_PLATFORM_WIN32_WINDOWS);
137 return (os_id() == VER_PLATFORM_WIN32_NT);
141 GetRegStrFromKey(HKEY hkey, const char *lpszValueName, char** ptr, DWORD* lpDataLen)
142 { /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
145 const char *subkey = "Software\\Perl";
148 retval = RegOpenKeyEx(hkey, subkey, 0, KEY_READ, &handle);
149 if (retval == ERROR_SUCCESS){
150 retval = RegQueryValueEx(handle, lpszValueName, 0, &type, NULL, lpDataLen);
151 if (retval == ERROR_SUCCESS && type == REG_SZ) {
153 Renew(*ptr, *lpDataLen, char);
156 New(1312, *ptr, *lpDataLen, char);
158 retval = RegQueryValueEx(handle, lpszValueName, 0, NULL, (PBYTE)*ptr, lpDataLen);
159 if (retval != ERROR_SUCCESS) {
170 GetRegStr(const char *lpszValueName, char** ptr, DWORD* lpDataLen)
172 *ptr = GetRegStrFromKey(HKEY_CURRENT_USER, lpszValueName, ptr, lpDataLen);
175 *ptr = GetRegStrFromKey(HKEY_LOCAL_MACHINE, lpszValueName, ptr, lpDataLen);
181 get_emd_part(char *prev_path, char *trailing_path, ...)
184 char mod_name[MAX_PATH+1];
188 int oldsize, newsize;
190 va_start(ap, trailing_path);
191 strip = va_arg(ap, char *);
193 GetModuleFileName((w32_perldll_handle == INVALID_HANDLE_VALUE)
194 ? GetModuleHandle(NULL)
195 : w32_perldll_handle, mod_name, sizeof(mod_name));
196 ptr = strrchr(mod_name, '\\');
197 while (ptr && strip) {
198 /* look for directories to skip back */
201 ptr = strrchr(mod_name, '\\');
202 if (!ptr || stricmp(ptr+1, strip) != 0) {
206 strip = va_arg(ap, char *);
214 strcpy(++ptr, trailing_path);
216 newsize = strlen(mod_name) + 1;
218 oldsize = strlen(prev_path) + 1;
219 newsize += oldsize; /* includes plus 1 for ';' */
220 Renew(prev_path, newsize, char);
221 prev_path[oldsize] = ';';
222 strcpy(&prev_path[oldsize], mod_name);
225 New(1311, prev_path, newsize, char);
226 strcpy(prev_path, mod_name);
233 win32_get_privlib(char *pl)
235 char *stdlib = "lib";
236 char buffer[MAX_PATH+1];
240 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
241 sprintf(buffer, "%s-%s", stdlib, pl);
242 path = GetRegStr(buffer, &path, &datalen);
244 path = GetRegStr(stdlib, &path, &datalen);
246 /* $stdlib .= ";$EMD/../../lib" */
247 return get_emd_part(path, stdlib, ARCHNAME, "bin", Nullch);
251 win32_get_sitelib(char *pl)
253 char *sitelib = "sitelib";
255 char pathstr[MAX_PATH+1];
257 char *path1 = Nullch;
258 char *path2 = Nullch;
261 /* $HKCU{"sitelib-$]"} || $HKLM{"sitelib-$]"} . ---; */
262 sprintf(regstr, "%s-%s", sitelib, pl);
263 path1 = GetRegStr(regstr, &path1, &datalen);
266 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/site/$]/lib"; */
267 sprintf(pathstr, "site\\%s\\lib", pl);
268 path1 = get_emd_part(path1, pathstr, ARCHNAME, "bin", pl, Nullch);
270 /* $HKCU{'sitelib'} || $HKLM{'sitelib'} . ---; */
271 path2 = GetRegStr(sitelib, &path2, &datalen);
274 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/site/lib"; */
275 path2 = get_emd_part(path2, "site\\lib", ARCHNAME, "bin", pl, Nullch);
284 newsize = len + strlen(path2) + 2; /* plus one for ';' */
286 Renew(path1, newsize, char);
288 strcpy(&path1[len], path2);
296 has_redirection(char *ptr)
302 * Scan string looking for redirection (< or >) or pipe
303 * characters (|) that are not in a quoted string
333 #if !defined(PERL_OBJECT)
334 /* since the current process environment is being updated in util.c
335 * the library functions will get the correct environment
338 my_popen(char *cmd, char *mode)
341 #define fixcmd(x) { \
342 char *pspace = strchr((x),' '); \
345 while (p < pspace) { \
356 win32_fflush(stdout);
357 win32_fflush(stderr);
358 return win32_popen(cmd, mode);
362 my_pclose(PerlIO *fp)
364 return win32_pclose(fp);
371 static OSVERSIONINFO osver;
373 if (osver.dwPlatformId != w32_platform) {
374 memset(&osver, 0, sizeof(OSVERSIONINFO));
375 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
376 GetVersionEx(&osver);
377 w32_platform = osver.dwPlatformId;
379 return (w32_platform);
382 /* Tokenize a string. Words are null-separated, and the list
383 * ends with a doubled null. Any character (except null and
384 * including backslash) may be escaped by preceding it with a
385 * backslash (the backslash will be stripped).
386 * Returns number of words in result buffer.
389 tokenize(char *str, char **dest, char ***destv)
391 char *retstart = Nullch;
392 char **retvstart = 0;
395 int slen = strlen(str);
397 register char **retv;
398 New(1307, ret, slen+2, char);
399 New(1308, retv, (slen+3)/2, char*);
407 if (*ret == '\\' && *str)
409 else if (*ret == ' ') {
425 retvstart[items] = Nullch;
437 if (!w32_perlshell_tokens) {
438 /* we don't use COMSPEC here for two reasons:
439 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
440 * uncontrolled unportability of the ensuing scripts.
441 * 2. PERL5SHELL could be set to a shell that may not be fit for
442 * interactive use (which is what most programs look in COMSPEC
445 char* defaultshell = (IsWinNT() ? "cmd.exe /x/c" : "command.com /c");
446 char *usershell = getenv("PERL5SHELL");
447 w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
448 &w32_perlshell_tokens,
454 do_aspawn(void *vreally, void **vmark, void **vsp)
456 SV *really = (SV*)vreally;
457 SV **mark = (SV**)vmark;
469 New(1306, argv, (sp - mark) + w32_perlshell_items + 2, char*);
471 if (SvNIOKp(*(mark+1)) && !SvPOKp(*(mark+1))) {
476 while (++mark <= sp) {
477 if (*mark && (str = SvPV(*mark, na)))
484 status = win32_spawnvp(flag,
485 (const char*)(really ? SvPV(really,na) : argv[0]),
486 (const char* const*)argv);
488 if (status < 0 && errno == ENOEXEC) {
489 /* possible shell-builtin, invoke with shell */
491 sh_items = w32_perlshell_items;
493 argv[index+sh_items] = argv[index];
494 while (--sh_items >= 0)
495 argv[sh_items] = w32_perlshell_vec[sh_items];
497 status = win32_spawnvp(flag,
498 (const char*)(really ? SvPV(really,na) : argv[0]),
499 (const char* const*)argv);
502 if (flag != P_NOWAIT) {
505 warn("Can't spawn \"%s\": %s", argv[0], strerror(errno));
510 statusvalue = status;
517 do_spawn2(char *cmd, int exectype)
523 BOOL needToTry = TRUE;
526 /* Save an extra exec if possible. See if there are shell
527 * metacharacters in it */
528 if (!has_redirection(cmd)) {
529 New(1301,argv, strlen(cmd) / 2 + 2, char*);
530 New(1302,cmd2, strlen(cmd) + 1, char);
533 for (s = cmd2; *s;) {
534 while (*s && isspace(*s))
538 while (*s && !isspace(*s))
547 status = win32_spawnvp(P_WAIT, argv[0],
548 (const char* const*)argv);
550 case EXECF_SPAWN_NOWAIT:
551 status = win32_spawnvp(P_NOWAIT, argv[0],
552 (const char* const*)argv);
555 status = win32_execvp(argv[0], (const char* const*)argv);
558 if (status != -1 || errno == 0)
568 New(1306, argv, w32_perlshell_items + 2, char*);
569 while (++i < w32_perlshell_items)
570 argv[i] = w32_perlshell_vec[i];
575 status = win32_spawnvp(P_WAIT, argv[0],
576 (const char* const*)argv);
578 case EXECF_SPAWN_NOWAIT:
579 status = win32_spawnvp(P_NOWAIT, argv[0],
580 (const char* const*)argv);
583 status = win32_execvp(argv[0], (const char* const*)argv);
589 if (exectype != EXECF_SPAWN_NOWAIT) {
592 warn("Can't %s \"%s\": %s",
593 (exectype == EXECF_EXEC ? "exec" : "spawn"),
594 cmd, strerror(errno));
599 statusvalue = status;
607 return do_spawn2(cmd, EXECF_SPAWN);
611 do_spawn_nowait(char *cmd)
613 return do_spawn2(cmd, EXECF_SPAWN_NOWAIT);
619 do_spawn2(cmd, EXECF_EXEC);
623 /* The idea here is to read all the directory names into a string table
624 * (separated by nulls) and when one of the other dir functions is called
625 * return the pointer to the current file name.
628 win32_opendir(char *filename)
633 char scanname[MAX_PATH+3];
635 WIN32_FIND_DATA FindData;
638 len = strlen(filename);
642 /* check to see if filename is a directory */
643 if (win32_stat(filename, &sbuf) < 0 || (sbuf.st_mode & S_IFDIR) == 0) {
644 /* CRT is buggy on sharenames, so make sure it really isn't */
645 DWORD r = GetFileAttributes(filename);
646 if (r == 0xffffffff || !(r & FILE_ATTRIBUTE_DIRECTORY))
650 /* Get us a DIR structure */
651 Newz(1303, p, 1, DIR);
655 /* Create the search pattern */
656 strcpy(scanname, filename);
657 if (scanname[len-1] != '/' && scanname[len-1] != '\\')
658 scanname[len++] = '/';
659 scanname[len++] = '*';
660 scanname[len] = '\0';
662 /* do the FindFirstFile call */
663 fh = FindFirstFile(scanname, &FindData);
664 if (fh == INVALID_HANDLE_VALUE) {
668 /* now allocate the first part of the string table for
669 * the filenames that we find.
671 idx = strlen(FindData.cFileName)+1;
672 New(1304, p->start, idx, char);
673 if (p->start == NULL)
674 croak("opendir: malloc failed!\n");
675 strcpy(p->start, FindData.cFileName);
678 /* loop finding all the files that match the wildcard
679 * (which should be all of them in this directory!).
680 * the variable idx should point one past the null terminator
681 * of the previous string found.
683 while (FindNextFile(fh, &FindData)) {
684 len = strlen(FindData.cFileName);
685 /* bump the string table size by enough for the
686 * new name and it's null terminator
688 Renew(p->start, idx+len+1, char);
689 if (p->start == NULL)
690 croak("opendir: malloc failed!\n");
691 strcpy(&p->start[idx], FindData.cFileName);
702 /* Readdir just returns the current string pointer and bumps the
703 * string pointer to the nDllExport entry.
706 win32_readdir(DIR *dirp)
709 static int dummy = 0;
712 /* first set up the structure to return */
713 len = strlen(dirp->curr);
714 strcpy(dirp->dirstr.d_name, dirp->curr);
715 dirp->dirstr.d_namlen = len;
718 dirp->dirstr.d_ino = dummy++;
720 /* Now set up for the nDllExport call to readdir */
721 dirp->curr += len + 1;
722 if (dirp->curr >= (dirp->start + dirp->size)) {
726 return &(dirp->dirstr);
732 /* Telldir returns the current string pointer position */
734 win32_telldir(DIR *dirp)
736 return (long) dirp->curr;
740 /* Seekdir moves the string pointer to a previously saved position
744 win32_seekdir(DIR *dirp, long loc)
746 dirp->curr = (char *)loc;
749 /* Rewinddir resets the string pointer to the start */
751 win32_rewinddir(DIR *dirp)
753 dirp->curr = dirp->start;
756 /* free the memory allocated by opendir */
758 win32_closedir(DIR *dirp)
760 Safefree(dirp->start);
773 * Just pretend that everyone is a superuser. NT will let us know if
774 * we don\'t really have permission to do something.
777 #define ROOT_UID ((uid_t)0)
778 #define ROOT_GID ((gid_t)0)
807 return (auid == ROOT_UID ? 0 : -1);
813 return (agid == ROOT_GID ? 0 : -1);
820 char *buf = getlogin_buffer;
821 DWORD size = sizeof(getlogin_buffer);
822 if (GetUserName(buf,&size))
828 chown(const char *path, uid_t owner, gid_t group)
835 remove_dead_process(HANDLE deceased)
839 for (child = 0 ; child < w32_num_children ; ++child) {
840 if (w32_child_pids[child] == deceased) {
841 Copy(&w32_child_pids[child+1], &w32_child_pids[child],
842 (w32_num_children-child-1), HANDLE);
851 win32_kill(int pid, int sig)
854 HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
856 HANDLE hProcess = (HANDLE) pid;
859 if (hProcess == NULL) {
860 croak("kill process failed!\n");
863 if (!TerminateProcess(hProcess, sig))
864 croak("kill process failed!\n");
865 CloseHandle(hProcess);
867 /* WaitForMultipleObjects() on a pid that was killed returns error
868 * so if we know the pid is gone we remove it from process list */
869 remove_dead_process(hProcess);
878 DllExport unsigned int
879 win32_sleep(unsigned int t)
886 win32_stat(const char *path, struct stat *buffer)
889 const char *p = path;
890 int l = strlen(path);
894 switch(path[l - 1]) {
897 if (path[l - 2] != ':') {
898 strncpy(t, path, l - 1);
904 res = stat(p,buffer);
907 if (S_ISDIR(buffer->st_mode))
908 buffer->st_mode |= S_IWRITE | S_IEXEC;
909 else if (S_ISREG(buffer->st_mode)) {
910 if (l >= 4 && path[l-4] == '.') {
911 const char *e = path + l - 3;
912 if (strnicmp(e,"exe",3)
913 && strnicmp(e,"bat",3)
914 && strnicmp(e,"com",3)
915 && (IsWin95() || strnicmp(e,"cmd",3)))
916 buffer->st_mode &= ~S_IEXEC;
918 buffer->st_mode |= S_IEXEC;
921 buffer->st_mode &= ~S_IEXEC;
928 #ifndef USE_WIN32_RTL_ENV
931 win32_getenv(const char *name)
933 static char *curitem = Nullch;
934 static DWORD curlen = 512;
937 New(1305,curitem,curlen,char);
939 needlen = GetEnvironmentVariable(name,curitem,curlen);
941 while (needlen > curlen) {
942 Renew(curitem,needlen,char);
944 needlen = GetEnvironmentVariable(name,curitem,curlen);
949 /* allow any environment variables that begin with 'PERL5'
950 to be stored in the registry
955 if (strncmp(name, "PERL5", 5) == 0) {
956 if (curitem != NULL) {
960 curitem = GetRegStr(name, &curitem, &curlen);
963 if(curitem != NULL && *curitem == '\0')
972 filetime_to_clock(PFILETIME ft)
974 __int64 qw = ft->dwHighDateTime;
976 qw |= ft->dwLowDateTime;
977 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
982 win32_times(struct tms *timebuf)
987 if (GetProcessTimes(GetCurrentProcess(), &dummy, &dummy,
989 timebuf->tms_utime = filetime_to_clock(&user);
990 timebuf->tms_stime = filetime_to_clock(&kernel);
991 timebuf->tms_cutime = 0;
992 timebuf->tms_cstime = 0;
995 /* That failed - e.g. Win95 fallback to clock() */
997 timebuf->tms_utime = t;
998 timebuf->tms_stime = 0;
999 timebuf->tms_cutime = 0;
1000 timebuf->tms_cstime = 0;
1005 /* fix utime() so it works on directories in NT
1006 * thanks to Jan Dubois <jan.dubois@ibm.net>
1009 filetime_from_time(PFILETIME pFileTime, time_t Time)
1011 struct tm *pTM = gmtime(&Time);
1012 SYSTEMTIME SystemTime;
1017 SystemTime.wYear = pTM->tm_year + 1900;
1018 SystemTime.wMonth = pTM->tm_mon + 1;
1019 SystemTime.wDay = pTM->tm_mday;
1020 SystemTime.wHour = pTM->tm_hour;
1021 SystemTime.wMinute = pTM->tm_min;
1022 SystemTime.wSecond = pTM->tm_sec;
1023 SystemTime.wMilliseconds = 0;
1025 return SystemTimeToFileTime(&SystemTime, pFileTime);
1029 win32_utime(const char *filename, struct utimbuf *times)
1035 struct utimbuf TimeBuffer;
1037 int rc = utime(filename,times);
1038 /* EACCES: path specifies directory or readonly file */
1039 if (rc == 0 || errno != EACCES /* || !IsWinNT() */)
1042 if (times == NULL) {
1043 times = &TimeBuffer;
1044 time(×->actime);
1045 times->modtime = times->actime;
1048 /* This will (and should) still fail on readonly files */
1049 handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
1050 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL,
1051 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1052 if (handle == INVALID_HANDLE_VALUE)
1055 if (GetFileTime(handle, &ftCreate, &ftAccess, &ftWrite) &&
1056 filetime_from_time(&ftAccess, times->actime) &&
1057 filetime_from_time(&ftWrite, times->modtime) &&
1058 SetFileTime(handle, &ftCreate, &ftAccess, &ftWrite))
1063 CloseHandle(handle);
1068 win32_waitpid(int pid, int *status, int flags)
1072 return win32_wait(status);
1074 rc = cwait(status, pid, WAIT_CHILD);
1075 /* cwait() returns differently on Borland */
1078 *status = (((*status >> 8) & 0xff) | ((*status << 8) & 0xff00));
1080 remove_dead_process((HANDLE)pid);
1082 return rc >= 0 ? pid : rc;
1086 win32_wait(int *status)
1089 return wait(status);
1091 /* XXX this wait emulation only knows about processes
1092 * spawned via win32_spawnvp(P_NOWAIT, ...).
1095 DWORD exitcode, waitcode;
1097 if (!w32_num_children) {
1102 /* if a child exists, wait for it to die */
1103 waitcode = WaitForMultipleObjects(w32_num_children,
1107 if (waitcode != WAIT_FAILED) {
1108 if (waitcode >= WAIT_ABANDONED_0
1109 && waitcode < WAIT_ABANDONED_0 + w32_num_children)
1110 i = waitcode - WAIT_ABANDONED_0;
1112 i = waitcode - WAIT_OBJECT_0;
1113 if (GetExitCodeProcess(w32_child_pids[i], &exitcode) ) {
1114 CloseHandle(w32_child_pids[i]);
1115 *status = (int)((exitcode & 0xff) << 8);
1116 retval = (int)w32_child_pids[i];
1117 Copy(&w32_child_pids[i+1], &w32_child_pids[i],
1118 (w32_num_children-i-1), HANDLE);
1125 errno = GetLastError();
1131 static UINT timerid = 0;
1133 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
1135 KillTimer(NULL,timerid);
1140 DllExport unsigned int
1141 win32_alarm(unsigned int sec)
1144 * the 'obvious' implentation is SetTimer() with a callback
1145 * which does whatever receiving SIGALRM would do
1146 * we cannot use SIGALRM even via raise() as it is not
1147 * one of the supported codes in <signal.h>
1149 * Snag is unless something is looking at the message queue
1150 * nothing happens :-(
1154 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
1156 croak("Cannot set timer");
1162 KillTimer(NULL,timerid);
1169 #ifdef HAVE_DES_FCRYPT
1170 extern char * des_fcrypt(char *cbuf, const char *txt, const char *salt);
1173 win32_crypt(const char *txt, const char *salt)
1176 return des_fcrypt(crypt_buffer, txt, salt);
1180 #ifdef USE_FIXED_OSFHANDLE
1182 EXTERN_C int __cdecl _alloc_osfhnd(void);
1183 EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
1184 EXTERN_C void __cdecl _lock_fhandle(int);
1185 EXTERN_C void __cdecl _unlock_fhandle(int);
1186 EXTERN_C void __cdecl _unlock(int);
1188 #if (_MSC_VER >= 1000)
1190 long osfhnd; /* underlying OS file HANDLE */
1191 char osfile; /* attributes of file (e.g., open in text mode?) */
1192 char pipech; /* one char buffer for handles opened on pipes */
1193 #if defined (_MT) && !defined (DLL_FOR_WIN32S)
1195 CRITICAL_SECTION lock;
1196 #endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
1199 EXTERN_C ioinfo * __pioinfo[];
1201 #define IOINFO_L2E 5
1202 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
1203 #define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
1204 #define _osfile(i) (_pioinfo(i)->osfile)
1206 #else /* (_MSC_VER >= 1000) */
1207 extern char _osfile[];
1208 #endif /* (_MSC_VER >= 1000) */
1210 #define FOPEN 0x01 /* file handle open */
1211 #define FAPPEND 0x20 /* file handle opened O_APPEND */
1212 #define FDEV 0x40 /* file handle refers to device */
1213 #define FTEXT 0x80 /* file handle is in text mode */
1215 #define _STREAM_LOCKS 26 /* Table of stream locks */
1216 #define _LAST_STREAM_LOCK (_STREAM_LOCKS+_NSTREAM_-1) /* Last stream lock */
1217 #define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
1220 *int my_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
1223 * This function allocates a free C Runtime file handle and associates
1224 * it with the Win32 HANDLE specified by the first parameter. This is a
1225 * temperary fix for WIN95's brain damage GetFileType() error on socket
1226 * we just bypass that call for socket
1229 * long osfhandle - Win32 HANDLE to associate with C Runtime file handle.
1230 * int flags - flags to associate with C Runtime file handle.
1233 * returns index of entry in fh, if successful
1234 * return -1, if no free entry is found
1238 *******************************************************************************/
1241 my_open_osfhandle(long osfhandle, int flags)
1244 char fileflags; /* _osfile flags */
1246 /* copy relevant flags from second parameter */
1249 if (flags & O_APPEND)
1250 fileflags |= FAPPEND;
1255 /* attempt to allocate a C Runtime file handle */
1256 if ((fh = _alloc_osfhnd()) == -1) {
1257 errno = EMFILE; /* too many open files */
1258 _doserrno = 0L; /* not an OS error */
1259 return -1; /* return error to caller */
1262 /* the file is open. now, set the info in _osfhnd array */
1263 _set_osfhnd(fh, osfhandle);
1265 fileflags |= FOPEN; /* mark as open */
1267 #if (_MSC_VER >= 1000)
1268 _osfile(fh) = fileflags; /* set osfile entry */
1269 _unlock_fhandle(fh);
1271 _osfile[fh] = fileflags; /* set osfile entry */
1272 _unlock(fh+_FH_LOCKS); /* unlock handle */
1275 return fh; /* return handle */
1278 #define _open_osfhandle my_open_osfhandle
1279 #endif /* USE_FIXED_OSFHANDLE */
1281 /* simulate flock by locking a range on the file */
1283 #define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
1284 #define LK_LEN 0xffff0000
1287 win32_flock(int fd, int oper)
1294 croak("flock() unimplemented on this platform");
1297 fh = (HANDLE)_get_osfhandle(fd);
1298 memset(&o, 0, sizeof(o));
1301 case LOCK_SH: /* shared lock */
1302 LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
1304 case LOCK_EX: /* exclusive lock */
1305 LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
1307 case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
1308 LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
1310 case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
1311 LK_ERR(LockFileEx(fh,
1312 LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
1313 0, LK_LEN, 0, &o),i);
1315 case LOCK_UN: /* unlock lock */
1316 LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
1318 default: /* unknown */
1329 * redirected io subsystem for all XS modules
1342 return (&(_environ));
1345 /* the rest are the remapped stdio routines */
1365 win32_ferror(FILE *fp)
1367 return (ferror(fp));
1372 win32_feof(FILE *fp)
1378 * Since the errors returned by the socket error function
1379 * WSAGetLastError() are not known by the library routine strerror
1380 * we have to roll our own.
1384 win32_strerror(int e)
1386 #ifndef __BORLANDC__ /* Borland intolerance */
1387 extern int sys_nerr;
1391 if (e < 0 || e > sys_nerr) {
1396 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
1397 strerror_buffer, sizeof(strerror_buffer), NULL) == 0)
1398 strcpy(strerror_buffer, "Unknown Error");
1400 return strerror_buffer;
1406 win32_str_os_error(void *sv, DWORD dwErr)
1410 dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
1411 |FORMAT_MESSAGE_IGNORE_INSERTS
1412 |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
1413 dwErr, 0, (char *)&sMsg, 1, NULL);
1415 while (0 < dwLen && isspace(sMsg[--dwLen]))
1417 if ('.' != sMsg[dwLen])
1422 sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
1423 dwLen = sprintf(sMsg,
1424 "Unknown error #0x%lX (lookup 0x%lX)",
1425 dwErr, GetLastError());
1427 sv_setpvn((SV*)sv, sMsg, dwLen);
1433 win32_fprintf(FILE *fp, const char *format, ...)
1436 va_start(marker, format); /* Initialize variable arguments. */
1438 return (vfprintf(fp, format, marker));
1442 win32_printf(const char *format, ...)
1445 va_start(marker, format); /* Initialize variable arguments. */
1447 return (vprintf(format, marker));
1451 win32_vfprintf(FILE *fp, const char *format, va_list args)
1453 return (vfprintf(fp, format, args));
1457 win32_vprintf(const char *format, va_list args)
1459 return (vprintf(format, args));
1463 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
1465 return fread(buf, size, count, fp);
1469 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
1471 return fwrite(buf, size, count, fp);
1475 win32_fopen(const char *filename, const char *mode)
1477 if (stricmp(filename, "/dev/null")==0)
1478 return fopen("NUL", mode);
1479 return fopen(filename, mode);
1482 #ifndef USE_SOCKETS_AS_HANDLES
1484 #define fdopen my_fdopen
1488 win32_fdopen( int handle, const char *mode)
1490 return fdopen(handle, (char *) mode);
1494 win32_freopen( const char *path, const char *mode, FILE *stream)
1496 if (stricmp(path, "/dev/null")==0)
1497 return freopen("NUL", mode, stream);
1498 return freopen(path, mode, stream);
1502 win32_fclose(FILE *pf)
1504 return my_fclose(pf); /* defined in win32sck.c */
1508 win32_fputs(const char *s,FILE *pf)
1510 return fputs(s, pf);
1514 win32_fputc(int c,FILE *pf)
1520 win32_ungetc(int c,FILE *pf)
1522 return ungetc(c,pf);
1526 win32_getc(FILE *pf)
1532 win32_fileno(FILE *pf)
1538 win32_clearerr(FILE *pf)
1545 win32_fflush(FILE *pf)
1551 win32_ftell(FILE *pf)
1557 win32_fseek(FILE *pf,long offset,int origin)
1559 return fseek(pf, offset, origin);
1563 win32_fgetpos(FILE *pf,fpos_t *p)
1565 return fgetpos(pf, p);
1569 win32_fsetpos(FILE *pf,const fpos_t *p)
1571 return fsetpos(pf, p);
1575 win32_rewind(FILE *pf)
1595 win32_fstat(int fd,struct stat *sbufptr)
1597 return fstat(fd,sbufptr);
1601 win32_pipe(int *pfd, unsigned int size, int mode)
1603 return _pipe(pfd, size, mode);
1607 * a popen() clone that respects PERL5SHELL
1611 win32_popen(const char *command, const char *mode)
1613 #ifdef USE_RTL_POPEN
1614 return _popen(command, mode);
1622 /* establish which ends read and write */
1623 if (strchr(mode,'w')) {
1624 stdfd = 0; /* stdin */
1628 else if (strchr(mode,'r')) {
1629 stdfd = 1; /* stdout */
1636 /* set the correct mode */
1637 if (strchr(mode,'b'))
1639 else if (strchr(mode,'t'))
1642 ourmode = _fmode & (O_TEXT | O_BINARY);
1644 /* the child doesn't inherit handles */
1645 ourmode |= O_NOINHERIT;
1647 if (win32_pipe( p, 512, ourmode) == -1)
1650 /* save current stdfd */
1651 if ((oldfd = win32_dup(stdfd)) == -1)
1654 /* make stdfd go to child end of pipe (implicitly closes stdfd) */
1655 /* stdfd will be inherited by the child */
1656 if (win32_dup2(p[child], stdfd) == -1)
1659 /* close the child end in parent */
1660 win32_close(p[child]);
1662 /* start the child */
1663 if ((childpid = do_spawn_nowait((char*)command)) == -1)
1666 /* revert stdfd to whatever it was before */
1667 if (win32_dup2(oldfd, stdfd) == -1)
1670 /* close saved handle */
1673 sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
1675 /* we have an fd, return a file stream */
1676 return (win32_fdopen(p[parent], (char *)mode));
1679 /* we don't need to check for errors here */
1683 win32_dup2(oldfd, stdfd);
1688 #endif /* USE_RTL_POPEN */
1696 win32_pclose(FILE *pf)
1698 #ifdef USE_RTL_POPEN
1702 int childpid, status;
1705 sv = *av_fetch(w32_fdpid, win32_fileno(pf), TRUE);
1707 childpid = SvIVX(sv);
1719 remove_dead_process((HANDLE)childpid);
1721 /* wait for the child */
1722 if (cwait(&status, childpid, WAIT_CHILD) == -1)
1724 /* cwait() returns differently on Borland */
1726 return (((status >> 8) & 0xff) | ((status << 8) & 0xff00));
1731 #endif /* USE_RTL_POPEN */
1735 win32_rename(const char *oname, const char *newname)
1737 char szNewWorkName[MAX_PATH+1];
1738 WIN32_FIND_DATA fdOldFile, fdNewFile;
1742 if ((strchr(oname, '\\') || strchr(oname, '/'))
1743 && strchr(newname, '\\') == NULL
1744 && strchr(newname, '/') == NULL)
1746 strcpy(szNewWorkName, oname);
1747 if ((ptr = strrchr(szNewWorkName, '\\')) == NULL)
1748 ptr = strrchr(szNewWorkName, '/');
1749 strcpy(++ptr, newname);
1752 strcpy(szNewWorkName, newname);
1754 if (stricmp(oname, szNewWorkName) != 0) {
1755 // check that we're not being fooled by relative paths
1756 // and only delete the new file
1758 // 2) it is not the same file as the old file
1759 // 3) old file exist
1760 // GetFullPathName does not return the long file name on some systems
1761 handle = FindFirstFile(oname, &fdOldFile);
1762 if (handle != INVALID_HANDLE_VALUE) {
1765 handle = FindFirstFile(szNewWorkName, &fdNewFile);
1767 if (handle != INVALID_HANDLE_VALUE)
1770 fdNewFile.cFileName[0] = '\0';
1772 if (strcmp(fdOldFile.cAlternateFileName,
1773 fdNewFile.cAlternateFileName) != 0
1774 && strcmp(fdOldFile.cFileName, fdNewFile.cFileName) != 0)
1776 // file exists and not same file
1777 DeleteFile(szNewWorkName);
1781 return rename(oname, newname);
1785 win32_setmode(int fd, int mode)
1787 return setmode(fd, mode);
1791 win32_lseek(int fd, long offset, int origin)
1793 return lseek(fd, offset, origin);
1803 win32_open(const char *path, int flag, ...)
1809 pmode = va_arg(ap, int);
1812 if (stricmp(path, "/dev/null")==0)
1813 return open("NUL", flag, pmode);
1814 return open(path,flag,pmode);
1836 win32_dup2(int fd1,int fd2)
1838 return dup2(fd1,fd2);
1842 win32_read(int fd, void *buf, unsigned int cnt)
1844 return read(fd, buf, cnt);
1848 win32_write(int fd, const void *buf, unsigned int cnt)
1850 return write(fd, buf, cnt);
1854 win32_mkdir(const char *dir, int mode)
1856 return mkdir(dir); /* just ignore mode */
1860 win32_rmdir(const char *dir)
1866 win32_chdir(const char *dir)
1872 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1876 #ifndef USE_RTL_WAIT
1877 if (mode == P_NOWAIT && w32_num_children >= MAXIMUM_WAIT_OBJECTS)
1881 status = spawnvp(mode, cmdname, (char * const *) argv);
1882 #ifndef USE_RTL_WAIT
1883 /* XXX For the P_NOWAIT case, Borland RTL returns pinfo.dwProcessId
1884 * while VC RTL returns pinfo.hProcess. For purposes of the custom
1885 * implementation of win32_wait(), we assume the latter.
1887 if (mode == P_NOWAIT && status >= 0)
1888 w32_child_pids[w32_num_children++] = (HANDLE)status;
1894 win32_execv(const char *cmdname, const char *const *argv)
1896 return execv(cmdname, (char *const *)argv);
1900 win32_execvp(const char *cmdname, const char *const *argv)
1902 return execvp(cmdname, (char *const *)argv);
1906 win32_perror(const char *str)
1912 win32_setbuf(FILE *pf, char *buf)
1918 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1920 return setvbuf(pf, buf, type, size);
1924 win32_flushall(void)
1930 win32_fcloseall(void)
1936 win32_fgets(char *s, int n, FILE *pf)
1938 return fgets(s, n, pf);
1948 win32_fgetc(FILE *pf)
1954 win32_putc(int c, FILE *pf)
1960 win32_puts(const char *s)
1972 win32_putchar(int c)
1979 #ifndef USE_PERL_SBRK
1981 static char *committed = NULL;
1982 static char *base = NULL;
1983 static char *reserved = NULL;
1984 static char *brk = NULL;
1985 static DWORD pagesize = 0;
1986 static DWORD allocsize = 0;
1994 GetSystemInfo(&info);
1995 /* Pretend page size is larger so we don't perpetually
1996 * call the OS to commit just one page ...
1998 pagesize = info.dwPageSize << 3;
1999 allocsize = info.dwAllocationGranularity;
2001 /* This scheme fails eventually if request for contiguous
2002 * block is denied so reserve big blocks - this is only
2003 * address space not memory ...
2005 if (brk+need >= reserved)
2007 DWORD size = 64*1024*1024;
2009 if (committed && reserved && committed < reserved)
2011 /* Commit last of previous chunk cannot span allocations */
2012 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
2014 committed = reserved;
2016 /* Reserve some (more) space
2017 * Note this is a little sneaky, 1st call passes NULL as reserved
2018 * so lets system choose where we start, subsequent calls pass
2019 * the old end address so ask for a contiguous block
2021 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
2024 reserved = addr+size;
2039 if (brk > committed)
2041 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
2042 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
2057 win32_malloc(size_t size)
2059 return malloc(size);
2063 win32_calloc(size_t numitems, size_t size)
2065 return calloc(numitems,size);
2069 win32_realloc(void *block, size_t size)
2071 return realloc(block,size);
2075 win32_free(void *block)
2082 win32_open_osfhandle(long handle, int flags)
2084 return _open_osfhandle(handle, flags);
2088 win32_get_osfhandle(int fd)
2090 return _get_osfhandle(fd);
2101 SV *sv = sv_newmortal();
2102 /* Make one call with zero size - return value is required size */
2103 DWORD len = GetCurrentDirectory((DWORD)0,NULL);
2104 SvUPGRADE(sv,SVt_PV);
2106 SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
2109 * then it worked, set PV valid,
2110 * else leave it 'undef'
2124 croak("usage: Win32::SetCurrentDirectory($cwd)");
2125 if (SetCurrentDirectory(SvPV(ST(0),na)))
2132 XS(w32_GetNextAvailDrive)
2136 char root[] = "_:\\";
2139 if (GetDriveType(root) == 1) {
2148 XS(w32_GetLastError)
2151 XSRETURN_IV(GetLastError());
2158 char *name = getlogin_buffer;
2159 DWORD size = sizeof(getlogin_buffer);
2160 if (GetUserName(name,&size)) {
2161 /* size includes NULL */
2162 ST(0) = sv_2mortal(newSVpv(name,size-1));
2172 char name[MAX_COMPUTERNAME_LENGTH+1];
2173 DWORD size = sizeof(name);
2174 if (GetComputerName(name,&size)) {
2175 /* size does NOT include NULL :-( */
2176 ST(0) = sv_2mortal(newSVpv(name,size));
2187 #ifndef HAS_NETWKSTAGETINFO
2188 /* mingw32 (and Win95) don't have NetWksta*(), so do it the old way */
2190 DWORD size = sizeof(name);
2191 if (GetUserName(name,&size)) {
2193 DWORD sidlen = sizeof(sid);
2195 DWORD dnamelen = sizeof(dname);
2197 if (LookupAccountName(NULL, name, &sid, &sidlen,
2198 dname, &dnamelen, &snu)) {
2199 XSRETURN_PV(dname); /* all that for this */
2203 /* this way is more reliable, in case user has a local account.
2204 * XXX need dynamic binding of netapi32.dll symbols or this will fail on
2205 * Win95. Probably makes more sense to move it into libwin32. */
2207 DWORD dnamelen = sizeof(dname);
2208 PWKSTA_INFO_100 pwi;
2209 if (NERR_Success == NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pwi)) {
2210 if (pwi->wki100_langroup && *(pwi->wki100_langroup)) {
2211 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup,
2212 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2215 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername,
2216 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2218 NetApiBufferFree(pwi);
2230 DWORD flags, filecomplen;
2231 if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
2232 &flags, fsname, sizeof(fsname))) {
2233 if (GIMME == G_ARRAY) {
2234 XPUSHs(sv_2mortal(newSVpv(fsname,0)));
2235 XPUSHs(sv_2mortal(newSViv(flags)));
2236 XPUSHs(sv_2mortal(newSViv(filecomplen)));
2240 XSRETURN_PV(fsname);
2246 XS(w32_GetOSVersion)
2249 OSVERSIONINFO osver;
2251 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
2252 if (GetVersionEx(&osver)) {
2253 XPUSHs(newSVpv(osver.szCSDVersion, 0));
2254 XPUSHs(newSViv(osver.dwMajorVersion));
2255 XPUSHs(newSViv(osver.dwMinorVersion));
2256 XPUSHs(newSViv(osver.dwBuildNumber));
2257 XPUSHs(newSViv(osver.dwPlatformId));
2268 XSRETURN_IV(IsWinNT());
2275 XSRETURN_IV(IsWin95());
2279 XS(w32_FormatMessage)
2286 croak("usage: Win32::FormatMessage($errno)");
2288 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
2289 &source, SvIV(ST(0)), 0,
2290 msgbuf, sizeof(msgbuf)-1, NULL))
2291 XSRETURN_PV(msgbuf);
2301 PROCESS_INFORMATION stProcInfo;
2302 STARTUPINFO stStartInfo;
2303 BOOL bSuccess = FALSE;
2306 croak("usage: Win32::Spawn($cmdName, $args, $PID)");
2308 cmd = SvPV(ST(0),na);
2309 args = SvPV(ST(1), na);
2311 memset(&stStartInfo, 0, sizeof(stStartInfo)); /* Clear the block */
2312 stStartInfo.cb = sizeof(stStartInfo); /* Set the structure size */
2313 stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
2314 stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
2317 cmd, /* Image path */
2318 args, /* Arguments for command line */
2319 NULL, /* Default process security */
2320 NULL, /* Default thread security */
2321 FALSE, /* Must be TRUE to use std handles */
2322 NORMAL_PRIORITY_CLASS, /* No special scheduling */
2323 NULL, /* Inherit our environment block */
2324 NULL, /* Inherit our currrent directory */
2325 &stStartInfo, /* -> Startup info */
2326 &stProcInfo)) /* <- Process info (if OK) */
2328 CloseHandle(stProcInfo.hThread);/* library source code does this. */
2329 sv_setiv(ST(2), stProcInfo.dwProcessId);
2332 XSRETURN_IV(bSuccess);
2336 XS(w32_GetTickCount)
2339 XSRETURN_IV(GetTickCount());
2343 XS(w32_GetShortPathName)
2350 croak("usage: Win32::GetShortPathName($longPathName)");
2352 shortpath = sv_mortalcopy(ST(0));
2353 SvUPGRADE(shortpath, SVt_PV);
2354 /* src == target is allowed */
2356 len = GetShortPathName(SvPVX(shortpath),
2359 } while (len >= SvLEN(shortpath) && sv_grow(shortpath,len+1));
2361 SvCUR_set(shortpath,len);
2374 croak("usage: Win32::Sleep($milliseconds)");
2380 Perl_init_os_extras()
2382 char *file = __FILE__;
2385 w32_perlshell_tokens = Nullch;
2386 w32_perlshell_items = -1;
2387 w32_fdpid = newAV(); /* XXX needs to be in Perl_win32_init()? */
2388 #ifndef USE_RTL_WAIT
2389 w32_num_children = 0;
2392 /* these names are Activeware compatible */
2393 newXS("Win32::GetCwd", w32_GetCwd, file);
2394 newXS("Win32::SetCwd", w32_SetCwd, file);
2395 newXS("Win32::GetNextAvailDrive", w32_GetNextAvailDrive, file);
2396 newXS("Win32::GetLastError", w32_GetLastError, file);
2397 newXS("Win32::LoginName", w32_LoginName, file);
2398 newXS("Win32::NodeName", w32_NodeName, file);
2399 newXS("Win32::DomainName", w32_DomainName, file);
2400 newXS("Win32::FsType", w32_FsType, file);
2401 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2402 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2403 newXS("Win32::IsWin95", w32_IsWin95, file);
2404 newXS("Win32::FormatMessage", w32_FormatMessage, file);
2405 newXS("Win32::Spawn", w32_Spawn, file);
2406 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2407 newXS("Win32::GetShortPathName", w32_GetShortPathName, file);
2408 newXS("Win32::Sleep", w32_Sleep, file);
2410 /* XXX Bloat Alert! The following Activeware preloads really
2411 * ought to be part of Win32::Sys::*, so they're not included
2414 /* LookupAccountName
2416 * InitiateSystemShutdown
2417 * AbortSystemShutdown
2418 * ExpandEnvrironmentStrings
2423 Perl_win32_init(int *argcp, char ***argvp)
2425 /* Disable floating point errors, Perl will trap the ones we
2426 * care about. VC++ RTL defaults to switching these off
2427 * already, but the Borland RTL doesn't. Since we don't
2428 * want to be at the vendor's whim on the default, we set
2429 * it explicitly here.
2431 #if !defined(_ALPHA_) && !defined(__GNUC__)
2432 _control87(MCW_EM, MCW_EM);
2437 #ifdef USE_BINMODE_SCRIPTS
2440 win32_strip_return(SV *sv)
2442 char *s = SvPVX(sv);
2443 char *e = s+SvCUR(sv);
2447 if (*s == '\r' && s[1] == '\n')
2457 SvCUR_set(sv,d-SvPVX(sv));