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)
41 #include "patchlevel.h"
45 extern CPerlObj* pPerl;
53 /* assert.h conflicts with #define of assert in perl.h */
60 #if defined(_MSC_VER) || defined(__MINGW32__)
61 #include <sys/utime.h>
67 /* Mingw32 defaults to globing command line
68 * So we turn it off like this:
75 #define EXECF_SPAWN_NOWAIT 3
77 #if defined(PERL_OBJECT)
78 #undef win32_get_privlib
79 #define win32_get_privlib g_win32_get_privlib
80 #undef win32_get_sitelib
81 #define win32_get_sitelib g_win32_get_sitelib
83 #define do_aspawn g_do_aspawn
85 #define do_spawn g_do_spawn
87 #define do_exec g_do_exec
89 #define getlogin g_getlogin
92 static DWORD os_id(void);
93 static void get_shell(void);
94 static long tokenize(char *str, char **dest, char ***destv);
95 int do_spawn2(char *cmd, int exectype);
96 static BOOL has_shell_metachars(char *ptr);
97 static long filetime_to_clock(PFILETIME ft);
98 static BOOL filetime_from_time(PFILETIME ft, time_t t);
99 static char * get_emd_part(char *leading, char *trailing, ...);
100 static void remove_dead_process(HANDLE deceased);
102 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
103 static DWORD w32_platform = (DWORD)-1;
106 # ifdef USE_DECLSPEC_THREAD
107 __declspec(thread) char strerror_buffer[512];
108 __declspec(thread) char getlogin_buffer[128];
109 __declspec(thread) char w32_perllib_root[MAX_PATH+1];
110 # ifdef HAVE_DES_FCRYPT
111 __declspec(thread) char crypt_buffer[30];
114 # define strerror_buffer (thr->i.Wstrerror_buffer)
115 # define getlogin_buffer (thr->i.Wgetlogin_buffer)
116 # define w32_perllib_root (thr->i.Ww32_perllib_root)
117 # define crypt_buffer (thr->i.Wcrypt_buffer)
120 static char strerror_buffer[512];
121 static char getlogin_buffer[128];
122 static char w32_perllib_root[MAX_PATH+1];
123 # ifdef HAVE_DES_FCRYPT
124 static char crypt_buffer[30];
130 return (os_id() == VER_PLATFORM_WIN32_WINDOWS);
135 return (os_id() == VER_PLATFORM_WIN32_NT);
139 GetRegStrFromKey(HKEY hkey, const char *lpszValueName, char** ptr, DWORD* lpDataLen)
140 { /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
143 const char *subkey = "Software\\Perl";
146 retval = RegOpenKeyEx(hkey, subkey, 0, KEY_READ, &handle);
147 if (retval == ERROR_SUCCESS){
148 retval = RegQueryValueEx(handle, lpszValueName, 0, &type, NULL, lpDataLen);
149 if (retval == ERROR_SUCCESS && type == REG_SZ) {
151 Renew(*ptr, *lpDataLen, char);
154 New(1312, *ptr, *lpDataLen, char);
156 retval = RegQueryValueEx(handle, lpszValueName, 0, NULL, (PBYTE)*ptr, lpDataLen);
157 if (retval != ERROR_SUCCESS) {
168 GetRegStr(const char *lpszValueName, char** ptr, DWORD* lpDataLen)
170 *ptr = GetRegStrFromKey(HKEY_CURRENT_USER, lpszValueName, ptr, lpDataLen);
173 *ptr = GetRegStrFromKey(HKEY_LOCAL_MACHINE, lpszValueName, ptr, lpDataLen);
179 get_emd_part(char *prev_path, char *trailing_path, ...)
183 char mod_name[MAX_PATH+1];
187 int oldsize, newsize;
189 va_start(ap, trailing_path);
190 strip = va_arg(ap, char *);
192 sprintf(base, "%5.3f", (double) 5 + ((double) PATCHLEVEL / (double) 1000));
194 GetModuleFileName((w32_perldll_handle == INVALID_HANDLE_VALUE)
195 ? GetModuleHandle(NULL)
196 : w32_perldll_handle, mod_name, sizeof(mod_name));
197 ptr = strrchr(mod_name, '\\');
198 while (ptr && strip) {
199 /* look for directories to skip back */
202 ptr = strrchr(mod_name, '\\');
203 if (!ptr || stricmp(ptr+1, strip) != 0) {
207 strip = va_arg(ap, char *);
215 strcpy(++ptr, trailing_path);
217 /* only add directory if it exists */
218 if(GetFileAttributes(mod_name) != (DWORD) -1) {
219 /* directory exists */
220 newsize = strlen(mod_name) + 1;
222 oldsize = strlen(prev_path) + 1;
223 newsize += oldsize; /* includes plus 1 for ';' */
224 Renew(prev_path, newsize, char);
225 prev_path[oldsize-1] = ';';
226 strcpy(&prev_path[oldsize], mod_name);
229 New(1311, prev_path, newsize, char);
230 strcpy(prev_path, mod_name);
238 win32_get_privlib(char *pl)
240 char *stdlib = "lib";
241 char buffer[MAX_PATH+1];
245 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
246 sprintf(buffer, "%s-%s", stdlib, pl);
247 path = GetRegStr(buffer, &path, &datalen);
249 path = GetRegStr(stdlib, &path, &datalen);
251 /* $stdlib .= ";$EMD/../../lib" */
252 return get_emd_part(path, stdlib, ARCHNAME, "bin", Nullch);
256 win32_get_sitelib(char *pl)
258 char *sitelib = "sitelib";
260 char pathstr[MAX_PATH+1];
262 char *path1 = Nullch;
263 char *path2 = Nullch;
266 /* $HKCU{"sitelib-$]"} || $HKLM{"sitelib-$]"} . ---; */
267 sprintf(regstr, "%s-%s", sitelib, pl);
268 path1 = GetRegStr(regstr, &path1, &datalen);
271 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/site/$]/lib"; */
272 sprintf(pathstr, "site\\%s\\lib", pl);
273 path1 = get_emd_part(path1, pathstr, ARCHNAME, "bin", pl, Nullch);
275 /* $HKCU{'sitelib'} || $HKLM{'sitelib'} . ---; */
276 path2 = GetRegStr(sitelib, &path2, &datalen);
279 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/site/lib"; */
280 path2 = get_emd_part(path2, "site\\lib", ARCHNAME, "bin", pl, Nullch);
289 newsize = len + strlen(path2) + 2; /* plus one for ';' */
291 Renew(path1, newsize, char);
293 strcpy(&path1[len], path2);
301 has_shell_metachars(char *ptr)
307 * Scan string looking for redirection (< or >) or pipe
308 * characters (|) that are not in a quoted string.
309 * Shell variable interpolation (%VAR%) can also happen inside strings.
341 #if !defined(PERL_OBJECT)
342 /* since the current process environment is being updated in util.c
343 * the library functions will get the correct environment
346 my_popen(char *cmd, char *mode)
349 #define fixcmd(x) { \
350 char *pspace = strchr((x),' '); \
353 while (p < pspace) { \
364 win32_fflush(stdout);
365 win32_fflush(stderr);
366 return win32_popen(cmd, mode);
370 my_pclose(PerlIO *fp)
372 return win32_pclose(fp);
379 static OSVERSIONINFO osver;
381 if (osver.dwPlatformId != w32_platform) {
382 memset(&osver, 0, sizeof(OSVERSIONINFO));
383 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
384 GetVersionEx(&osver);
385 w32_platform = osver.dwPlatformId;
387 return (w32_platform);
390 /* Tokenize a string. Words are null-separated, and the list
391 * ends with a doubled null. Any character (except null and
392 * including backslash) may be escaped by preceding it with a
393 * backslash (the backslash will be stripped).
394 * Returns number of words in result buffer.
397 tokenize(char *str, char **dest, char ***destv)
399 char *retstart = Nullch;
400 char **retvstart = 0;
403 int slen = strlen(str);
405 register char **retv;
406 New(1307, ret, slen+2, char);
407 New(1308, retv, (slen+3)/2, char*);
415 if (*ret == '\\' && *str)
417 else if (*ret == ' ') {
433 retvstart[items] = Nullch;
445 if (!w32_perlshell_tokens) {
446 /* we don't use COMSPEC here for two reasons:
447 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
448 * uncontrolled unportability of the ensuing scripts.
449 * 2. PERL5SHELL could be set to a shell that may not be fit for
450 * interactive use (which is what most programs look in COMSPEC
453 char* defaultshell = (IsWinNT() ? "cmd.exe /x/c" : "command.com /c");
454 char *usershell = getenv("PERL5SHELL");
455 w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
456 &w32_perlshell_tokens,
462 do_aspawn(void *vreally, void **vmark, void **vsp)
464 SV *really = (SV*)vreally;
465 SV **mark = (SV**)vmark;
478 New(1306, argv, (sp - mark) + w32_perlshell_items + 2, char*);
480 if (SvNIOKp(*(mark+1)) && !SvPOKp(*(mark+1))) {
485 while (++mark <= sp) {
486 if (*mark && (str = SvPV(*mark, n_a)))
493 status = win32_spawnvp(flag,
494 (const char*)(really ? SvPV(really,n_a) : argv[0]),
495 (const char* const*)argv);
497 if (status < 0 && errno == ENOEXEC) {
498 /* possible shell-builtin, invoke with shell */
500 sh_items = w32_perlshell_items;
502 argv[index+sh_items] = argv[index];
503 while (--sh_items >= 0)
504 argv[sh_items] = w32_perlshell_vec[sh_items];
506 status = win32_spawnvp(flag,
507 (const char*)(really ? SvPV(really,n_a) : argv[0]),
508 (const char* const*)argv);
511 if (flag != P_NOWAIT) {
514 warn("Can't spawn \"%s\": %s", argv[0], strerror(errno));
519 PL_statusvalue = status;
526 do_spawn2(char *cmd, int exectype)
532 BOOL needToTry = TRUE;
535 /* Save an extra exec if possible. See if there are shell
536 * metacharacters in it */
537 if (!has_shell_metachars(cmd)) {
538 New(1301,argv, strlen(cmd) / 2 + 2, char*);
539 New(1302,cmd2, strlen(cmd) + 1, char);
542 for (s = cmd2; *s;) {
543 while (*s && isspace(*s))
547 while (*s && !isspace(*s))
556 status = win32_spawnvp(P_WAIT, argv[0],
557 (const char* const*)argv);
559 case EXECF_SPAWN_NOWAIT:
560 status = win32_spawnvp(P_NOWAIT, argv[0],
561 (const char* const*)argv);
564 status = win32_execvp(argv[0], (const char* const*)argv);
567 if (status != -1 || errno == 0)
577 New(1306, argv, w32_perlshell_items + 2, char*);
578 while (++i < w32_perlshell_items)
579 argv[i] = w32_perlshell_vec[i];
584 status = win32_spawnvp(P_WAIT, argv[0],
585 (const char* const*)argv);
587 case EXECF_SPAWN_NOWAIT:
588 status = win32_spawnvp(P_NOWAIT, argv[0],
589 (const char* const*)argv);
592 status = win32_execvp(argv[0], (const char* const*)argv);
598 if (exectype != EXECF_SPAWN_NOWAIT) {
601 warn("Can't %s \"%s\": %s",
602 (exectype == EXECF_EXEC ? "exec" : "spawn"),
603 cmd, strerror(errno));
608 PL_statusvalue = status;
616 return do_spawn2(cmd, EXECF_SPAWN);
620 do_spawn_nowait(char *cmd)
622 return do_spawn2(cmd, EXECF_SPAWN_NOWAIT);
628 do_spawn2(cmd, EXECF_EXEC);
632 /* The idea here is to read all the directory names into a string table
633 * (separated by nulls) and when one of the other dir functions is called
634 * return the pointer to the current file name.
637 win32_opendir(char *filename)
642 char scanname[MAX_PATH+3];
644 WIN32_FIND_DATA FindData;
647 len = strlen(filename);
651 /* check to see if filename is a directory */
652 if (win32_stat(filename, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode))
655 /* Get us a DIR structure */
656 Newz(1303, p, 1, DIR);
660 /* Create the search pattern */
661 strcpy(scanname, filename);
662 if (scanname[len-1] != '/' && scanname[len-1] != '\\')
663 scanname[len++] = '/';
664 scanname[len++] = '*';
665 scanname[len] = '\0';
667 /* do the FindFirstFile call */
668 fh = FindFirstFile(scanname, &FindData);
669 if (fh == INVALID_HANDLE_VALUE) {
670 /* FindFirstFile() fails on empty drives! */
671 if (GetLastError() == ERROR_FILE_NOT_FOUND)
677 /* now allocate the first part of the string table for
678 * the filenames that we find.
680 idx = strlen(FindData.cFileName)+1;
681 New(1304, p->start, idx, char);
682 if (p->start == NULL)
683 croak("opendir: malloc failed!\n");
684 strcpy(p->start, FindData.cFileName);
687 /* loop finding all the files that match the wildcard
688 * (which should be all of them in this directory!).
689 * the variable idx should point one past the null terminator
690 * of the previous string found.
692 while (FindNextFile(fh, &FindData)) {
693 len = strlen(FindData.cFileName);
694 /* bump the string table size by enough for the
695 * new name and it's null terminator
697 Renew(p->start, idx+len+1, char);
698 if (p->start == NULL)
699 croak("opendir: malloc failed!\n");
700 strcpy(&p->start[idx], FindData.cFileName);
711 /* Readdir just returns the current string pointer and bumps the
712 * string pointer to the nDllExport entry.
715 win32_readdir(DIR *dirp)
718 static int dummy = 0;
721 /* first set up the structure to return */
722 len = strlen(dirp->curr);
723 strcpy(dirp->dirstr.d_name, dirp->curr);
724 dirp->dirstr.d_namlen = len;
727 dirp->dirstr.d_ino = dummy++;
729 /* Now set up for the nDllExport call to readdir */
730 dirp->curr += len + 1;
731 if (dirp->curr >= (dirp->start + dirp->size)) {
735 return &(dirp->dirstr);
741 /* Telldir returns the current string pointer position */
743 win32_telldir(DIR *dirp)
745 return (long) dirp->curr;
749 /* Seekdir moves the string pointer to a previously saved position
753 win32_seekdir(DIR *dirp, long loc)
755 dirp->curr = (char *)loc;
758 /* Rewinddir resets the string pointer to the start */
760 win32_rewinddir(DIR *dirp)
762 dirp->curr = dirp->start;
765 /* free the memory allocated by opendir */
767 win32_closedir(DIR *dirp)
769 Safefree(dirp->start);
782 * Just pretend that everyone is a superuser. NT will let us know if
783 * we don\'t really have permission to do something.
786 #define ROOT_UID ((uid_t)0)
787 #define ROOT_GID ((gid_t)0)
816 return (auid == ROOT_UID ? 0 : -1);
822 return (agid == ROOT_GID ? 0 : -1);
829 char *buf = getlogin_buffer;
830 DWORD size = sizeof(getlogin_buffer);
831 if (GetUserName(buf,&size))
837 chown(const char *path, uid_t owner, gid_t group)
844 remove_dead_process(HANDLE deceased)
848 for (child = 0 ; child < w32_num_children ; ++child) {
849 if (w32_child_pids[child] == deceased) {
850 Copy(&w32_child_pids[child+1], &w32_child_pids[child],
851 (w32_num_children-child-1), HANDLE);
860 win32_kill(int pid, int sig)
863 HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
865 HANDLE hProcess = (HANDLE) pid;
868 if (hProcess == NULL) {
869 croak("kill process failed!\n");
872 if (!TerminateProcess(hProcess, sig))
873 croak("kill process failed!\n");
874 CloseHandle(hProcess);
876 /* WaitForMultipleObjects() on a pid that was killed returns error
877 * so if we know the pid is gone we remove it from process list */
878 remove_dead_process(hProcess);
887 DllExport unsigned int
888 win32_sleep(unsigned int t)
895 win32_stat(const char *path, struct stat *buffer)
898 const char *p = path;
899 int l = strlen(path);
903 switch(path[l - 1]) {
906 if (path[l - 2] != ':') {
907 strncpy(t, path, l - 1);
913 res = stat(p,buffer);
915 /* CRT is buggy on sharenames, so make sure it really isn't.
916 * XXX using GetFileAttributesEx() will enable us to set
917 * buffer->st_*time (but note that's not available on the
918 * Windows of 1995) */
919 DWORD r = GetFileAttributes(p);
920 if (r != 0xffffffff && (r & FILE_ATTRIBUTE_DIRECTORY)) {
921 buffer->st_mode |= S_IFDIR | S_IREAD;
923 if (!(r & FILE_ATTRIBUTE_READONLY))
924 buffer->st_mode |= S_IWRITE | S_IEXEC;
929 if (l == 3 && path[l-2] == ':'
930 && (path[l-1] == '\\' || path[l-1] == '/'))
932 /* The drive can be inaccessible, some _stat()s are buggy */
933 if (!GetVolumeInformation(path,NULL,0,NULL,NULL,NULL,NULL,0)) {
939 if (S_ISDIR(buffer->st_mode))
940 buffer->st_mode |= S_IWRITE | S_IEXEC;
941 else if (S_ISREG(buffer->st_mode)) {
942 if (l >= 4 && path[l-4] == '.') {
943 const char *e = path + l - 3;
944 if (strnicmp(e,"exe",3)
945 && strnicmp(e,"bat",3)
946 && strnicmp(e,"com",3)
947 && (IsWin95() || strnicmp(e,"cmd",3)))
948 buffer->st_mode &= ~S_IEXEC;
950 buffer->st_mode |= S_IEXEC;
953 buffer->st_mode &= ~S_IEXEC;
960 #ifndef USE_WIN32_RTL_ENV
963 win32_getenv(const char *name)
965 static char *curitem = Nullch; /* XXX threadead */
966 static DWORD curlen = 0; /* XXX threadead */
970 New(1305,curitem,curlen,char);
973 needlen = GetEnvironmentVariable(name,curitem,curlen);
975 while (needlen > curlen) {
976 Renew(curitem,needlen,char);
978 needlen = GetEnvironmentVariable(name,curitem,curlen);
982 /* allow any environment variables that begin with 'PERL'
983 to be stored in the registry */
987 if (strncmp(name, "PERL", 4) == 0) {
993 curitem = GetRegStr(name, &curitem, &curlen);
996 if (curitem && *curitem == '\0')
1005 filetime_to_clock(PFILETIME ft)
1007 __int64 qw = ft->dwHighDateTime;
1009 qw |= ft->dwLowDateTime;
1010 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
1015 win32_times(struct tms *timebuf)
1020 if (GetProcessTimes(GetCurrentProcess(), &dummy, &dummy,
1022 timebuf->tms_utime = filetime_to_clock(&user);
1023 timebuf->tms_stime = filetime_to_clock(&kernel);
1024 timebuf->tms_cutime = 0;
1025 timebuf->tms_cstime = 0;
1028 /* That failed - e.g. Win95 fallback to clock() */
1029 clock_t t = clock();
1030 timebuf->tms_utime = t;
1031 timebuf->tms_stime = 0;
1032 timebuf->tms_cutime = 0;
1033 timebuf->tms_cstime = 0;
1038 /* fix utime() so it works on directories in NT
1039 * thanks to Jan Dubois <jan.dubois@ibm.net>
1042 filetime_from_time(PFILETIME pFileTime, time_t Time)
1044 struct tm *pTM = gmtime(&Time);
1045 SYSTEMTIME SystemTime;
1050 SystemTime.wYear = pTM->tm_year + 1900;
1051 SystemTime.wMonth = pTM->tm_mon + 1;
1052 SystemTime.wDay = pTM->tm_mday;
1053 SystemTime.wHour = pTM->tm_hour;
1054 SystemTime.wMinute = pTM->tm_min;
1055 SystemTime.wSecond = pTM->tm_sec;
1056 SystemTime.wMilliseconds = 0;
1058 return SystemTimeToFileTime(&SystemTime, pFileTime);
1062 win32_utime(const char *filename, struct utimbuf *times)
1068 struct utimbuf TimeBuffer;
1070 int rc = utime(filename,times);
1071 /* EACCES: path specifies directory or readonly file */
1072 if (rc == 0 || errno != EACCES /* || !IsWinNT() */)
1075 if (times == NULL) {
1076 times = &TimeBuffer;
1077 time(×->actime);
1078 times->modtime = times->actime;
1081 /* This will (and should) still fail on readonly files */
1082 handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
1083 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL,
1084 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1085 if (handle == INVALID_HANDLE_VALUE)
1088 if (GetFileTime(handle, &ftCreate, &ftAccess, &ftWrite) &&
1089 filetime_from_time(&ftAccess, times->actime) &&
1090 filetime_from_time(&ftWrite, times->modtime) &&
1091 SetFileTime(handle, &ftCreate, &ftAccess, &ftWrite))
1096 CloseHandle(handle);
1101 win32_waitpid(int pid, int *status, int flags)
1105 return win32_wait(status);
1107 rc = cwait(status, pid, WAIT_CHILD);
1108 /* cwait() returns "correctly" on Borland */
1109 #ifndef __BORLANDC__
1113 remove_dead_process((HANDLE)pid);
1115 return rc >= 0 ? pid : rc;
1119 win32_wait(int *status)
1122 return wait(status);
1124 /* XXX this wait emulation only knows about processes
1125 * spawned via win32_spawnvp(P_NOWAIT, ...).
1128 DWORD exitcode, waitcode;
1130 if (!w32_num_children) {
1135 /* if a child exists, wait for it to die */
1136 waitcode = WaitForMultipleObjects(w32_num_children,
1140 if (waitcode != WAIT_FAILED) {
1141 if (waitcode >= WAIT_ABANDONED_0
1142 && waitcode < WAIT_ABANDONED_0 + w32_num_children)
1143 i = waitcode - WAIT_ABANDONED_0;
1145 i = waitcode - WAIT_OBJECT_0;
1146 if (GetExitCodeProcess(w32_child_pids[i], &exitcode) ) {
1147 CloseHandle(w32_child_pids[i]);
1148 *status = (int)((exitcode & 0xff) << 8);
1149 retval = (int)w32_child_pids[i];
1150 Copy(&w32_child_pids[i+1], &w32_child_pids[i],
1151 (w32_num_children-i-1), HANDLE);
1158 errno = GetLastError();
1164 static UINT timerid = 0;
1166 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
1168 KillTimer(NULL,timerid);
1173 DllExport unsigned int
1174 win32_alarm(unsigned int sec)
1177 * the 'obvious' implentation is SetTimer() with a callback
1178 * which does whatever receiving SIGALRM would do
1179 * we cannot use SIGALRM even via raise() as it is not
1180 * one of the supported codes in <signal.h>
1182 * Snag is unless something is looking at the message queue
1183 * nothing happens :-(
1187 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
1189 croak("Cannot set timer");
1195 KillTimer(NULL,timerid);
1202 #if defined(HAVE_DES_FCRYPT) || defined(PERL_OBJECT)
1203 #ifdef HAVE_DES_FCRYPT
1204 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
1208 win32_crypt(const char *txt, const char *salt)
1210 #ifdef HAVE_DES_FCRYPT
1212 return des_fcrypt(txt, salt, crypt_buffer);
1214 die("The crypt() function is unimplemented due to excessive paranoia.");
1220 #ifdef USE_FIXED_OSFHANDLE
1222 EXTERN_C int __cdecl _alloc_osfhnd(void);
1223 EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
1224 EXTERN_C void __cdecl _lock_fhandle(int);
1225 EXTERN_C void __cdecl _unlock_fhandle(int);
1226 EXTERN_C void __cdecl _unlock(int);
1228 #if (_MSC_VER >= 1000)
1230 long osfhnd; /* underlying OS file HANDLE */
1231 char osfile; /* attributes of file (e.g., open in text mode?) */
1232 char pipech; /* one char buffer for handles opened on pipes */
1233 #if defined (_MT) && !defined (DLL_FOR_WIN32S)
1235 CRITICAL_SECTION lock;
1236 #endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
1239 EXTERN_C ioinfo * __pioinfo[];
1241 #define IOINFO_L2E 5
1242 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
1243 #define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
1244 #define _osfile(i) (_pioinfo(i)->osfile)
1246 #else /* (_MSC_VER >= 1000) */
1247 extern char _osfile[];
1248 #endif /* (_MSC_VER >= 1000) */
1250 #define FOPEN 0x01 /* file handle open */
1251 #define FAPPEND 0x20 /* file handle opened O_APPEND */
1252 #define FDEV 0x40 /* file handle refers to device */
1253 #define FTEXT 0x80 /* file handle is in text mode */
1255 #define _STREAM_LOCKS 26 /* Table of stream locks */
1256 #define _LAST_STREAM_LOCK (_STREAM_LOCKS+_NSTREAM_-1) /* Last stream lock */
1257 #define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
1260 *int my_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
1263 * This function allocates a free C Runtime file handle and associates
1264 * it with the Win32 HANDLE specified by the first parameter. This is a
1265 * temperary fix for WIN95's brain damage GetFileType() error on socket
1266 * we just bypass that call for socket
1269 * long osfhandle - Win32 HANDLE to associate with C Runtime file handle.
1270 * int flags - flags to associate with C Runtime file handle.
1273 * returns index of entry in fh, if successful
1274 * return -1, if no free entry is found
1278 *******************************************************************************/
1281 my_open_osfhandle(long osfhandle, int flags)
1284 char fileflags; /* _osfile flags */
1286 /* copy relevant flags from second parameter */
1289 if (flags & O_APPEND)
1290 fileflags |= FAPPEND;
1295 /* attempt to allocate a C Runtime file handle */
1296 if ((fh = _alloc_osfhnd()) == -1) {
1297 errno = EMFILE; /* too many open files */
1298 _doserrno = 0L; /* not an OS error */
1299 return -1; /* return error to caller */
1302 /* the file is open. now, set the info in _osfhnd array */
1303 _set_osfhnd(fh, osfhandle);
1305 fileflags |= FOPEN; /* mark as open */
1307 #if (_MSC_VER >= 1000)
1308 _osfile(fh) = fileflags; /* set osfile entry */
1309 _unlock_fhandle(fh);
1311 _osfile[fh] = fileflags; /* set osfile entry */
1312 _unlock(fh+_FH_LOCKS); /* unlock handle */
1315 return fh; /* return handle */
1318 #define _open_osfhandle my_open_osfhandle
1319 #endif /* USE_FIXED_OSFHANDLE */
1321 /* simulate flock by locking a range on the file */
1323 #define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
1324 #define LK_LEN 0xffff0000
1327 win32_flock(int fd, int oper)
1334 croak("flock() unimplemented on this platform");
1337 fh = (HANDLE)_get_osfhandle(fd);
1338 memset(&o, 0, sizeof(o));
1341 case LOCK_SH: /* shared lock */
1342 LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
1344 case LOCK_EX: /* exclusive lock */
1345 LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
1347 case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
1348 LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
1350 case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
1351 LK_ERR(LockFileEx(fh,
1352 LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
1353 0, LK_LEN, 0, &o),i);
1355 case LOCK_UN: /* unlock lock */
1356 LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
1358 default: /* unknown */
1369 * redirected io subsystem for all XS modules
1382 return (&(_environ));
1385 /* the rest are the remapped stdio routines */
1405 win32_ferror(FILE *fp)
1407 return (ferror(fp));
1412 win32_feof(FILE *fp)
1418 * Since the errors returned by the socket error function
1419 * WSAGetLastError() are not known by the library routine strerror
1420 * we have to roll our own.
1424 win32_strerror(int e)
1426 #ifndef __BORLANDC__ /* Borland intolerance */
1427 extern int sys_nerr;
1431 if (e < 0 || e > sys_nerr) {
1436 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
1437 strerror_buffer, sizeof(strerror_buffer), NULL) == 0)
1438 strcpy(strerror_buffer, "Unknown Error");
1440 return strerror_buffer;
1446 win32_str_os_error(void *sv, DWORD dwErr)
1450 dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
1451 |FORMAT_MESSAGE_IGNORE_INSERTS
1452 |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
1453 dwErr, 0, (char *)&sMsg, 1, NULL);
1455 while (0 < dwLen && isspace(sMsg[--dwLen]))
1457 if ('.' != sMsg[dwLen])
1462 sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
1463 dwLen = sprintf(sMsg,
1464 "Unknown error #0x%lX (lookup 0x%lX)",
1465 dwErr, GetLastError());
1467 sv_setpvn((SV*)sv, sMsg, dwLen);
1473 win32_fprintf(FILE *fp, const char *format, ...)
1476 va_start(marker, format); /* Initialize variable arguments. */
1478 return (vfprintf(fp, format, marker));
1482 win32_printf(const char *format, ...)
1485 va_start(marker, format); /* Initialize variable arguments. */
1487 return (vprintf(format, marker));
1491 win32_vfprintf(FILE *fp, const char *format, va_list args)
1493 return (vfprintf(fp, format, args));
1497 win32_vprintf(const char *format, va_list args)
1499 return (vprintf(format, args));
1503 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
1505 return fread(buf, size, count, fp);
1509 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
1511 return fwrite(buf, size, count, fp);
1515 win32_fopen(const char *filename, const char *mode)
1517 if (stricmp(filename, "/dev/null")==0)
1518 return fopen("NUL", mode);
1519 return fopen(filename, mode);
1522 #ifndef USE_SOCKETS_AS_HANDLES
1524 #define fdopen my_fdopen
1528 win32_fdopen( int handle, const char *mode)
1530 return fdopen(handle, (char *) mode);
1534 win32_freopen( const char *path, const char *mode, FILE *stream)
1536 if (stricmp(path, "/dev/null")==0)
1537 return freopen("NUL", mode, stream);
1538 return freopen(path, mode, stream);
1542 win32_fclose(FILE *pf)
1544 return my_fclose(pf); /* defined in win32sck.c */
1548 win32_fputs(const char *s,FILE *pf)
1550 return fputs(s, pf);
1554 win32_fputc(int c,FILE *pf)
1560 win32_ungetc(int c,FILE *pf)
1562 return ungetc(c,pf);
1566 win32_getc(FILE *pf)
1572 win32_fileno(FILE *pf)
1578 win32_clearerr(FILE *pf)
1585 win32_fflush(FILE *pf)
1591 win32_ftell(FILE *pf)
1597 win32_fseek(FILE *pf,long offset,int origin)
1599 return fseek(pf, offset, origin);
1603 win32_fgetpos(FILE *pf,fpos_t *p)
1605 return fgetpos(pf, p);
1609 win32_fsetpos(FILE *pf,const fpos_t *p)
1611 return fsetpos(pf, p);
1615 win32_rewind(FILE *pf)
1635 win32_fstat(int fd,struct stat *sbufptr)
1637 return fstat(fd,sbufptr);
1641 win32_pipe(int *pfd, unsigned int size, int mode)
1643 return _pipe(pfd, size, mode);
1647 * a popen() clone that respects PERL5SHELL
1651 win32_popen(const char *command, const char *mode)
1653 #ifdef USE_RTL_POPEN
1654 return _popen(command, mode);
1662 /* establish which ends read and write */
1663 if (strchr(mode,'w')) {
1664 stdfd = 0; /* stdin */
1668 else if (strchr(mode,'r')) {
1669 stdfd = 1; /* stdout */
1676 /* set the correct mode */
1677 if (strchr(mode,'b'))
1679 else if (strchr(mode,'t'))
1682 ourmode = _fmode & (O_TEXT | O_BINARY);
1684 /* the child doesn't inherit handles */
1685 ourmode |= O_NOINHERIT;
1687 if (win32_pipe( p, 512, ourmode) == -1)
1690 /* save current stdfd */
1691 if ((oldfd = win32_dup(stdfd)) == -1)
1694 /* make stdfd go to child end of pipe (implicitly closes stdfd) */
1695 /* stdfd will be inherited by the child */
1696 if (win32_dup2(p[child], stdfd) == -1)
1699 /* close the child end in parent */
1700 win32_close(p[child]);
1702 /* start the child */
1703 if ((childpid = do_spawn_nowait((char*)command)) == -1)
1706 /* revert stdfd to whatever it was before */
1707 if (win32_dup2(oldfd, stdfd) == -1)
1710 /* close saved handle */
1713 sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
1715 /* we have an fd, return a file stream */
1716 return (win32_fdopen(p[parent], (char *)mode));
1719 /* we don't need to check for errors here */
1723 win32_dup2(oldfd, stdfd);
1728 #endif /* USE_RTL_POPEN */
1736 win32_pclose(FILE *pf)
1738 #ifdef USE_RTL_POPEN
1742 int childpid, status;
1745 sv = *av_fetch(w32_fdpid, win32_fileno(pf), TRUE);
1747 childpid = SvIVX(sv);
1759 remove_dead_process((HANDLE)childpid);
1761 /* wait for the child */
1762 if (cwait(&status, childpid, WAIT_CHILD) == -1)
1764 /* cwait() returns "correctly" on Borland */
1765 #ifndef __BORLANDC__
1770 #endif /* USE_RTL_POPEN */
1774 win32_rename(const char *oname, const char *newname)
1776 char szNewWorkName[MAX_PATH+1];
1777 WIN32_FIND_DATA fdOldFile, fdNewFile;
1781 if ((strchr(oname, '\\') || strchr(oname, '/'))
1782 && strchr(newname, '\\') == NULL
1783 && strchr(newname, '/') == NULL)
1785 strcpy(szNewWorkName, oname);
1786 if ((ptr = strrchr(szNewWorkName, '\\')) == NULL)
1787 ptr = strrchr(szNewWorkName, '/');
1788 strcpy(++ptr, newname);
1791 strcpy(szNewWorkName, newname);
1793 if (stricmp(oname, szNewWorkName) != 0) {
1794 // check that we're not being fooled by relative paths
1795 // and only delete the new file
1797 // 2) it is not the same file as the old file
1798 // 3) old file exist
1799 // GetFullPathName does not return the long file name on some systems
1800 handle = FindFirstFile(oname, &fdOldFile);
1801 if (handle != INVALID_HANDLE_VALUE) {
1804 handle = FindFirstFile(szNewWorkName, &fdNewFile);
1806 if (handle != INVALID_HANDLE_VALUE)
1809 fdNewFile.cFileName[0] = '\0';
1811 if (strcmp(fdOldFile.cAlternateFileName,
1812 fdNewFile.cAlternateFileName) != 0
1813 && strcmp(fdOldFile.cFileName, fdNewFile.cFileName) != 0)
1815 // file exists and not same file
1816 DeleteFile(szNewWorkName);
1820 return rename(oname, newname);
1824 win32_setmode(int fd, int mode)
1826 return setmode(fd, mode);
1830 win32_lseek(int fd, long offset, int origin)
1832 return lseek(fd, offset, origin);
1842 win32_open(const char *path, int flag, ...)
1848 pmode = va_arg(ap, int);
1851 if (stricmp(path, "/dev/null")==0)
1852 return open("NUL", flag, pmode);
1853 return open(path,flag,pmode);
1875 win32_dup2(int fd1,int fd2)
1877 return dup2(fd1,fd2);
1881 win32_read(int fd, void *buf, unsigned int cnt)
1883 return read(fd, buf, cnt);
1887 win32_write(int fd, const void *buf, unsigned int cnt)
1889 return write(fd, buf, cnt);
1893 win32_mkdir(const char *dir, int mode)
1895 return mkdir(dir); /* just ignore mode */
1899 win32_rmdir(const char *dir)
1905 win32_chdir(const char *dir)
1911 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1915 #ifndef USE_RTL_WAIT
1916 if (mode == P_NOWAIT && w32_num_children >= MAXIMUM_WAIT_OBJECTS)
1920 status = spawnvp(mode, cmdname, (char * const *) argv);
1921 #ifndef USE_RTL_WAIT
1922 /* XXX For the P_NOWAIT case, Borland RTL returns pinfo.dwProcessId
1923 * while VC RTL returns pinfo.hProcess. For purposes of the custom
1924 * implementation of win32_wait(), we assume the latter.
1926 if (mode == P_NOWAIT && status >= 0)
1927 w32_child_pids[w32_num_children++] = (HANDLE)status;
1933 win32_execv(const char *cmdname, const char *const *argv)
1935 return execv(cmdname, (char *const *)argv);
1939 win32_execvp(const char *cmdname, const char *const *argv)
1941 return execvp(cmdname, (char *const *)argv);
1945 win32_perror(const char *str)
1951 win32_setbuf(FILE *pf, char *buf)
1957 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1959 return setvbuf(pf, buf, type, size);
1963 win32_flushall(void)
1969 win32_fcloseall(void)
1975 win32_fgets(char *s, int n, FILE *pf)
1977 return fgets(s, n, pf);
1987 win32_fgetc(FILE *pf)
1993 win32_putc(int c, FILE *pf)
1999 win32_puts(const char *s)
2011 win32_putchar(int c)
2018 #ifndef USE_PERL_SBRK
2020 static char *committed = NULL;
2021 static char *base = NULL;
2022 static char *reserved = NULL;
2023 static char *brk = NULL;
2024 static DWORD pagesize = 0;
2025 static DWORD allocsize = 0;
2033 GetSystemInfo(&info);
2034 /* Pretend page size is larger so we don't perpetually
2035 * call the OS to commit just one page ...
2037 pagesize = info.dwPageSize << 3;
2038 allocsize = info.dwAllocationGranularity;
2040 /* This scheme fails eventually if request for contiguous
2041 * block is denied so reserve big blocks - this is only
2042 * address space not memory ...
2044 if (brk+need >= reserved)
2046 DWORD size = 64*1024*1024;
2048 if (committed && reserved && committed < reserved)
2050 /* Commit last of previous chunk cannot span allocations */
2051 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
2053 committed = reserved;
2055 /* Reserve some (more) space
2056 * Note this is a little sneaky, 1st call passes NULL as reserved
2057 * so lets system choose where we start, subsequent calls pass
2058 * the old end address so ask for a contiguous block
2060 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
2063 reserved = addr+size;
2078 if (brk > committed)
2080 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
2081 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
2096 win32_malloc(size_t size)
2098 return malloc(size);
2102 win32_calloc(size_t numitems, size_t size)
2104 return calloc(numitems,size);
2108 win32_realloc(void *block, size_t size)
2110 return realloc(block,size);
2114 win32_free(void *block)
2121 win32_open_osfhandle(long handle, int flags)
2123 return _open_osfhandle(handle, flags);
2127 win32_get_osfhandle(int fd)
2129 return _get_osfhandle(fd);
2140 SV *sv = sv_newmortal();
2141 /* Make one call with zero size - return value is required size */
2142 DWORD len = GetCurrentDirectory((DWORD)0,NULL);
2143 SvUPGRADE(sv,SVt_PV);
2145 SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
2148 * then it worked, set PV valid,
2149 * else leave it 'undef'
2164 croak("usage: Win32::SetCurrentDirectory($cwd)");
2165 if (SetCurrentDirectory(SvPV(ST(0),n_a)))
2172 XS(w32_GetNextAvailDrive)
2176 char root[] = "_:\\";
2179 if (GetDriveType(root) == 1) {
2188 XS(w32_GetLastError)
2191 XSRETURN_IV(GetLastError());
2198 char *name = getlogin_buffer;
2199 DWORD size = sizeof(getlogin_buffer);
2200 if (GetUserName(name,&size)) {
2201 /* size includes NULL */
2202 ST(0) = sv_2mortal(newSVpv(name,size-1));
2212 char name[MAX_COMPUTERNAME_LENGTH+1];
2213 DWORD size = sizeof(name);
2214 if (GetComputerName(name,&size)) {
2215 /* size does NOT include NULL :-( */
2216 ST(0) = sv_2mortal(newSVpv(name,size));
2227 #ifndef HAS_NETWKSTAGETINFO
2228 /* mingw32 (and Win95) don't have NetWksta*(), so do it the old way */
2230 DWORD size = sizeof(name);
2231 if (GetUserName(name,&size)) {
2233 DWORD sidlen = sizeof(sid);
2235 DWORD dnamelen = sizeof(dname);
2237 if (LookupAccountName(NULL, name, (PSID)&sid, &sidlen,
2238 dname, &dnamelen, &snu)) {
2239 XSRETURN_PV(dname); /* all that for this */
2243 /* this way is more reliable, in case user has a local account.
2244 * XXX need dynamic binding of netapi32.dll symbols or this will fail on
2245 * Win95. Probably makes more sense to move it into libwin32. */
2247 DWORD dnamelen = sizeof(dname);
2248 PWKSTA_INFO_100 pwi;
2249 if (NERR_Success == NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pwi)) {
2250 if (pwi->wki100_langroup && *(pwi->wki100_langroup)) {
2251 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup,
2252 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2255 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername,
2256 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2258 NetApiBufferFree(pwi);
2270 DWORD flags, filecomplen;
2271 if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
2272 &flags, fsname, sizeof(fsname))) {
2273 if (GIMME == G_ARRAY) {
2274 XPUSHs(sv_2mortal(newSVpv(fsname,0)));
2275 XPUSHs(sv_2mortal(newSViv(flags)));
2276 XPUSHs(sv_2mortal(newSViv(filecomplen)));
2280 XSRETURN_PV(fsname);
2286 XS(w32_GetOSVersion)
2289 OSVERSIONINFO osver;
2291 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
2292 if (GetVersionEx(&osver)) {
2293 XPUSHs(newSVpv(osver.szCSDVersion, 0));
2294 XPUSHs(newSViv(osver.dwMajorVersion));
2295 XPUSHs(newSViv(osver.dwMinorVersion));
2296 XPUSHs(newSViv(osver.dwBuildNumber));
2297 XPUSHs(newSViv(osver.dwPlatformId));
2308 XSRETURN_IV(IsWinNT());
2315 XSRETURN_IV(IsWin95());
2319 XS(w32_FormatMessage)
2326 croak("usage: Win32::FormatMessage($errno)");
2328 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
2329 &source, SvIV(ST(0)), 0,
2330 msgbuf, sizeof(msgbuf)-1, NULL))
2331 XSRETURN_PV(msgbuf);
2341 PROCESS_INFORMATION stProcInfo;
2342 STARTUPINFO stStartInfo;
2343 BOOL bSuccess = FALSE;
2347 croak("usage: Win32::Spawn($cmdName, $args, $PID)");
2349 cmd = SvPV(ST(0), n_a);
2350 args = SvPV(ST(1), n_a);
2352 memset(&stStartInfo, 0, sizeof(stStartInfo)); /* Clear the block */
2353 stStartInfo.cb = sizeof(stStartInfo); /* Set the structure size */
2354 stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
2355 stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
2358 cmd, /* Image path */
2359 args, /* Arguments for command line */
2360 NULL, /* Default process security */
2361 NULL, /* Default thread security */
2362 FALSE, /* Must be TRUE to use std handles */
2363 NORMAL_PRIORITY_CLASS, /* No special scheduling */
2364 NULL, /* Inherit our environment block */
2365 NULL, /* Inherit our currrent directory */
2366 &stStartInfo, /* -> Startup info */
2367 &stProcInfo)) /* <- Process info (if OK) */
2369 CloseHandle(stProcInfo.hThread);/* library source code does this. */
2370 sv_setiv(ST(2), stProcInfo.dwProcessId);
2373 XSRETURN_IV(bSuccess);
2377 XS(w32_GetTickCount)
2380 XSRETURN_IV(GetTickCount());
2384 XS(w32_GetShortPathName)
2391 croak("usage: Win32::GetShortPathName($longPathName)");
2393 shortpath = sv_mortalcopy(ST(0));
2394 SvUPGRADE(shortpath, SVt_PV);
2395 /* src == target is allowed */
2397 len = GetShortPathName(SvPVX(shortpath),
2400 } while (len >= SvLEN(shortpath) && sv_grow(shortpath,len+1));
2402 SvCUR_set(shortpath,len);
2406 ST(0) = &PL_sv_undef;
2415 croak("usage: Win32::Sleep($milliseconds)");
2421 Perl_init_os_extras()
2423 char *file = __FILE__;
2426 w32_perlshell_tokens = Nullch;
2427 w32_perlshell_items = -1;
2428 w32_fdpid = newAV(); /* XXX needs to be in Perl_win32_init()? */
2429 #ifndef USE_RTL_WAIT
2430 w32_num_children = 0;
2433 /* these names are Activeware compatible */
2434 newXS("Win32::GetCwd", w32_GetCwd, file);
2435 newXS("Win32::SetCwd", w32_SetCwd, file);
2436 newXS("Win32::GetNextAvailDrive", w32_GetNextAvailDrive, file);
2437 newXS("Win32::GetLastError", w32_GetLastError, file);
2438 newXS("Win32::LoginName", w32_LoginName, file);
2439 newXS("Win32::NodeName", w32_NodeName, file);
2440 newXS("Win32::DomainName", w32_DomainName, file);
2441 newXS("Win32::FsType", w32_FsType, file);
2442 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2443 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2444 newXS("Win32::IsWin95", w32_IsWin95, file);
2445 newXS("Win32::FormatMessage", w32_FormatMessage, file);
2446 newXS("Win32::Spawn", w32_Spawn, file);
2447 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2448 newXS("Win32::GetShortPathName", w32_GetShortPathName, file);
2449 newXS("Win32::Sleep", w32_Sleep, file);
2451 /* XXX Bloat Alert! The following Activeware preloads really
2452 * ought to be part of Win32::Sys::*, so they're not included
2455 /* LookupAccountName
2457 * InitiateSystemShutdown
2458 * AbortSystemShutdown
2459 * ExpandEnvrironmentStrings
2464 Perl_win32_init(int *argcp, char ***argvp)
2466 /* Disable floating point errors, Perl will trap the ones we
2467 * care about. VC++ RTL defaults to switching these off
2468 * already, but the Borland RTL doesn't. Since we don't
2469 * want to be at the vendor's whim on the default, we set
2470 * it explicitly here.
2472 #if !defined(_ALPHA_) && !defined(__GNUC__)
2473 _control87(MCW_EM, MCW_EM);
2478 #ifdef USE_BINMODE_SCRIPTS
2481 win32_strip_return(SV *sv)
2483 char *s = SvPVX(sv);
2484 char *e = s+SvCUR(sv);
2488 if (*s == '\r' && s[1] == '\n')
2498 SvCUR_set(sv,d-SvPVX(sv));