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_shell_metachars(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_shell_metachars(char *ptr)
298 * Scan string looking for redirection (< or >) or pipe
299 * characters (|) that are not in a quoted string.
300 * Shell variable interpolation (%VAR%) can also happen inside strings.
332 #if !defined(PERL_OBJECT)
333 /* since the current process environment is being updated in util.c
334 * the library functions will get the correct environment
337 my_popen(char *cmd, char *mode)
340 #define fixcmd(x) { \
341 char *pspace = strchr((x),' '); \
344 while (p < pspace) { \
355 win32_fflush(stdout);
356 win32_fflush(stderr);
357 return win32_popen(cmd, mode);
361 my_pclose(PerlIO *fp)
363 return win32_pclose(fp);
370 static OSVERSIONINFO osver;
372 if (osver.dwPlatformId != w32_platform) {
373 memset(&osver, 0, sizeof(OSVERSIONINFO));
374 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
375 GetVersionEx(&osver);
376 w32_platform = osver.dwPlatformId;
378 return (w32_platform);
381 /* Tokenize a string. Words are null-separated, and the list
382 * ends with a doubled null. Any character (except null and
383 * including backslash) may be escaped by preceding it with a
384 * backslash (the backslash will be stripped).
385 * Returns number of words in result buffer.
388 tokenize(char *str, char **dest, char ***destv)
390 char *retstart = Nullch;
391 char **retvstart = 0;
394 int slen = strlen(str);
396 register char **retv;
397 New(1307, ret, slen+2, char);
398 New(1308, retv, (slen+3)/2, char*);
406 if (*ret == '\\' && *str)
408 else if (*ret == ' ') {
424 retvstart[items] = Nullch;
436 if (!w32_perlshell_tokens) {
437 /* we don't use COMSPEC here for two reasons:
438 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
439 * uncontrolled unportability of the ensuing scripts.
440 * 2. PERL5SHELL could be set to a shell that may not be fit for
441 * interactive use (which is what most programs look in COMSPEC
444 char* defaultshell = (IsWinNT() ? "cmd.exe /x/c" : "command.com /c");
445 char *usershell = getenv("PERL5SHELL");
446 w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
447 &w32_perlshell_tokens,
453 do_aspawn(void *vreally, void **vmark, void **vsp)
455 SV *really = (SV*)vreally;
456 SV **mark = (SV**)vmark;
468 New(1306, argv, (sp - mark) + w32_perlshell_items + 2, char*);
470 if (SvNIOKp(*(mark+1)) && !SvPOKp(*(mark+1))) {
475 while (++mark <= sp) {
476 if (*mark && (str = SvPV(*mark, PL_na)))
483 status = win32_spawnvp(flag,
484 (const char*)(really ? SvPV(really,PL_na) : argv[0]),
485 (const char* const*)argv);
487 if (status < 0 && errno == ENOEXEC) {
488 /* possible shell-builtin, invoke with shell */
490 sh_items = w32_perlshell_items;
492 argv[index+sh_items] = argv[index];
493 while (--sh_items >= 0)
494 argv[sh_items] = w32_perlshell_vec[sh_items];
496 status = win32_spawnvp(flag,
497 (const char*)(really ? SvPV(really,PL_na) : argv[0]),
498 (const char* const*)argv);
501 if (flag != P_NOWAIT) {
504 warn("Can't spawn \"%s\": %s", argv[0], strerror(errno));
509 PL_statusvalue = status;
516 do_spawn2(char *cmd, int exectype)
522 BOOL needToTry = TRUE;
525 /* Save an extra exec if possible. See if there are shell
526 * metacharacters in it */
527 if (!has_shell_metachars(cmd)) {
528 New(1301,argv, strlen(cmd) / 2 + 2, char*);
529 New(1302,cmd2, strlen(cmd) + 1, char);
532 for (s = cmd2; *s;) {
533 while (*s && isspace(*s))
537 while (*s && !isspace(*s))
546 status = win32_spawnvp(P_WAIT, argv[0],
547 (const char* const*)argv);
549 case EXECF_SPAWN_NOWAIT:
550 status = win32_spawnvp(P_NOWAIT, argv[0],
551 (const char* const*)argv);
554 status = win32_execvp(argv[0], (const char* const*)argv);
557 if (status != -1 || errno == 0)
567 New(1306, argv, w32_perlshell_items + 2, char*);
568 while (++i < w32_perlshell_items)
569 argv[i] = w32_perlshell_vec[i];
574 status = win32_spawnvp(P_WAIT, argv[0],
575 (const char* const*)argv);
577 case EXECF_SPAWN_NOWAIT:
578 status = win32_spawnvp(P_NOWAIT, argv[0],
579 (const char* const*)argv);
582 status = win32_execvp(argv[0], (const char* const*)argv);
588 if (exectype != EXECF_SPAWN_NOWAIT) {
591 warn("Can't %s \"%s\": %s",
592 (exectype == EXECF_EXEC ? "exec" : "spawn"),
593 cmd, strerror(errno));
598 PL_statusvalue = status;
606 return do_spawn2(cmd, EXECF_SPAWN);
610 do_spawn_nowait(char *cmd)
612 return do_spawn2(cmd, EXECF_SPAWN_NOWAIT);
618 do_spawn2(cmd, EXECF_EXEC);
622 /* The idea here is to read all the directory names into a string table
623 * (separated by nulls) and when one of the other dir functions is called
624 * return the pointer to the current file name.
627 win32_opendir(char *filename)
632 char scanname[MAX_PATH+3];
634 WIN32_FIND_DATA FindData;
637 len = strlen(filename);
641 /* check to see if filename is a directory */
642 if (win32_stat(filename, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode))
645 /* Get us a DIR structure */
646 Newz(1303, p, 1, DIR);
650 /* Create the search pattern */
651 strcpy(scanname, filename);
652 if (scanname[len-1] != '/' && scanname[len-1] != '\\')
653 scanname[len++] = '/';
654 scanname[len++] = '*';
655 scanname[len] = '\0';
657 /* do the FindFirstFile call */
658 fh = FindFirstFile(scanname, &FindData);
659 if (fh == INVALID_HANDLE_VALUE) {
660 /* FindFirstFile() fails on empty drives! */
661 if (GetLastError() == ERROR_FILE_NOT_FOUND)
667 /* now allocate the first part of the string table for
668 * the filenames that we find.
670 idx = strlen(FindData.cFileName)+1;
671 New(1304, p->start, idx, char);
672 if (p->start == NULL)
673 croak("opendir: malloc failed!\n");
674 strcpy(p->start, FindData.cFileName);
677 /* loop finding all the files that match the wildcard
678 * (which should be all of them in this directory!).
679 * the variable idx should point one past the null terminator
680 * of the previous string found.
682 while (FindNextFile(fh, &FindData)) {
683 len = strlen(FindData.cFileName);
684 /* bump the string table size by enough for the
685 * new name and it's null terminator
687 Renew(p->start, idx+len+1, char);
688 if (p->start == NULL)
689 croak("opendir: malloc failed!\n");
690 strcpy(&p->start[idx], FindData.cFileName);
701 /* Readdir just returns the current string pointer and bumps the
702 * string pointer to the nDllExport entry.
705 win32_readdir(DIR *dirp)
708 static int dummy = 0;
711 /* first set up the structure to return */
712 len = strlen(dirp->curr);
713 strcpy(dirp->dirstr.d_name, dirp->curr);
714 dirp->dirstr.d_namlen = len;
717 dirp->dirstr.d_ino = dummy++;
719 /* Now set up for the nDllExport call to readdir */
720 dirp->curr += len + 1;
721 if (dirp->curr >= (dirp->start + dirp->size)) {
725 return &(dirp->dirstr);
731 /* Telldir returns the current string pointer position */
733 win32_telldir(DIR *dirp)
735 return (long) dirp->curr;
739 /* Seekdir moves the string pointer to a previously saved position
743 win32_seekdir(DIR *dirp, long loc)
745 dirp->curr = (char *)loc;
748 /* Rewinddir resets the string pointer to the start */
750 win32_rewinddir(DIR *dirp)
752 dirp->curr = dirp->start;
755 /* free the memory allocated by opendir */
757 win32_closedir(DIR *dirp)
759 Safefree(dirp->start);
772 * Just pretend that everyone is a superuser. NT will let us know if
773 * we don\'t really have permission to do something.
776 #define ROOT_UID ((uid_t)0)
777 #define ROOT_GID ((gid_t)0)
806 return (auid == ROOT_UID ? 0 : -1);
812 return (agid == ROOT_GID ? 0 : -1);
819 char *buf = getlogin_buffer;
820 DWORD size = sizeof(getlogin_buffer);
821 if (GetUserName(buf,&size))
827 chown(const char *path, uid_t owner, gid_t group)
834 remove_dead_process(HANDLE deceased)
838 for (child = 0 ; child < w32_num_children ; ++child) {
839 if (w32_child_pids[child] == deceased) {
840 Copy(&w32_child_pids[child+1], &w32_child_pids[child],
841 (w32_num_children-child-1), HANDLE);
850 win32_kill(int pid, int sig)
853 HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
855 HANDLE hProcess = (HANDLE) pid;
858 if (hProcess == NULL) {
859 croak("kill process failed!\n");
862 if (!TerminateProcess(hProcess, sig))
863 croak("kill process failed!\n");
864 CloseHandle(hProcess);
866 /* WaitForMultipleObjects() on a pid that was killed returns error
867 * so if we know the pid is gone we remove it from process list */
868 remove_dead_process(hProcess);
877 DllExport unsigned int
878 win32_sleep(unsigned int t)
885 win32_stat(const char *path, struct stat *buffer)
888 const char *p = path;
889 int l = strlen(path);
893 switch(path[l - 1]) {
896 if (path[l - 2] != ':') {
897 strncpy(t, path, l - 1);
903 res = stat(p,buffer);
905 /* CRT is buggy on sharenames, so make sure it really isn't.
906 * XXX using GetFileAttributesEx() will enable us to set
907 * buffer->st_*time (but note that's not available on the
908 * Windows of 1995) */
909 DWORD r = GetFileAttributes(p);
910 if (r != 0xffffffff && (r & FILE_ATTRIBUTE_DIRECTORY)) {
911 buffer->st_mode |= S_IFDIR | S_IREAD;
913 if (!(r & FILE_ATTRIBUTE_READONLY))
914 buffer->st_mode |= S_IWRITE | S_IEXEC;
919 if (l == 3 && path[l-2] == ':'
920 && (path[l-1] == '\\' || path[l-1] == '/'))
922 /* The drive can be inaccessible, some _stat()s are buggy */
923 if (!GetVolumeInformation(path,NULL,0,NULL,NULL,NULL,NULL,0)) {
929 if (S_ISDIR(buffer->st_mode))
930 buffer->st_mode |= S_IWRITE | S_IEXEC;
931 else if (S_ISREG(buffer->st_mode)) {
932 if (l >= 4 && path[l-4] == '.') {
933 const char *e = path + l - 3;
934 if (strnicmp(e,"exe",3)
935 && strnicmp(e,"bat",3)
936 && strnicmp(e,"com",3)
937 && (IsWin95() || strnicmp(e,"cmd",3)))
938 buffer->st_mode &= ~S_IEXEC;
940 buffer->st_mode |= S_IEXEC;
943 buffer->st_mode &= ~S_IEXEC;
950 #ifndef USE_WIN32_RTL_ENV
953 win32_getenv(const char *name)
955 static char *curitem = Nullch; /* XXX threadead */
956 static DWORD curlen = 0; /* XXX threadead */
960 New(1305,curitem,curlen,char);
963 needlen = GetEnvironmentVariable(name,curitem,curlen);
965 while (needlen > curlen) {
966 Renew(curitem,needlen,char);
968 needlen = GetEnvironmentVariable(name,curitem,curlen);
972 /* allow any environment variables that begin with 'PERL'
973 to be stored in the registry */
977 if (strncmp(name, "PERL", 4) == 0) {
983 curitem = GetRegStr(name, &curitem, &curlen);
986 if (curitem && *curitem == '\0')
995 filetime_to_clock(PFILETIME ft)
997 __int64 qw = ft->dwHighDateTime;
999 qw |= ft->dwLowDateTime;
1000 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
1005 win32_times(struct tms *timebuf)
1010 if (GetProcessTimes(GetCurrentProcess(), &dummy, &dummy,
1012 timebuf->tms_utime = filetime_to_clock(&user);
1013 timebuf->tms_stime = filetime_to_clock(&kernel);
1014 timebuf->tms_cutime = 0;
1015 timebuf->tms_cstime = 0;
1018 /* That failed - e.g. Win95 fallback to clock() */
1019 clock_t t = clock();
1020 timebuf->tms_utime = t;
1021 timebuf->tms_stime = 0;
1022 timebuf->tms_cutime = 0;
1023 timebuf->tms_cstime = 0;
1028 /* fix utime() so it works on directories in NT
1029 * thanks to Jan Dubois <jan.dubois@ibm.net>
1032 filetime_from_time(PFILETIME pFileTime, time_t Time)
1034 struct tm *pTM = gmtime(&Time);
1035 SYSTEMTIME SystemTime;
1040 SystemTime.wYear = pTM->tm_year + 1900;
1041 SystemTime.wMonth = pTM->tm_mon + 1;
1042 SystemTime.wDay = pTM->tm_mday;
1043 SystemTime.wHour = pTM->tm_hour;
1044 SystemTime.wMinute = pTM->tm_min;
1045 SystemTime.wSecond = pTM->tm_sec;
1046 SystemTime.wMilliseconds = 0;
1048 return SystemTimeToFileTime(&SystemTime, pFileTime);
1052 win32_utime(const char *filename, struct utimbuf *times)
1058 struct utimbuf TimeBuffer;
1060 int rc = utime(filename,times);
1061 /* EACCES: path specifies directory or readonly file */
1062 if (rc == 0 || errno != EACCES /* || !IsWinNT() */)
1065 if (times == NULL) {
1066 times = &TimeBuffer;
1067 time(×->actime);
1068 times->modtime = times->actime;
1071 /* This will (and should) still fail on readonly files */
1072 handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
1073 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL,
1074 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1075 if (handle == INVALID_HANDLE_VALUE)
1078 if (GetFileTime(handle, &ftCreate, &ftAccess, &ftWrite) &&
1079 filetime_from_time(&ftAccess, times->actime) &&
1080 filetime_from_time(&ftWrite, times->modtime) &&
1081 SetFileTime(handle, &ftCreate, &ftAccess, &ftWrite))
1086 CloseHandle(handle);
1091 win32_waitpid(int pid, int *status, int flags)
1095 return win32_wait(status);
1097 rc = cwait(status, pid, WAIT_CHILD);
1098 /* cwait() returns differently on Borland */
1101 *status = (((*status >> 8) & 0xff) | ((*status << 8) & 0xff00));
1103 remove_dead_process((HANDLE)pid);
1105 return rc >= 0 ? pid : rc;
1109 win32_wait(int *status)
1112 return wait(status);
1114 /* XXX this wait emulation only knows about processes
1115 * spawned via win32_spawnvp(P_NOWAIT, ...).
1118 DWORD exitcode, waitcode;
1120 if (!w32_num_children) {
1125 /* if a child exists, wait for it to die */
1126 waitcode = WaitForMultipleObjects(w32_num_children,
1130 if (waitcode != WAIT_FAILED) {
1131 if (waitcode >= WAIT_ABANDONED_0
1132 && waitcode < WAIT_ABANDONED_0 + w32_num_children)
1133 i = waitcode - WAIT_ABANDONED_0;
1135 i = waitcode - WAIT_OBJECT_0;
1136 if (GetExitCodeProcess(w32_child_pids[i], &exitcode) ) {
1137 CloseHandle(w32_child_pids[i]);
1138 *status = (int)((exitcode & 0xff) << 8);
1139 retval = (int)w32_child_pids[i];
1140 Copy(&w32_child_pids[i+1], &w32_child_pids[i],
1141 (w32_num_children-i-1), HANDLE);
1148 errno = GetLastError();
1154 static UINT timerid = 0;
1156 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
1158 KillTimer(NULL,timerid);
1163 DllExport unsigned int
1164 win32_alarm(unsigned int sec)
1167 * the 'obvious' implentation is SetTimer() with a callback
1168 * which does whatever receiving SIGALRM would do
1169 * we cannot use SIGALRM even via raise() as it is not
1170 * one of the supported codes in <signal.h>
1172 * Snag is unless something is looking at the message queue
1173 * nothing happens :-(
1177 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
1179 croak("Cannot set timer");
1185 KillTimer(NULL,timerid);
1192 #if defined(HAVE_DES_FCRYPT) || defined(PERL_OBJECT)
1193 #ifdef HAVE_DES_FCRYPT
1194 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
1198 win32_crypt(const char *txt, const char *salt)
1200 #ifdef HAVE_DES_FCRYPT
1202 return des_fcrypt(txt, salt, crypt_buffer);
1204 die("The crypt() function is unimplemented due to excessive paranoia.");
1210 #ifdef USE_FIXED_OSFHANDLE
1212 EXTERN_C int __cdecl _alloc_osfhnd(void);
1213 EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
1214 EXTERN_C void __cdecl _lock_fhandle(int);
1215 EXTERN_C void __cdecl _unlock_fhandle(int);
1216 EXTERN_C void __cdecl _unlock(int);
1218 #if (_MSC_VER >= 1000)
1220 long osfhnd; /* underlying OS file HANDLE */
1221 char osfile; /* attributes of file (e.g., open in text mode?) */
1222 char pipech; /* one char buffer for handles opened on pipes */
1223 #if defined (_MT) && !defined (DLL_FOR_WIN32S)
1225 CRITICAL_SECTION lock;
1226 #endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
1229 EXTERN_C ioinfo * __pioinfo[];
1231 #define IOINFO_L2E 5
1232 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
1233 #define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
1234 #define _osfile(i) (_pioinfo(i)->osfile)
1236 #else /* (_MSC_VER >= 1000) */
1237 extern char _osfile[];
1238 #endif /* (_MSC_VER >= 1000) */
1240 #define FOPEN 0x01 /* file handle open */
1241 #define FAPPEND 0x20 /* file handle opened O_APPEND */
1242 #define FDEV 0x40 /* file handle refers to device */
1243 #define FTEXT 0x80 /* file handle is in text mode */
1245 #define _STREAM_LOCKS 26 /* Table of stream locks */
1246 #define _LAST_STREAM_LOCK (_STREAM_LOCKS+_NSTREAM_-1) /* Last stream lock */
1247 #define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
1250 *int my_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
1253 * This function allocates a free C Runtime file handle and associates
1254 * it with the Win32 HANDLE specified by the first parameter. This is a
1255 * temperary fix for WIN95's brain damage GetFileType() error on socket
1256 * we just bypass that call for socket
1259 * long osfhandle - Win32 HANDLE to associate with C Runtime file handle.
1260 * int flags - flags to associate with C Runtime file handle.
1263 * returns index of entry in fh, if successful
1264 * return -1, if no free entry is found
1268 *******************************************************************************/
1271 my_open_osfhandle(long osfhandle, int flags)
1274 char fileflags; /* _osfile flags */
1276 /* copy relevant flags from second parameter */
1279 if (flags & O_APPEND)
1280 fileflags |= FAPPEND;
1285 /* attempt to allocate a C Runtime file handle */
1286 if ((fh = _alloc_osfhnd()) == -1) {
1287 errno = EMFILE; /* too many open files */
1288 _doserrno = 0L; /* not an OS error */
1289 return -1; /* return error to caller */
1292 /* the file is open. now, set the info in _osfhnd array */
1293 _set_osfhnd(fh, osfhandle);
1295 fileflags |= FOPEN; /* mark as open */
1297 #if (_MSC_VER >= 1000)
1298 _osfile(fh) = fileflags; /* set osfile entry */
1299 _unlock_fhandle(fh);
1301 _osfile[fh] = fileflags; /* set osfile entry */
1302 _unlock(fh+_FH_LOCKS); /* unlock handle */
1305 return fh; /* return handle */
1308 #define _open_osfhandle my_open_osfhandle
1309 #endif /* USE_FIXED_OSFHANDLE */
1311 /* simulate flock by locking a range on the file */
1313 #define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
1314 #define LK_LEN 0xffff0000
1317 win32_flock(int fd, int oper)
1324 croak("flock() unimplemented on this platform");
1327 fh = (HANDLE)_get_osfhandle(fd);
1328 memset(&o, 0, sizeof(o));
1331 case LOCK_SH: /* shared lock */
1332 LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
1334 case LOCK_EX: /* exclusive lock */
1335 LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
1337 case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
1338 LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
1340 case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
1341 LK_ERR(LockFileEx(fh,
1342 LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
1343 0, LK_LEN, 0, &o),i);
1345 case LOCK_UN: /* unlock lock */
1346 LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
1348 default: /* unknown */
1359 * redirected io subsystem for all XS modules
1372 return (&(_environ));
1375 /* the rest are the remapped stdio routines */
1395 win32_ferror(FILE *fp)
1397 return (ferror(fp));
1402 win32_feof(FILE *fp)
1408 * Since the errors returned by the socket error function
1409 * WSAGetLastError() are not known by the library routine strerror
1410 * we have to roll our own.
1414 win32_strerror(int e)
1416 #ifndef __BORLANDC__ /* Borland intolerance */
1417 extern int sys_nerr;
1421 if (e < 0 || e > sys_nerr) {
1426 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
1427 strerror_buffer, sizeof(strerror_buffer), NULL) == 0)
1428 strcpy(strerror_buffer, "Unknown Error");
1430 return strerror_buffer;
1436 win32_str_os_error(void *sv, DWORD dwErr)
1440 dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
1441 |FORMAT_MESSAGE_IGNORE_INSERTS
1442 |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
1443 dwErr, 0, (char *)&sMsg, 1, NULL);
1445 while (0 < dwLen && isspace(sMsg[--dwLen]))
1447 if ('.' != sMsg[dwLen])
1452 sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
1453 dwLen = sprintf(sMsg,
1454 "Unknown error #0x%lX (lookup 0x%lX)",
1455 dwErr, GetLastError());
1457 sv_setpvn((SV*)sv, sMsg, dwLen);
1463 win32_fprintf(FILE *fp, const char *format, ...)
1466 va_start(marker, format); /* Initialize variable arguments. */
1468 return (vfprintf(fp, format, marker));
1472 win32_printf(const char *format, ...)
1475 va_start(marker, format); /* Initialize variable arguments. */
1477 return (vprintf(format, marker));
1481 win32_vfprintf(FILE *fp, const char *format, va_list args)
1483 return (vfprintf(fp, format, args));
1487 win32_vprintf(const char *format, va_list args)
1489 return (vprintf(format, args));
1493 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
1495 return fread(buf, size, count, fp);
1499 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
1501 return fwrite(buf, size, count, fp);
1505 win32_fopen(const char *filename, const char *mode)
1507 if (stricmp(filename, "/dev/null")==0)
1508 return fopen("NUL", mode);
1509 return fopen(filename, mode);
1512 #ifndef USE_SOCKETS_AS_HANDLES
1514 #define fdopen my_fdopen
1518 win32_fdopen( int handle, const char *mode)
1520 return fdopen(handle, (char *) mode);
1524 win32_freopen( const char *path, const char *mode, FILE *stream)
1526 if (stricmp(path, "/dev/null")==0)
1527 return freopen("NUL", mode, stream);
1528 return freopen(path, mode, stream);
1532 win32_fclose(FILE *pf)
1534 return my_fclose(pf); /* defined in win32sck.c */
1538 win32_fputs(const char *s,FILE *pf)
1540 return fputs(s, pf);
1544 win32_fputc(int c,FILE *pf)
1550 win32_ungetc(int c,FILE *pf)
1552 return ungetc(c,pf);
1556 win32_getc(FILE *pf)
1562 win32_fileno(FILE *pf)
1568 win32_clearerr(FILE *pf)
1575 win32_fflush(FILE *pf)
1581 win32_ftell(FILE *pf)
1587 win32_fseek(FILE *pf,long offset,int origin)
1589 return fseek(pf, offset, origin);
1593 win32_fgetpos(FILE *pf,fpos_t *p)
1595 return fgetpos(pf, p);
1599 win32_fsetpos(FILE *pf,const fpos_t *p)
1601 return fsetpos(pf, p);
1605 win32_rewind(FILE *pf)
1625 win32_fstat(int fd,struct stat *sbufptr)
1627 return fstat(fd,sbufptr);
1631 win32_pipe(int *pfd, unsigned int size, int mode)
1633 return _pipe(pfd, size, mode);
1637 * a popen() clone that respects PERL5SHELL
1641 win32_popen(const char *command, const char *mode)
1643 #ifdef USE_RTL_POPEN
1644 return _popen(command, mode);
1652 /* establish which ends read and write */
1653 if (strchr(mode,'w')) {
1654 stdfd = 0; /* stdin */
1658 else if (strchr(mode,'r')) {
1659 stdfd = 1; /* stdout */
1666 /* set the correct mode */
1667 if (strchr(mode,'b'))
1669 else if (strchr(mode,'t'))
1672 ourmode = _fmode & (O_TEXT | O_BINARY);
1674 /* the child doesn't inherit handles */
1675 ourmode |= O_NOINHERIT;
1677 if (win32_pipe( p, 512, ourmode) == -1)
1680 /* save current stdfd */
1681 if ((oldfd = win32_dup(stdfd)) == -1)
1684 /* make stdfd go to child end of pipe (implicitly closes stdfd) */
1685 /* stdfd will be inherited by the child */
1686 if (win32_dup2(p[child], stdfd) == -1)
1689 /* close the child end in parent */
1690 win32_close(p[child]);
1692 /* start the child */
1693 if ((childpid = do_spawn_nowait((char*)command)) == -1)
1696 /* revert stdfd to whatever it was before */
1697 if (win32_dup2(oldfd, stdfd) == -1)
1700 /* close saved handle */
1703 sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
1705 /* we have an fd, return a file stream */
1706 return (win32_fdopen(p[parent], (char *)mode));
1709 /* we don't need to check for errors here */
1713 win32_dup2(oldfd, stdfd);
1718 #endif /* USE_RTL_POPEN */
1726 win32_pclose(FILE *pf)
1728 #ifdef USE_RTL_POPEN
1732 int childpid, status;
1735 sv = *av_fetch(w32_fdpid, win32_fileno(pf), TRUE);
1737 childpid = SvIVX(sv);
1749 remove_dead_process((HANDLE)childpid);
1751 /* wait for the child */
1752 if (cwait(&status, childpid, WAIT_CHILD) == -1)
1754 /* cwait() returns differently on Borland */
1756 return (((status >> 8) & 0xff) | ((status << 8) & 0xff00));
1761 #endif /* USE_RTL_POPEN */
1765 win32_rename(const char *oname, const char *newname)
1767 char szNewWorkName[MAX_PATH+1];
1768 WIN32_FIND_DATA fdOldFile, fdNewFile;
1772 if ((strchr(oname, '\\') || strchr(oname, '/'))
1773 && strchr(newname, '\\') == NULL
1774 && strchr(newname, '/') == NULL)
1776 strcpy(szNewWorkName, oname);
1777 if ((ptr = strrchr(szNewWorkName, '\\')) == NULL)
1778 ptr = strrchr(szNewWorkName, '/');
1779 strcpy(++ptr, newname);
1782 strcpy(szNewWorkName, newname);
1784 if (stricmp(oname, szNewWorkName) != 0) {
1785 // check that we're not being fooled by relative paths
1786 // and only delete the new file
1788 // 2) it is not the same file as the old file
1789 // 3) old file exist
1790 // GetFullPathName does not return the long file name on some systems
1791 handle = FindFirstFile(oname, &fdOldFile);
1792 if (handle != INVALID_HANDLE_VALUE) {
1795 handle = FindFirstFile(szNewWorkName, &fdNewFile);
1797 if (handle != INVALID_HANDLE_VALUE)
1800 fdNewFile.cFileName[0] = '\0';
1802 if (strcmp(fdOldFile.cAlternateFileName,
1803 fdNewFile.cAlternateFileName) != 0
1804 && strcmp(fdOldFile.cFileName, fdNewFile.cFileName) != 0)
1806 // file exists and not same file
1807 DeleteFile(szNewWorkName);
1811 return rename(oname, newname);
1815 win32_setmode(int fd, int mode)
1817 return setmode(fd, mode);
1821 win32_lseek(int fd, long offset, int origin)
1823 return lseek(fd, offset, origin);
1833 win32_open(const char *path, int flag, ...)
1839 pmode = va_arg(ap, int);
1842 if (stricmp(path, "/dev/null")==0)
1843 return open("NUL", flag, pmode);
1844 return open(path,flag,pmode);
1866 win32_dup2(int fd1,int fd2)
1868 return dup2(fd1,fd2);
1872 win32_read(int fd, void *buf, unsigned int cnt)
1874 return read(fd, buf, cnt);
1878 win32_write(int fd, const void *buf, unsigned int cnt)
1880 return write(fd, buf, cnt);
1884 win32_mkdir(const char *dir, int mode)
1886 return mkdir(dir); /* just ignore mode */
1890 win32_rmdir(const char *dir)
1896 win32_chdir(const char *dir)
1902 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1906 #ifndef USE_RTL_WAIT
1907 if (mode == P_NOWAIT && w32_num_children >= MAXIMUM_WAIT_OBJECTS)
1911 status = spawnvp(mode, cmdname, (char * const *) argv);
1912 #ifndef USE_RTL_WAIT
1913 /* XXX For the P_NOWAIT case, Borland RTL returns pinfo.dwProcessId
1914 * while VC RTL returns pinfo.hProcess. For purposes of the custom
1915 * implementation of win32_wait(), we assume the latter.
1917 if (mode == P_NOWAIT && status >= 0)
1918 w32_child_pids[w32_num_children++] = (HANDLE)status;
1924 win32_execv(const char *cmdname, const char *const *argv)
1926 return execv(cmdname, (char *const *)argv);
1930 win32_execvp(const char *cmdname, const char *const *argv)
1932 return execvp(cmdname, (char *const *)argv);
1936 win32_perror(const char *str)
1942 win32_setbuf(FILE *pf, char *buf)
1948 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1950 return setvbuf(pf, buf, type, size);
1954 win32_flushall(void)
1960 win32_fcloseall(void)
1966 win32_fgets(char *s, int n, FILE *pf)
1968 return fgets(s, n, pf);
1978 win32_fgetc(FILE *pf)
1984 win32_putc(int c, FILE *pf)
1990 win32_puts(const char *s)
2002 win32_putchar(int c)
2009 #ifndef USE_PERL_SBRK
2011 static char *committed = NULL;
2012 static char *base = NULL;
2013 static char *reserved = NULL;
2014 static char *brk = NULL;
2015 static DWORD pagesize = 0;
2016 static DWORD allocsize = 0;
2024 GetSystemInfo(&info);
2025 /* Pretend page size is larger so we don't perpetually
2026 * call the OS to commit just one page ...
2028 pagesize = info.dwPageSize << 3;
2029 allocsize = info.dwAllocationGranularity;
2031 /* This scheme fails eventually if request for contiguous
2032 * block is denied so reserve big blocks - this is only
2033 * address space not memory ...
2035 if (brk+need >= reserved)
2037 DWORD size = 64*1024*1024;
2039 if (committed && reserved && committed < reserved)
2041 /* Commit last of previous chunk cannot span allocations */
2042 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
2044 committed = reserved;
2046 /* Reserve some (more) space
2047 * Note this is a little sneaky, 1st call passes NULL as reserved
2048 * so lets system choose where we start, subsequent calls pass
2049 * the old end address so ask for a contiguous block
2051 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
2054 reserved = addr+size;
2069 if (brk > committed)
2071 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
2072 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
2087 win32_malloc(size_t size)
2089 return malloc(size);
2093 win32_calloc(size_t numitems, size_t size)
2095 return calloc(numitems,size);
2099 win32_realloc(void *block, size_t size)
2101 return realloc(block,size);
2105 win32_free(void *block)
2112 win32_open_osfhandle(long handle, int flags)
2114 return _open_osfhandle(handle, flags);
2118 win32_get_osfhandle(int fd)
2120 return _get_osfhandle(fd);
2131 SV *sv = sv_newmortal();
2132 /* Make one call with zero size - return value is required size */
2133 DWORD len = GetCurrentDirectory((DWORD)0,NULL);
2134 SvUPGRADE(sv,SVt_PV);
2136 SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
2139 * then it worked, set PV valid,
2140 * else leave it 'undef'
2154 croak("usage: Win32::SetCurrentDirectory($cwd)");
2155 if (SetCurrentDirectory(SvPV(ST(0),PL_na)))
2162 XS(w32_GetNextAvailDrive)
2166 char root[] = "_:\\";
2169 if (GetDriveType(root) == 1) {
2178 XS(w32_GetLastError)
2181 XSRETURN_IV(GetLastError());
2188 char *name = getlogin_buffer;
2189 DWORD size = sizeof(getlogin_buffer);
2190 if (GetUserName(name,&size)) {
2191 /* size includes NULL */
2192 ST(0) = sv_2mortal(newSVpv(name,size-1));
2202 char name[MAX_COMPUTERNAME_LENGTH+1];
2203 DWORD size = sizeof(name);
2204 if (GetComputerName(name,&size)) {
2205 /* size does NOT include NULL :-( */
2206 ST(0) = sv_2mortal(newSVpv(name,size));
2217 #ifndef HAS_NETWKSTAGETINFO
2218 /* mingw32 (and Win95) don't have NetWksta*(), so do it the old way */
2220 DWORD size = sizeof(name);
2221 if (GetUserName(name,&size)) {
2223 DWORD sidlen = sizeof(sid);
2225 DWORD dnamelen = sizeof(dname);
2227 if (LookupAccountName(NULL, name, (PSID)&sid, &sidlen,
2228 dname, &dnamelen, &snu)) {
2229 XSRETURN_PV(dname); /* all that for this */
2233 /* this way is more reliable, in case user has a local account.
2234 * XXX need dynamic binding of netapi32.dll symbols or this will fail on
2235 * Win95. Probably makes more sense to move it into libwin32. */
2237 DWORD dnamelen = sizeof(dname);
2238 PWKSTA_INFO_100 pwi;
2239 if (NERR_Success == NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pwi)) {
2240 if (pwi->wki100_langroup && *(pwi->wki100_langroup)) {
2241 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup,
2242 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2245 WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername,
2246 -1, (LPSTR)dname, dnamelen, NULL, NULL);
2248 NetApiBufferFree(pwi);
2260 DWORD flags, filecomplen;
2261 if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
2262 &flags, fsname, sizeof(fsname))) {
2263 if (GIMME == G_ARRAY) {
2264 XPUSHs(sv_2mortal(newSVpv(fsname,0)));
2265 XPUSHs(sv_2mortal(newSViv(flags)));
2266 XPUSHs(sv_2mortal(newSViv(filecomplen)));
2270 XSRETURN_PV(fsname);
2276 XS(w32_GetOSVersion)
2279 OSVERSIONINFO osver;
2281 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
2282 if (GetVersionEx(&osver)) {
2283 XPUSHs(newSVpv(osver.szCSDVersion, 0));
2284 XPUSHs(newSViv(osver.dwMajorVersion));
2285 XPUSHs(newSViv(osver.dwMinorVersion));
2286 XPUSHs(newSViv(osver.dwBuildNumber));
2287 XPUSHs(newSViv(osver.dwPlatformId));
2298 XSRETURN_IV(IsWinNT());
2305 XSRETURN_IV(IsWin95());
2309 XS(w32_FormatMessage)
2316 croak("usage: Win32::FormatMessage($errno)");
2318 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
2319 &source, SvIV(ST(0)), 0,
2320 msgbuf, sizeof(msgbuf)-1, NULL))
2321 XSRETURN_PV(msgbuf);
2331 PROCESS_INFORMATION stProcInfo;
2332 STARTUPINFO stStartInfo;
2333 BOOL bSuccess = FALSE;
2336 croak("usage: Win32::Spawn($cmdName, $args, $PID)");
2338 cmd = SvPV(ST(0),PL_na);
2339 args = SvPV(ST(1), PL_na);
2341 memset(&stStartInfo, 0, sizeof(stStartInfo)); /* Clear the block */
2342 stStartInfo.cb = sizeof(stStartInfo); /* Set the structure size */
2343 stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
2344 stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
2347 cmd, /* Image path */
2348 args, /* Arguments for command line */
2349 NULL, /* Default process security */
2350 NULL, /* Default thread security */
2351 FALSE, /* Must be TRUE to use std handles */
2352 NORMAL_PRIORITY_CLASS, /* No special scheduling */
2353 NULL, /* Inherit our environment block */
2354 NULL, /* Inherit our currrent directory */
2355 &stStartInfo, /* -> Startup info */
2356 &stProcInfo)) /* <- Process info (if OK) */
2358 CloseHandle(stProcInfo.hThread);/* library source code does this. */
2359 sv_setiv(ST(2), stProcInfo.dwProcessId);
2362 XSRETURN_IV(bSuccess);
2366 XS(w32_GetTickCount)
2369 XSRETURN_IV(GetTickCount());
2373 XS(w32_GetShortPathName)
2380 croak("usage: Win32::GetShortPathName($longPathName)");
2382 shortpath = sv_mortalcopy(ST(0));
2383 SvUPGRADE(shortpath, SVt_PV);
2384 /* src == target is allowed */
2386 len = GetShortPathName(SvPVX(shortpath),
2389 } while (len >= SvLEN(shortpath) && sv_grow(shortpath,len+1));
2391 SvCUR_set(shortpath,len);
2395 ST(0) = &PL_sv_undef;
2404 croak("usage: Win32::Sleep($milliseconds)");
2410 Perl_init_os_extras()
2412 char *file = __FILE__;
2415 w32_perlshell_tokens = Nullch;
2416 w32_perlshell_items = -1;
2417 w32_fdpid = newAV(); /* XXX needs to be in Perl_win32_init()? */
2418 #ifndef USE_RTL_WAIT
2419 w32_num_children = 0;
2422 /* these names are Activeware compatible */
2423 newXS("Win32::GetCwd", w32_GetCwd, file);
2424 newXS("Win32::SetCwd", w32_SetCwd, file);
2425 newXS("Win32::GetNextAvailDrive", w32_GetNextAvailDrive, file);
2426 newXS("Win32::GetLastError", w32_GetLastError, file);
2427 newXS("Win32::LoginName", w32_LoginName, file);
2428 newXS("Win32::NodeName", w32_NodeName, file);
2429 newXS("Win32::DomainName", w32_DomainName, file);
2430 newXS("Win32::FsType", w32_FsType, file);
2431 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2432 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2433 newXS("Win32::IsWin95", w32_IsWin95, file);
2434 newXS("Win32::FormatMessage", w32_FormatMessage, file);
2435 newXS("Win32::Spawn", w32_Spawn, file);
2436 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2437 newXS("Win32::GetShortPathName", w32_GetShortPathName, file);
2438 newXS("Win32::Sleep", w32_Sleep, file);
2440 /* XXX Bloat Alert! The following Activeware preloads really
2441 * ought to be part of Win32::Sys::*, so they're not included
2444 /* LookupAccountName
2446 * InitiateSystemShutdown
2447 * AbortSystemShutdown
2448 * ExpandEnvrironmentStrings
2453 Perl_win32_init(int *argcp, char ***argvp)
2455 /* Disable floating point errors, Perl will trap the ones we
2456 * care about. VC++ RTL defaults to switching these off
2457 * already, but the Borland RTL doesn't. Since we don't
2458 * want to be at the vendor's whim on the default, we set
2459 * it explicitly here.
2461 #if !defined(_ALPHA_) && !defined(__GNUC__)
2462 _control87(MCW_EM, MCW_EM);
2467 #ifdef USE_BINMODE_SCRIPTS
2470 win32_strip_return(SV *sv)
2472 char *s = SvPVX(sv);
2473 char *e = s+SvCUR(sv);
2477 if (*s == '\r' && s[1] == '\n')
2487 SvCUR_set(sv,d-SvPVX(sv));