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
22 /* ugliness to work around a buggy struct definition in lmwksta.h */
29 #endif /* __MINGW32__ */
31 /* #include "config.h" */
33 #define PERLIO_NOT_STDIO 0
34 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
43 extern CPerlObj* pPerl;
51 /* assert.h conflicts with #define of assert in perl.h */
58 #if defined(_MSC_VER) || defined(__MINGW32__)
59 #include <sys/utime.h>
65 /* Mingw32 defaults to globing command line
66 * So we turn it off like this:
73 #define EXECF_SPAWN_NOWAIT 3
75 #if defined(PERL_OBJECT)
76 #undef win32_get_privlib
77 #define win32_get_privlib g_win32_get_privlib
78 #undef win32_get_sitelib
79 #define win32_get_sitelib g_win32_get_sitelib
81 #define do_aspawn g_do_aspawn
83 #define do_spawn g_do_spawn
85 #define do_exec g_do_exec
87 #define getlogin g_getlogin
90 static DWORD os_id(void);
91 static void get_shell(void);
92 static long tokenize(char *str, char **dest, char ***destv);
93 int do_spawn2(char *cmd, int exectype);
94 static BOOL has_redirection(char *ptr);
95 static long filetime_to_clock(PFILETIME ft);
96 static BOOL filetime_from_time(PFILETIME ft, time_t t);
97 static char * get_emd_part(char *leading, char *trailing, ...);
98 static void remove_dead_process(HANDLE deceased);
100 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
101 static DWORD w32_platform = (DWORD)-1;
104 # ifdef USE_DECLSPEC_THREAD
105 __declspec(thread) char strerror_buffer[512];
106 __declspec(thread) char getlogin_buffer[128];
107 __declspec(thread) char w32_perllib_root[MAX_PATH+1];
108 # ifdef HAVE_DES_FCRYPT
109 __declspec(thread) char crypt_buffer[30];
112 # define strerror_buffer (thr->i.Wstrerror_buffer)
113 # define getlogin_buffer (thr->i.Wgetlogin_buffer)
114 # define w32_perllib_root (thr->i.Ww32_perllib_root)
115 # define crypt_buffer (thr->i.Wcrypt_buffer)
118 static char strerror_buffer[512];
119 static char getlogin_buffer[128];
120 static char w32_perllib_root[MAX_PATH+1];
121 # ifdef HAVE_DES_FCRYPT
122 static char crypt_buffer[30];
128 return (os_id() == VER_PLATFORM_WIN32_WINDOWS);
133 return (os_id() == VER_PLATFORM_WIN32_NT);
137 GetRegStrFromKey(HKEY hkey, const char *lpszValueName, char** ptr, DWORD* lpDataLen)
138 { /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
141 const char *subkey = "Software\\Perl";
144 retval = RegOpenKeyEx(hkey, subkey, 0, KEY_READ, &handle);
145 if (retval == ERROR_SUCCESS){
146 retval = RegQueryValueEx(handle, lpszValueName, 0, &type, NULL, lpDataLen);
147 if (retval == ERROR_SUCCESS && type == REG_SZ) {
149 Renew(*ptr, *lpDataLen, char);
152 New(1312, *ptr, *lpDataLen, char);
154 retval = RegQueryValueEx(handle, lpszValueName, 0, NULL, (PBYTE)*ptr, lpDataLen);
155 if (retval != ERROR_SUCCESS) {
166 GetRegStr(const char *lpszValueName, char** ptr, DWORD* lpDataLen)
168 *ptr = GetRegStrFromKey(HKEY_CURRENT_USER, lpszValueName, ptr, lpDataLen);
171 *ptr = GetRegStrFromKey(HKEY_LOCAL_MACHINE, lpszValueName, ptr, lpDataLen);
177 get_emd_part(char *prev_path, char *trailing_path, ...)
180 char mod_name[MAX_PATH+1];
184 int oldsize, newsize;
186 va_start(ap, trailing_path);
187 strip = va_arg(ap, char *);
189 GetModuleFileName((w32_perldll_handle == INVALID_HANDLE_VALUE)
190 ? GetModuleHandle(NULL)
191 : w32_perldll_handle, mod_name, sizeof(mod_name));
192 ptr = strrchr(mod_name, '\\');
193 while (ptr && strip) {
194 /* look for directories to skip back */
197 ptr = strrchr(mod_name, '\\');
198 if (!ptr || stricmp(ptr+1, strip) != 0) {
202 strip = va_arg(ap, char *);
210 strcpy(++ptr, trailing_path);
212 newsize = strlen(mod_name) + 1;
214 oldsize = strlen(prev_path) + 1;
215 newsize += oldsize; /* includes plus 1 for ';' */
216 Renew(prev_path, newsize, char);
217 prev_path[oldsize-1] = ';';
218 strcpy(&prev_path[oldsize], mod_name);
221 New(1311, prev_path, newsize, char);
222 strcpy(prev_path, mod_name);
229 win32_get_privlib(char *pl)
231 char *stdlib = "lib";
232 char buffer[MAX_PATH+1];
236 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
237 sprintf(buffer, "%s-%s", stdlib, pl);
238 path = GetRegStr(buffer, &path, &datalen);
240 path = GetRegStr(stdlib, &path, &datalen);
242 /* $stdlib .= ";$EMD/../../lib" */
243 return get_emd_part(path, stdlib, ARCHNAME, "bin", Nullch);
247 win32_get_sitelib(char *pl)
249 char *sitelib = "sitelib";
251 char pathstr[MAX_PATH+1];
253 char *path1 = Nullch;
254 char *path2 = Nullch;
257 /* $HKCU{"sitelib-$]"} || $HKLM{"sitelib-$]"} . ---; */
258 sprintf(regstr, "%s-%s", sitelib, pl);
259 path1 = GetRegStr(regstr, &path1, &datalen);
262 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/site/$]/lib"; */
263 sprintf(pathstr, "site\\%s\\lib", pl);
264 path1 = get_emd_part(path1, pathstr, ARCHNAME, "bin", pl, Nullch);
266 /* $HKCU{'sitelib'} || $HKLM{'sitelib'} . ---; */
267 path2 = GetRegStr(sitelib, &path2, &datalen);
270 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/site/lib"; */
271 path2 = get_emd_part(path2, "site\\lib", ARCHNAME, "bin", pl, Nullch);
280 newsize = len + strlen(path2) + 2; /* plus one for ';' */
282 Renew(path1, newsize, char);
284 strcpy(&path1[len], path2);
292 has_redirection(char *ptr)
298 * Scan string looking for redirection (< or >) or pipe
299 * characters (|) that are not in a quoted string
329 #if !defined(PERL_OBJECT)
330 /* since the current process environment is being updated in util.c
331 * the library functions will get the correct environment
334 my_popen(char *cmd, char *mode)
337 #define fixcmd(x) { \
338 char *pspace = strchr((x),' '); \
341 while (p < pspace) { \
352 win32_fflush(stdout);
353 win32_fflush(stderr);
354 return win32_popen(cmd, mode);
358 my_pclose(PerlIO *fp)
360 return win32_pclose(fp);
367 static OSVERSIONINFO osver;
369 if (osver.dwPlatformId != w32_platform) {
370 memset(&osver, 0, sizeof(OSVERSIONINFO));
371 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
372 GetVersionEx(&osver);
373 w32_platform = osver.dwPlatformId;
375 return (w32_platform);
378 /* Tokenize a string. Words are null-separated, and the list
379 * ends with a doubled null. Any character (except null and
380 * including backslash) may be escaped by preceding it with a
381 * backslash (the backslash will be stripped).
382 * Returns number of words in result buffer.
385 tokenize(char *str, char **dest, char ***destv)
387 char *retstart = Nullch;
388 char **retvstart = 0;
391 int slen = strlen(str);
393 register char **retv;
394 New(1307, ret, slen+2, char);
395 New(1308, retv, (slen+3)/2, char*);
403 if (*ret == '\\' && *str)
405 else if (*ret == ' ') {
421 retvstart[items] = Nullch;
433 if (!w32_perlshell_tokens) {
434 /* we don't use COMSPEC here for two reasons:
435 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
436 * uncontrolled unportability of the ensuing scripts.
437 * 2. PERL5SHELL could be set to a shell that may not be fit for
438 * interactive use (which is what most programs look in COMSPEC
441 char* defaultshell = (IsWinNT() ? "cmd.exe /x/c" : "command.com /c");
442 char *usershell = getenv("PERL5SHELL");
443 w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
444 &w32_perlshell_tokens,
450 do_aspawn(void *vreally, void **vmark, void **vsp)
452 SV *really = (SV*)vreally;
453 SV **mark = (SV**)vmark;
465 New(1306, argv, (sp - mark) + w32_perlshell_items + 2, char*);
467 if (SvNIOKp(*(mark+1)) && !SvPOKp(*(mark+1))) {
472 while (++mark <= sp) {
473 if (*mark && (str = SvPV(*mark, PL_na)))
480 status = win32_spawnvp(flag,
481 (const char*)(really ? SvPV(really,PL_na) : argv[0]),
482 (const char* const*)argv);
484 if (status < 0 && errno == ENOEXEC) {
485 /* possible shell-builtin, invoke with shell */
487 sh_items = w32_perlshell_items;
489 argv[index+sh_items] = argv[index];
490 while (--sh_items >= 0)
491 argv[sh_items] = w32_perlshell_vec[sh_items];
493 status = win32_spawnvp(flag,
494 (const char*)(really ? SvPV(really,PL_na) : argv[0]),
495 (const char* const*)argv);
498 if (flag != P_NOWAIT) {
501 warn("Can't spawn \"%s\": %s", argv[0], strerror(errno));
506 PL_statusvalue = status;
513 do_spawn2(char *cmd, int exectype)
519 BOOL needToTry = TRUE;
522 /* Save an extra exec if possible. See if there are shell
523 * metacharacters in it */
524 if (!has_redirection(cmd)) {
525 New(1301,argv, strlen(cmd) / 2 + 2, char*);
526 New(1302,cmd2, strlen(cmd) + 1, char);
529 for (s = cmd2; *s;) {
530 while (*s && isspace(*s))
534 while (*s && !isspace(*s))
543 status = win32_spawnvp(P_WAIT, argv[0],
544 (const char* const*)argv);
546 case EXECF_SPAWN_NOWAIT:
547 status = win32_spawnvp(P_NOWAIT, argv[0],
548 (const char* const*)argv);
551 status = win32_execvp(argv[0], (const char* const*)argv);
554 if (status != -1 || errno == 0)
564 New(1306, argv, w32_perlshell_items + 2, char*);
565 while (++i < w32_perlshell_items)
566 argv[i] = w32_perlshell_vec[i];
571 status = win32_spawnvp(P_WAIT, argv[0],
572 (const char* const*)argv);
574 case EXECF_SPAWN_NOWAIT:
575 status = win32_spawnvp(P_NOWAIT, argv[0],
576 (const char* const*)argv);
579 status = win32_execvp(argv[0], (const char* const*)argv);
585 if (exectype != EXECF_SPAWN_NOWAIT) {
588 warn("Can't %s \"%s\": %s",
589 (exectype == EXECF_EXEC ? "exec" : "spawn"),
590 cmd, strerror(errno));
595 PL_statusvalue = status;
603 return do_spawn2(cmd, EXECF_SPAWN);
607 do_spawn_nowait(char *cmd)
609 return do_spawn2(cmd, EXECF_SPAWN_NOWAIT);
615 do_spawn2(cmd, EXECF_EXEC);
619 /* The idea here is to read all the directory names into a string table
620 * (separated by nulls) and when one of the other dir functions is called
621 * return the pointer to the current file name.
624 win32_opendir(char *filename)
629 char scanname[MAX_PATH+3];
631 WIN32_FIND_DATA FindData;
634 len = strlen(filename);
638 /* check to see if filename is a directory */
639 if (win32_stat(filename, &sbuf) < 0 || (sbuf.st_mode & S_IFDIR) == 0) {
640 /* CRT is buggy on sharenames, so make sure it really isn't */
641 DWORD r = GetFileAttributes(filename);
642 if (r == 0xffffffff || !(r & FILE_ATTRIBUTE_DIRECTORY))
646 /* Get us a DIR structure */
647 Newz(1303, p, 1, DIR);
651 /* Create the search pattern */
652 strcpy(scanname, filename);
653 if (scanname[len-1] != '/' && scanname[len-1] != '\\')
654 scanname[len++] = '/';
655 scanname[len++] = '*';
656 scanname[len] = '\0';
658 /* do the FindFirstFile call */
659 fh = FindFirstFile(scanname, &FindData);
660 if (fh == INVALID_HANDLE_VALUE) {
664 /* now allocate the first part of the string table for
665 * the filenames that we find.
667 idx = strlen(FindData.cFileName)+1;
668 New(1304, p->start, idx, char);
669 if (p->start == NULL)
670 croak("opendir: malloc failed!\n");
671 strcpy(p->start, FindData.cFileName);
674 /* loop finding all the files that match the wildcard
675 * (which should be all of them in this directory!).
676 * the variable idx should point one past the null terminator
677 * of the previous string found.
679 while (FindNextFile(fh, &FindData)) {
680 len = strlen(FindData.cFileName);
681 /* bump the string table size by enough for the
682 * new name and it's null terminator
684 Renew(p->start, idx+len+1, char);
685 if (p->start == NULL)
686 croak("opendir: malloc failed!\n");
687 strcpy(&p->start[idx], FindData.cFileName);
698 /* Readdir just returns the current string pointer and bumps the
699 * string pointer to the nDllExport entry.
702 win32_readdir(DIR *dirp)
705 static int dummy = 0;
708 /* first set up the structure to return */
709 len = strlen(dirp->curr);
710 strcpy(dirp->dirstr.d_name, dirp->curr);
711 dirp->dirstr.d_namlen = len;
714 dirp->dirstr.d_ino = dummy++;
716 /* Now set up for the nDllExport call to readdir */
717 dirp->curr += len + 1;
718 if (dirp->curr >= (dirp->start + dirp->size)) {
722 return &(dirp->dirstr);
728 /* Telldir returns the current string pointer position */
730 win32_telldir(DIR *dirp)
732 return (long) dirp->curr;
736 /* Seekdir moves the string pointer to a previously saved position
740 win32_seekdir(DIR *dirp, long loc)
742 dirp->curr = (char *)loc;
745 /* Rewinddir resets the string pointer to the start */
747 win32_rewinddir(DIR *dirp)
749 dirp->curr = dirp->start;
752 /* free the memory allocated by opendir */
754 win32_closedir(DIR *dirp)
756 Safefree(dirp->start);
769 * Just pretend that everyone is a superuser. NT will let us know if
770 * we don\'t really have permission to do something.
773 #define ROOT_UID ((uid_t)0)
774 #define ROOT_GID ((gid_t)0)
803 return (auid == ROOT_UID ? 0 : -1);
809 return (agid == ROOT_GID ? 0 : -1);
816 char *buf = getlogin_buffer;
817 DWORD size = sizeof(getlogin_buffer);
818 if (GetUserName(buf,&size))
824 chown(const char *path, uid_t owner, gid_t group)
831 remove_dead_process(HANDLE deceased)
835 for (child = 0 ; child < w32_num_children ; ++child) {
836 if (w32_child_pids[child] == deceased) {
837 Copy(&w32_child_pids[child+1], &w32_child_pids[child],
838 (w32_num_children-child-1), HANDLE);
847 win32_kill(int pid, int sig)
850 HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
852 HANDLE hProcess = (HANDLE) pid;
855 if (hProcess == NULL) {
856 croak("kill process failed!\n");
859 if (!TerminateProcess(hProcess, sig))
860 croak("kill process failed!\n");
861 CloseHandle(hProcess);
863 /* WaitForMultipleObjects() on a pid that was killed returns error
864 * so if we know the pid is gone we remove it from process list */
865 remove_dead_process(hProcess);
874 DllExport unsigned int
875 win32_sleep(unsigned int t)
882 win32_stat(const char *path, struct stat *buffer)
885 const char *p = path;
886 int l = strlen(path);
890 switch(path[l - 1]) {
893 if (path[l - 2] != ':') {
894 strncpy(t, path, l - 1);
900 res = stat(p,buffer);
903 if (S_ISDIR(buffer->st_mode))
904 buffer->st_mode |= S_IWRITE | S_IEXEC;
905 else if (S_ISREG(buffer->st_mode)) {
906 if (l >= 4 && path[l-4] == '.') {
907 const char *e = path + l - 3;
908 if (strnicmp(e,"exe",3)
909 && strnicmp(e,"bat",3)
910 && strnicmp(e,"com",3)
911 && (IsWin95() || strnicmp(e,"cmd",3)))
912 buffer->st_mode &= ~S_IEXEC;
914 buffer->st_mode |= S_IEXEC;
917 buffer->st_mode &= ~S_IEXEC;
924 #ifndef USE_WIN32_RTL_ENV
927 win32_getenv(const char *name)
929 static char *curitem = Nullch; /* XXX threadead */
930 static DWORD curlen = 512; /* XXX threadead */
933 New(1305,curitem,curlen,char);
935 needlen = GetEnvironmentVariable(name,curitem,curlen);
937 while (needlen > curlen) {
938 Renew(curitem,needlen,char);
940 needlen = GetEnvironmentVariable(name,curitem,curlen);
944 /* allow any environment variables that begin with 'PERL'
945 to be stored in the registry */
949 if (strncmp(name, "PERL", 4) == 0) {
954 curitem = GetRegStr(name, &curitem, &curlen);
957 if (curitem && *curitem == '\0')
966 filetime_to_clock(PFILETIME ft)
968 __int64 qw = ft->dwHighDateTime;
970 qw |= ft->dwLowDateTime;
971 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
976 win32_times(struct tms *timebuf)
981 if (GetProcessTimes(GetCurrentProcess(), &dummy, &dummy,
983 timebuf->tms_utime = filetime_to_clock(&user);
984 timebuf->tms_stime = filetime_to_clock(&kernel);
985 timebuf->tms_cutime = 0;
986 timebuf->tms_cstime = 0;
989 /* That failed - e.g. Win95 fallback to clock() */
991 timebuf->tms_utime = t;
992 timebuf->tms_stime = 0;
993 timebuf->tms_cutime = 0;
994 timebuf->tms_cstime = 0;
999 /* fix utime() so it works on directories in NT
1000 * thanks to Jan Dubois <jan.dubois@ibm.net>
1003 filetime_from_time(PFILETIME pFileTime, time_t Time)
1005 struct tm *pTM = gmtime(&Time);
1006 SYSTEMTIME SystemTime;
1011 SystemTime.wYear = pTM->tm_year + 1900;
1012 SystemTime.wMonth = pTM->tm_mon + 1;
1013 SystemTime.wDay = pTM->tm_mday;
1014 SystemTime.wHour = pTM->tm_hour;
1015 SystemTime.wMinute = pTM->tm_min;
1016 SystemTime.wSecond = pTM->tm_sec;
1017 SystemTime.wMilliseconds = 0;
1019 return SystemTimeToFileTime(&SystemTime, pFileTime);
1023 win32_utime(const char *filename, struct utimbuf *times)
1029 struct utimbuf TimeBuffer;
1031 int rc = utime(filename,times);
1032 /* EACCES: path specifies directory or readonly file */
1033 if (rc == 0 || errno != EACCES /* || !IsWinNT() */)
1036 if (times == NULL) {
1037 times = &TimeBuffer;
1038 time(×->actime);
1039 times->modtime = times->actime;
1042 /* This will (and should) still fail on readonly files */
1043 handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
1044 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL,
1045 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1046 if (handle == INVALID_HANDLE_VALUE)
1049 if (GetFileTime(handle, &ftCreate, &ftAccess, &ftWrite) &&
1050 filetime_from_time(&ftAccess, times->actime) &&
1051 filetime_from_time(&ftWrite, times->modtime) &&
1052 SetFileTime(handle, &ftCreate, &ftAccess, &ftWrite))
1057 CloseHandle(handle);
1062 win32_waitpid(int pid, int *status, int flags)
1066 return win32_wait(status);
1068 rc = cwait(status, pid, WAIT_CHILD);
1069 /* cwait() returns differently on Borland */
1072 *status = (((*status >> 8) & 0xff) | ((*status << 8) & 0xff00));
1074 remove_dead_process((HANDLE)pid);
1076 return rc >= 0 ? pid : rc;
1080 win32_wait(int *status)
1083 return wait(status);
1085 /* XXX this wait emulation only knows about processes
1086 * spawned via win32_spawnvp(P_NOWAIT, ...).
1089 DWORD exitcode, waitcode;
1091 if (!w32_num_children) {
1096 /* if a child exists, wait for it to die */
1097 waitcode = WaitForMultipleObjects(w32_num_children,
1101 if (waitcode != WAIT_FAILED) {
1102 if (waitcode >= WAIT_ABANDONED_0
1103 && waitcode < WAIT_ABANDONED_0 + w32_num_children)
1104 i = waitcode - WAIT_ABANDONED_0;
1106 i = waitcode - WAIT_OBJECT_0;
1107 if (GetExitCodeProcess(w32_child_pids[i], &exitcode) ) {
1108 CloseHandle(w32_child_pids[i]);
1109 *status = (int)((exitcode & 0xff) << 8);
1110 retval = (int)w32_child_pids[i];
1111 Copy(&w32_child_pids[i+1], &w32_child_pids[i],
1112 (w32_num_children-i-1), HANDLE);
1119 errno = GetLastError();
1125 static UINT timerid = 0;
1127 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
1129 KillTimer(NULL,timerid);
1134 DllExport unsigned int
1135 win32_alarm(unsigned int sec)
1138 * the 'obvious' implentation is SetTimer() with a callback
1139 * which does whatever receiving SIGALRM would do
1140 * we cannot use SIGALRM even via raise() as it is not
1141 * one of the supported codes in <signal.h>
1143 * Snag is unless something is looking at the message queue
1144 * nothing happens :-(
1148 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
1150 croak("Cannot set timer");
1156 KillTimer(NULL,timerid);
1163 #if defined(HAVE_DES_FCRYPT) || defined(PERL_OBJECT)
1164 #ifdef HAVE_DES_FCRYPT
1165 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
1169 win32_crypt(const char *txt, const char *salt)
1171 #ifdef HAVE_DES_FCRYPT
1173 return des_fcrypt(txt, salt, crypt_buffer);
1175 die("The crypt() function is unimplemented due to excessive paranoia.");
1181 #ifdef USE_FIXED_OSFHANDLE
1183 EXTERN_C int __cdecl _alloc_osfhnd(void);
1184 EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
1185 EXTERN_C void __cdecl _lock_fhandle(int);
1186 EXTERN_C void __cdecl _unlock_fhandle(int);
1187 EXTERN_C void __cdecl _unlock(int);
1189 #if (_MSC_VER >= 1000)
1191 long osfhnd; /* underlying OS file HANDLE */
1192 char osfile; /* attributes of file (e.g., open in text mode?) */
1193 char pipech; /* one char buffer for handles opened on pipes */
1194 #if defined (_MT) && !defined (DLL_FOR_WIN32S)
1196 CRITICAL_SECTION lock;
1197 #endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
1200 EXTERN_C ioinfo * __pioinfo[];
1202 #define IOINFO_L2E 5
1203 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
1204 #define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
1205 #define _osfile(i) (_pioinfo(i)->osfile)
1207 #else /* (_MSC_VER >= 1000) */
1208 extern char _osfile[];
1209 #endif /* (_MSC_VER >= 1000) */
1211 #define FOPEN 0x01 /* file handle open */
1212 #define FAPPEND 0x20 /* file handle opened O_APPEND */
1213 #define FDEV 0x40 /* file handle refers to device */
1214 #define FTEXT 0x80 /* file handle is in text mode */
1216 #define _STREAM_LOCKS 26 /* Table of stream locks */
1217 #define _LAST_STREAM_LOCK (_STREAM_LOCKS+_NSTREAM_-1) /* Last stream lock */
1218 #define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
1221 *int my_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
1224 * This function allocates a free C Runtime file handle and associates
1225 * it with the Win32 HANDLE specified by the first parameter. This is a
1226 * temperary fix for WIN95's brain damage GetFileType() error on socket
1227 * we just bypass that call for socket
1230 * long osfhandle - Win32 HANDLE to associate with C Runtime file handle.
1231 * int flags - flags to associate with C Runtime file handle.
1234 * returns index of entry in fh, if successful
1235 * return -1, if no free entry is found
1239 *******************************************************************************/
1242 my_open_osfhandle(long osfhandle, int flags)
1245 char fileflags; /* _osfile flags */
1247 /* copy relevant flags from second parameter */
1250 if (flags & O_APPEND)
1251 fileflags |= FAPPEND;
1256 /* attempt to allocate a C Runtime file handle */
1257 if ((fh = _alloc_osfhnd()) == -1) {
1258 errno = EMFILE; /* too many open files */
1259 _doserrno = 0L; /* not an OS error */
1260 return -1; /* return error to caller */
1263 /* the file is open. now, set the info in _osfhnd array */
1264 _set_osfhnd(fh, osfhandle);
1266 fileflags |= FOPEN; /* mark as open */
1268 #if (_MSC_VER >= 1000)
1269 _osfile(fh) = fileflags; /* set osfile entry */
1270 _unlock_fhandle(fh);
1272 _osfile[fh] = fileflags; /* set osfile entry */
1273 _unlock(fh+_FH_LOCKS); /* unlock handle */
1276 return fh; /* return handle */
1279 #define _open_osfhandle my_open_osfhandle
1280 #endif /* USE_FIXED_OSFHANDLE */
1282 /* simulate flock by locking a range on the file */
1284 #define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
1285 #define LK_LEN 0xffff0000
1288 win32_flock(int fd, int oper)
1295 croak("flock() unimplemented on this platform");
1298 fh = (HANDLE)_get_osfhandle(fd);
1299 memset(&o, 0, sizeof(o));
1302 case LOCK_SH: /* shared lock */
1303 LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
1305 case LOCK_EX: /* exclusive lock */
1306 LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
1308 case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
1309 LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
1311 case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
1312 LK_ERR(LockFileEx(fh,
1313 LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
1314 0, LK_LEN, 0, &o),i);
1316 case LOCK_UN: /* unlock lock */
1317 LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
1319 default: /* unknown */
1330 * redirected io subsystem for all XS modules
1343 return (&(_environ));
1346 /* the rest are the remapped stdio routines */
1366 win32_ferror(FILE *fp)
1368 return (ferror(fp));
1373 win32_feof(FILE *fp)
1379 * Since the errors returned by the socket error function
1380 * WSAGetLastError() are not known by the library routine strerror
1381 * we have to roll our own.
1385 win32_strerror(int e)
1387 #ifndef __BORLANDC__ /* Borland intolerance */
1388 extern int sys_nerr;
1392 if (e < 0 || e > sys_nerr) {
1397 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
1398 strerror_buffer, sizeof(strerror_buffer), NULL) == 0)
1399 strcpy(strerror_buffer, "Unknown Error");
1401 return strerror_buffer;
1407 win32_str_os_error(void *sv, DWORD dwErr)
1411 dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
1412 |FORMAT_MESSAGE_IGNORE_INSERTS
1413 |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
1414 dwErr, 0, (char *)&sMsg, 1, NULL);
1416 while (0 < dwLen && isspace(sMsg[--dwLen]))
1418 if ('.' != sMsg[dwLen])
1423 sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
1424 dwLen = sprintf(sMsg,
1425 "Unknown error #0x%lX (lookup 0x%lX)",
1426 dwErr, GetLastError());
1428 sv_setpvn((SV*)sv, sMsg, dwLen);
1434 win32_fprintf(FILE *fp, const char *format, ...)
1437 va_start(marker, format); /* Initialize variable arguments. */
1439 return (vfprintf(fp, format, marker));
1443 win32_printf(const char *format, ...)
1446 va_start(marker, format); /* Initialize variable arguments. */
1448 return (vprintf(format, marker));
1452 win32_vfprintf(FILE *fp, const char *format, va_list args)
1454 return (vfprintf(fp, format, args));
1458 win32_vprintf(const char *format, va_list args)
1460 return (vprintf(format, args));
1464 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
1466 return fread(buf, size, count, fp);
1470 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
1472 return fwrite(buf, size, count, fp);
1476 win32_fopen(const char *filename, const char *mode)
1478 if (stricmp(filename, "/dev/null")==0)
1479 return fopen("NUL", mode);
1480 return fopen(filename, mode);
1483 #ifndef USE_SOCKETS_AS_HANDLES
1485 #define fdopen my_fdopen
1489 win32_fdopen( int handle, const char *mode)
1491 return fdopen(handle, (char *) mode);
1495 win32_freopen( const char *path, const char *mode, FILE *stream)
1497 if (stricmp(path, "/dev/null")==0)
1498 return freopen("NUL", mode, stream);
1499 return freopen(path, mode, stream);
1503 win32_fclose(FILE *pf)
1505 return my_fclose(pf); /* defined in win32sck.c */
1509 win32_fputs(const char *s,FILE *pf)
1511 return fputs(s, pf);
1515 win32_fputc(int c,FILE *pf)
1521 win32_ungetc(int c,FILE *pf)
1523 return ungetc(c,pf);
1527 win32_getc(FILE *pf)
1533 win32_fileno(FILE *pf)
1539 win32_clearerr(FILE *pf)
1546 win32_fflush(FILE *pf)
1552 win32_ftell(FILE *pf)
1558 win32_fseek(FILE *pf,long offset,int origin)
1560 return fseek(pf, offset, origin);
1564 win32_fgetpos(FILE *pf,fpos_t *p)
1566 return fgetpos(pf, p);
1570 win32_fsetpos(FILE *pf,const fpos_t *p)
1572 return fsetpos(pf, p);
1576 win32_rewind(FILE *pf)
1596 win32_fstat(int fd,struct stat *sbufptr)
1598 return fstat(fd,sbufptr);
1602 win32_pipe(int *pfd, unsigned int size, int mode)
1604 return _pipe(pfd, size, mode);
1608 * a popen() clone that respects PERL5SHELL
1612 win32_popen(const char *command, const char *mode)
1614 #ifdef USE_RTL_POPEN
1615 return _popen(command, mode);
1623 /* establish which ends read and write */
1624 if (strchr(mode,'w')) {
1625 stdfd = 0; /* stdin */
1629 else if (strchr(mode,'r')) {
1630 stdfd = 1; /* stdout */
1637 /* set the correct mode */
1638 if (strchr(mode,'b'))
1640 else if (strchr(mode,'t'))
1643 ourmode = _fmode & (O_TEXT | O_BINARY);
1645 /* the child doesn't inherit handles */
1646 ourmode |= O_NOINHERIT;
1648 if (win32_pipe( p, 512, ourmode) == -1)
1651 /* save current stdfd */
1652 if ((oldfd = win32_dup(stdfd)) == -1)
1655 /* make stdfd go to child end of pipe (implicitly closes stdfd) */
1656 /* stdfd will be inherited by the child */
1657 if (win32_dup2(p[child], stdfd) == -1)
1660 /* close the child end in parent */
1661 win32_close(p[child]);
1663 /* start the child */
1664 if ((childpid = do_spawn_nowait((char*)command)) == -1)
1667 /* revert stdfd to whatever it was before */
1668 if (win32_dup2(oldfd, stdfd) == -1)
1671 /* close saved handle */
1674 sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
1676 /* we have an fd, return a file stream */
1677 return (win32_fdopen(p[parent], (char *)mode));
1680 /* we don't need to check for errors here */
1684 win32_dup2(oldfd, stdfd);
1689 #endif /* USE_RTL_POPEN */
1697 win32_pclose(FILE *pf)
1699 #ifdef USE_RTL_POPEN
1703 int childpid, status;
1706 sv = *av_fetch(w32_fdpid, win32_fileno(pf), TRUE);
1708 childpid = SvIVX(sv);
1720 remove_dead_process((HANDLE)childpid);
1722 /* wait for the child */
1723 if (cwait(&status, childpid, WAIT_CHILD) == -1)
1725 /* cwait() returns differently on Borland */
1727 return (((status >> 8) & 0xff) | ((status << 8) & 0xff00));
1732 #endif /* USE_RTL_POPEN */
1736 win32_rename(const char *oname, const char *newname)
1738 char szNewWorkName[MAX_PATH+1];
1739 WIN32_FIND_DATA fdOldFile, fdNewFile;
1743 if ((strchr(oname, '\\') || strchr(oname, '/'))
1744 && strchr(newname, '\\') == NULL
1745 && strchr(newname, '/') == NULL)
1747 strcpy(szNewWorkName, oname);
1748 if ((ptr = strrchr(szNewWorkName, '\\')) == NULL)
1749 ptr = strrchr(szNewWorkName, '/');
1750 strcpy(++ptr, newname);
1753 strcpy(szNewWorkName, newname);
1755 if (stricmp(oname, szNewWorkName) != 0) {
1756 // check that we're not being fooled by relative paths
1757 // and only delete the new file
1759 // 2) it is not the same file as the old file
1760 // 3) old file exist
1761 // GetFullPathName does not return the long file name on some systems
1762 handle = FindFirstFile(oname, &fdOldFile);
1763 if (handle != INVALID_HANDLE_VALUE) {
1766 handle = FindFirstFile(szNewWorkName, &fdNewFile);
1768 if (handle != INVALID_HANDLE_VALUE)
1771 fdNewFile.cFileName[0] = '\0';
1773 if (strcmp(fdOldFile.cAlternateFileName,
1774 fdNewFile.cAlternateFileName) != 0
1775 && strcmp(fdOldFile.cFileName, fdNewFile.cFileName) != 0)
1777 // file exists and not same file
1778 DeleteFile(szNewWorkName);
1782 return rename(oname, newname);
1786 win32_setmode(int fd, int mode)
1788 return setmode(fd, mode);
1792 win32_lseek(int fd, long offset, int origin)
1794 return lseek(fd, offset, origin);
1804 win32_open(const char *path, int flag, ...)
1810 pmode = va_arg(ap, int);
1813 if (stricmp(path, "/dev/null")==0)
1814 return open("NUL", flag, pmode);
1815 return open(path,flag,pmode);
1837 win32_dup2(int fd1,int fd2)
1839 return dup2(fd1,fd2);
1843 win32_read(int fd, void *buf, unsigned int cnt)
1845 return read(fd, buf, cnt);
1849 win32_write(int fd, const void *buf, unsigned int cnt)
1851 return write(fd, buf, cnt);
1855 win32_mkdir(const char *dir, int mode)
1857 return mkdir(dir); /* just ignore mode */
1861 win32_rmdir(const char *dir)
1867 win32_chdir(const char *dir)
1873 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1877 #ifndef USE_RTL_WAIT
1878 if (mode == P_NOWAIT && w32_num_children >= MAXIMUM_WAIT_OBJECTS)
1882 status = spawnvp(mode, cmdname, (char * const *) argv);
1883 #ifndef USE_RTL_WAIT
1884 /* XXX For the P_NOWAIT case, Borland RTL returns pinfo.dwProcessId
1885 * while VC RTL returns pinfo.hProcess. For purposes of the custom
1886 * implementation of win32_wait(), we assume the latter.
1888 if (mode == P_NOWAIT && status >= 0)
1889 w32_child_pids[w32_num_children++] = (HANDLE)status;
1895 win32_execv(const char *cmdname, const char *const *argv)
1897 return execv(cmdname, (char *const *)argv);
1901 win32_execvp(const char *cmdname, const char *const *argv)
1903 return execvp(cmdname, (char *const *)argv);
1907 win32_perror(const char *str)
1913 win32_setbuf(FILE *pf, char *buf)
1919 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1921 return setvbuf(pf, buf, type, size);
1925 win32_flushall(void)
1931 win32_fcloseall(void)
1937 win32_fgets(char *s, int n, FILE *pf)
1939 return fgets(s, n, pf);
1949 win32_fgetc(FILE *pf)
1955 win32_putc(int c, FILE *pf)
1961 win32_puts(const char *s)
1973 win32_putchar(int c)
1980 #ifndef USE_PERL_SBRK
1982 static char *committed = NULL;
1983 static char *base = NULL;
1984 static char *reserved = NULL;
1985 static char *brk = NULL;
1986 static DWORD pagesize = 0;
1987 static DWORD allocsize = 0;
1995 GetSystemInfo(&info);
1996 /* Pretend page size is larger so we don't perpetually
1997 * call the OS to commit just one page ...
1999 pagesize = info.dwPageSize << 3;
2000 allocsize = info.dwAllocationGranularity;
2002 /* This scheme fails eventually if request for contiguous
2003 * block is denied so reserve big blocks - this is only
2004 * address space not memory ...
2006 if (brk+need >= reserved)
2008 DWORD size = 64*1024*1024;
2010 if (committed && reserved && committed < reserved)
2012 /* Commit last of previous chunk cannot span allocations */
2013 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
2015 committed = reserved;
2017 /* Reserve some (more) space
2018 * Note this is a little sneaky, 1st call passes NULL as reserved
2019 * so lets system choose where we start, subsequent calls pass
2020 * the old end address so ask for a contiguous block
2022 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
2025 reserved = addr+size;
2040 if (brk > committed)
2042 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
2043 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
2058 win32_malloc(size_t size)
2060 return malloc(size);
2064 win32_calloc(size_t numitems, size_t size)
2066 return calloc(numitems,size);
2070 win32_realloc(void *block, size_t size)
2072 return realloc(block,size);
2076 win32_free(void *block)
2083 win32_open_osfhandle(long handle, int flags)
2085 return _open_osfhandle(handle, flags);
2089 win32_get_osfhandle(int fd)
2091 return _get_osfhandle(fd);
2102 SV *sv = sv_newmortal();
2103 /* Make one call with zero size - return value is required size */
2104 DWORD len = GetCurrentDirectory((DWORD)0,NULL);
2105 SvUPGRADE(sv,SVt_PV);
2107 SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
2110 * then it worked, set PV valid,
2111 * else leave it 'undef'
2125 croak("usage: Win32::SetCurrentDirectory($cwd)");
2126 if (SetCurrentDirectory(SvPV(ST(0),PL_na)))
2133 XS(w32_GetNextAvailDrive)
2137 char root[] = "_:\\";
2140 if (GetDriveType(root) == 1) {
2149 XS(w32_GetLastError)
2152 XSRETURN_IV(GetLastError());
2159 char *name = getlogin_buffer;
2160 DWORD size = sizeof(getlogin_buffer);
2161 if (GetUserName(name,&size)) {
2162 /* size includes NULL */
2163 ST(0) = sv_2mortal(newSVpv(name,size-1));
2173 char name[MAX_COMPUTERNAME_LENGTH+1];
2174 DWORD size = sizeof(name);
2175 if (GetComputerName(name,&size)) {
2176 /* size does NOT include NULL :-( */
2177 ST(0) = sv_2mortal(newSVpv(name,size));
2188 #ifndef HAS_NETWKSTAGETINFO
2189 /* mingw32 (and Win95) don't have NetWksta*(), so do it the old way */
2191 DWORD size = sizeof(name);
2192 if (GetUserName(name,&size)) {
2194 DWORD sidlen = sizeof(sid);
2196 DWORD dnamelen = sizeof(dname);
2198 if (LookupAccountName(NULL, name, (PSID)&sid, &sidlen,
2199 dname, &dnamelen, &snu)) {
2200 XSRETURN_PV(dname); /* all that for this */
2204 /* this way is more reliable, in case user has a local account.
2205 * XXX need dynamic binding of netapi32.dll symbols or this will fail on
2206 * Win95. Probably makes more sense to move it into libwin32. */
2208 DWORD dnamelen = sizeof(dname);
2209 PWKSTA_INFO_100 pwi;
2210 if (NERR_Success == NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pwi)) {
2211 if (pwi->wki100_langroup && *(pwi->wki100_langroup)) {
2212 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup,
2213 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2216 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername,
2217 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2219 NetApiBufferFree(pwi);
2231 DWORD flags, filecomplen;
2232 if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
2233 &flags, fsname, sizeof(fsname))) {
2234 if (GIMME == G_ARRAY) {
2235 XPUSHs(sv_2mortal(newSVpv(fsname,0)));
2236 XPUSHs(sv_2mortal(newSViv(flags)));
2237 XPUSHs(sv_2mortal(newSViv(filecomplen)));
2241 XSRETURN_PV(fsname);
2247 XS(w32_GetOSVersion)
2250 OSVERSIONINFO osver;
2252 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
2253 if (GetVersionEx(&osver)) {
2254 XPUSHs(newSVpv(osver.szCSDVersion, 0));
2255 XPUSHs(newSViv(osver.dwMajorVersion));
2256 XPUSHs(newSViv(osver.dwMinorVersion));
2257 XPUSHs(newSViv(osver.dwBuildNumber));
2258 XPUSHs(newSViv(osver.dwPlatformId));
2269 XSRETURN_IV(IsWinNT());
2276 XSRETURN_IV(IsWin95());
2280 XS(w32_FormatMessage)
2287 croak("usage: Win32::FormatMessage($errno)");
2289 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
2290 &source, SvIV(ST(0)), 0,
2291 msgbuf, sizeof(msgbuf)-1, NULL))
2292 XSRETURN_PV(msgbuf);
2302 PROCESS_INFORMATION stProcInfo;
2303 STARTUPINFO stStartInfo;
2304 BOOL bSuccess = FALSE;
2307 croak("usage: Win32::Spawn($cmdName, $args, $PID)");
2309 cmd = SvPV(ST(0),PL_na);
2310 args = SvPV(ST(1), PL_na);
2312 memset(&stStartInfo, 0, sizeof(stStartInfo)); /* Clear the block */
2313 stStartInfo.cb = sizeof(stStartInfo); /* Set the structure size */
2314 stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
2315 stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
2318 cmd, /* Image path */
2319 args, /* Arguments for command line */
2320 NULL, /* Default process security */
2321 NULL, /* Default thread security */
2322 FALSE, /* Must be TRUE to use std handles */
2323 NORMAL_PRIORITY_CLASS, /* No special scheduling */
2324 NULL, /* Inherit our environment block */
2325 NULL, /* Inherit our currrent directory */
2326 &stStartInfo, /* -> Startup info */
2327 &stProcInfo)) /* <- Process info (if OK) */
2329 CloseHandle(stProcInfo.hThread);/* library source code does this. */
2330 sv_setiv(ST(2), stProcInfo.dwProcessId);
2333 XSRETURN_IV(bSuccess);
2337 XS(w32_GetTickCount)
2340 XSRETURN_IV(GetTickCount());
2344 XS(w32_GetShortPathName)
2351 croak("usage: Win32::GetShortPathName($longPathName)");
2353 shortpath = sv_mortalcopy(ST(0));
2354 SvUPGRADE(shortpath, SVt_PV);
2355 /* src == target is allowed */
2357 len = GetShortPathName(SvPVX(shortpath),
2360 } while (len >= SvLEN(shortpath) && sv_grow(shortpath,len+1));
2362 SvCUR_set(shortpath,len);
2366 ST(0) = &PL_sv_undef;
2375 croak("usage: Win32::Sleep($milliseconds)");
2381 Perl_init_os_extras()
2383 char *file = __FILE__;
2386 w32_perlshell_tokens = Nullch;
2387 w32_perlshell_items = -1;
2388 w32_fdpid = newAV(); /* XXX needs to be in Perl_win32_init()? */
2389 #ifndef USE_RTL_WAIT
2390 w32_num_children = 0;
2393 /* these names are Activeware compatible */
2394 newXS("Win32::GetCwd", w32_GetCwd, file);
2395 newXS("Win32::SetCwd", w32_SetCwd, file);
2396 newXS("Win32::GetNextAvailDrive", w32_GetNextAvailDrive, file);
2397 newXS("Win32::GetLastError", w32_GetLastError, file);
2398 newXS("Win32::LoginName", w32_LoginName, file);
2399 newXS("Win32::NodeName", w32_NodeName, file);
2400 newXS("Win32::DomainName", w32_DomainName, file);
2401 newXS("Win32::FsType", w32_FsType, file);
2402 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2403 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2404 newXS("Win32::IsWin95", w32_IsWin95, file);
2405 newXS("Win32::FormatMessage", w32_FormatMessage, file);
2406 newXS("Win32::Spawn", w32_Spawn, file);
2407 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2408 newXS("Win32::GetShortPathName", w32_GetShortPathName, file);
2409 newXS("Win32::Sleep", w32_Sleep, file);
2411 /* XXX Bloat Alert! The following Activeware preloads really
2412 * ought to be part of Win32::Sys::*, so they're not included
2415 /* LookupAccountName
2417 * InitiateSystemShutdown
2418 * AbortSystemShutdown
2419 * ExpandEnvrironmentStrings
2424 Perl_win32_init(int *argcp, char ***argvp)
2426 /* Disable floating point errors, Perl will trap the ones we
2427 * care about. VC++ RTL defaults to switching these off
2428 * already, but the Borland RTL doesn't. Since we don't
2429 * want to be at the vendor's whim on the default, we set
2430 * it explicitly here.
2432 #if !defined(_ALPHA_) && !defined(__GNUC__)
2433 _control87(MCW_EM, MCW_EM);
2438 #ifdef USE_BINMODE_SCRIPTS
2441 win32_strip_return(SV *sv)
2443 char *s = SvPVX(sv);
2444 char *e = s+SvCUR(sv);
2448 if (*s == '\r' && s[1] == '\n')
2458 SvCUR_set(sv,d-SvPVX(sv));