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
16 /* #include "config.h" */
18 #define PERLIO_NOT_STDIO 0
19 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
38 #define EXECF_SPAWN_NOWAIT 3
40 static DWORD IdOS(void);
42 extern WIN32_IOSUBSYSTEM win32stdio;
43 static PWIN32_IOSUBSYSTEM pIOSubSystem = &win32stdio;
45 BOOL ProbeEnv = FALSE;
46 DWORD Win32System = (DWORD)-1;
47 char szShellPath[MAX_PATH+1];
48 char szPerlLibRoot[MAX_PATH+1];
49 HANDLE PerlDllHandle = INVALID_HANDLE_VALUE;
51 static int do_spawn2(char *cmd, int exectype);
55 return (IdOS() == VER_PLATFORM_WIN32_WINDOWS);
60 return (IdOS() == VER_PLATFORM_WIN32_NT);
64 SetIOSubSystem(void *p)
66 PWIN32_IOSUBSYSTEM old = pIOSubSystem;
68 PWIN32_IOSUBSYSTEM pio = (PWIN32_IOSUBSYSTEM)p;
69 if (pio->signature_begin == 12345678L
70 && pio->signature_end == 87654321L) {
75 pIOSubSystem = &win32stdio;
81 win32PerlLibPath(void)
84 GetModuleFileName((PerlDllHandle == INVALID_HANDLE_VALUE)
85 ? GetModuleHandle(NULL)
88 sizeof(szPerlLibRoot));
90 *(end = strrchr(szPerlLibRoot, '\\')) = '\0';
91 if (stricmp(end-4,"\\bin") == 0)
94 return (szPerlLibRoot);
98 win32SiteLibPath(void)
100 static char szPerlSiteLib[MAX_PATH+1];
101 strcpy(szPerlSiteLib, win32PerlLibPath());
102 strcat(szPerlSiteLib, "\\site");
103 return (szPerlSiteLib);
107 HasRedirection(char *ptr)
113 * Scan string looking for redirection (< or >) or pipe
114 * characters (|) that are not in a quoted string
144 /* since the current process environment is being updated in util.c
145 * the library functions will get the correct environment
148 my_popen(char *cmd, char *mode)
151 #define fixcmd(x) { \
152 char *pspace = strchr((x),' '); \
155 while (p < pspace) { \
167 /* was #ifndef PERLDLL, but the #else stuff doesn't work on NT
171 #ifdef __BORLANDC__ /* workaround a Borland stdio bug */
172 win32_fflush(stdout);
173 win32_fflush(stderr);
175 return win32_popen(cmd, mode);
178 * There seems to be some problems for the _popen call in a DLL
179 * this trick at the moment seems to work but it is never test
184 #define EXT_C_FUNC extern "C"
186 #define EXT_C_FUNC extern
189 EXT_C_FUNC int __cdecl _set_osfhnd(int fh, long value);
190 EXT_C_FUNC void __cdecl _lock_fhandle(int);
191 EXT_C_FUNC void __cdecl _unlock_fhandle(int);
194 PerlIO *pf; /* to store the _popen return value */
195 int tm = 0; /* flag indicating tDllExport or binary mode */
196 int fhNeeded, fhInherited, fhDup;
197 int ineeded, iinherited;
199 int phdls[2]; /* I/O handles for pipe */
200 HANDLE hPIn, hPOut, hPErr,
201 hSaveStdin, hSaveStdout, hSaveStderr,
202 hPNeeded, hPInherited, hPDuped;
204 /* first check for errors in the arguments */
205 if ( (cmd == NULL) || (mode == NULL)
206 || ((*mode != 'w') && (*mode != _T('r'))) )
209 if ( *(mode + 1) == _T('t') )
211 else if ( *(mode + 1) == _T('b') )
214 tm = (*mode == 'w' ? O_BINARY : O_TEXT);
218 if (&win32stdio != pIOSubSystem)
219 return win32_popen(cmd, mode);
222 if ( _pipe( phdls, 1024, tm ) == -1 )
224 if ( win32_pipe( phdls, 1024, tm ) == -1 )
228 /* save the current situation */
229 hSaveStdin = GetStdHandle(STD_INPUT_HANDLE);
230 hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
231 hSaveStderr = GetStdHandle(STD_ERROR_HANDLE);
233 if (*mode == _T('w')) {
235 dwDup = STD_INPUT_HANDLE;
240 dwDup = STD_OUTPUT_HANDLE;
244 fhNeeded = phdls[ineeded];
245 fhInherited = phdls[iinherited];
247 fSuccess = DuplicateHandle(GetCurrentProcess(),
248 (HANDLE) stolen_get_osfhandle(fhNeeded),
252 FALSE, /* not inherited */
253 DUPLICATE_SAME_ACCESS);
258 fhDup = stolen_open_osfhandle((long) hPNeeded, tm);
259 win32_dup2(fhDup, fhNeeded);
263 /* Close the Out pipe, child won't need it */
264 hPDuped = (HANDLE) stolen_get_osfhandle(fhNeeded);
266 _lock_fhandle(fhNeeded);
267 _set_osfhnd(fhNeeded, (long)hPNeeded); /* put in ours duplicated one */
268 _unlock_fhandle(fhNeeded);
270 CloseHandle(hPDuped); /* close the handle first */
273 if (!SetStdHandle(dwDup, (HANDLE) stolen_get_osfhandle(fhInherited)))
277 * make sure the child see the same stderr as the calling program
279 if (!SetStdHandle(STD_ERROR_HANDLE,
280 (HANDLE)stolen_get_osfhandle(win32_fileno(win32_stderr()))))
283 pf = win32_popen(cmd, mode); /* ask _popen to do the job */
285 /* restore to where we were */
286 SetStdHandle(STD_INPUT_HANDLE, hSaveStdin);
287 SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout);
288 SetStdHandle(STD_ERROR_HANDLE, hSaveStderr);
290 /* we don't need it any more, that's for the child */
291 win32_close(fhInherited);
294 /* something wrong */
295 win32_close(fhNeeded);
300 * here we steal the file handle in pf and stuff ours in
302 win32_dup2(fhNeeded, win32_fileno(pf));
303 win32_close(fhNeeded);
308 win32_close(fhNeeded);
309 win32_close(fhInherited);
318 my_pclose(PerlIO *fp)
320 return win32_pclose(fp);
326 static OSVERSIONINFO osver;
328 if (osver.dwPlatformId != Win32System) {
329 memset(&osver, 0, sizeof(OSVERSIONINFO));
330 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
331 GetVersionEx(&osver);
332 Win32System = osver.dwPlatformId;
334 return (Win32System);
341 char* defaultshell = (IsWinNT() ? "cmd.exe" : "command.com");
342 /* we don't use COMSPEC here for two reasons:
343 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
344 * uncontrolled unportability of the ensuing scripts.
345 * 2. PERL5SHELL could be set to a shell that may not be fit for
346 * interactive use (which is what most programs look in COMSPEC
349 char *usershell = getenv("PERL5SHELL");
352 strcpy(szShellPath, usershell ? usershell : defaultshell);
358 do_aspawn(void* really, void** mark, void** arglast)
366 SV *sv = (SV*)really;
367 SV** pSv = (SV**)mark;
369 New(1310, argv, (arglast - mark) + 4, char*);
372 cmd = SvPV(sv, length);
375 argv[index++] = cmd = GetShell();
376 argv[index++] = "/x"; /* always enable command extensions */
377 argv[index++] = "/c";
380 while(++pSv <= (SV**)arglast) {
382 strPtr = SvPV(sv, length);
383 if(strPtr != NULL && *strPtr != '\0')
384 argv[index++] = strPtr;
388 status = win32_spawnvp(P_WAIT, cmd, (const char* const*)argv);
394 warn("Can't spawn \"%s\": %s", cmd, strerror(errno));
401 do_spawn2(char *cmd, int exectype)
407 BOOL needToTry = TRUE;
410 /* save an extra exec if possible */
413 /* see if there are shell metacharacters in it */
414 if(!HasRedirection(cmd)) {
415 New(1301,argv, strlen(cmd) / 2 + 2, char*);
416 New(1302,cmd2, strlen(cmd) + 1, char);
419 for (s = cmd2; *s;) {
420 while (*s && isspace(*s))
424 while(*s && !isspace(*s))
433 status = win32_spawnvp(P_WAIT, argv[0],
434 (const char* const*)argv);
436 case EXECF_SPAWN_NOWAIT:
437 status = win32_spawnvp(P_NOWAIT, argv[0],
438 (const char* const*)argv);
441 status = win32_execvp(argv[0], (const char* const*)argv);
444 if(status != -1 || errno == 0)
452 argv[0] = shell; argv[1] = "/x"; argv[2] = "/c";
453 argv[3] = cmd; argv[4] = Nullch;
456 status = win32_spawnvp(P_WAIT, argv[0],
457 (const char* const*)argv);
459 case EXECF_SPAWN_NOWAIT:
460 status = win32_spawnvp(P_NOWAIT, argv[0],
461 (const char* const*)argv);
464 status = win32_execvp(argv[0], (const char* const*)argv);
470 warn("Can't %s \"%s\": %s",
471 (exectype == EXECF_EXEC ? "exec" : "spawn"),
472 needToTry ? shell : argv[0],
482 return do_spawn2(cmd, EXECF_SPAWN);
488 do_spawn2(cmd, EXECF_EXEC);
495 /* The idea here is to read all the directory names into a string table
496 * (separated by nulls) and when one of the other dir functions is called
497 * return the pointer to the current file name.
500 opendir(char *filename)
505 char scannamespc[PATHLEN];
506 char *scanname = scannamespc;
508 WIN32_FIND_DATA FindData;
510 /* char root[_MAX_PATH];*/
511 /* char volname[_MAX_PATH];*/
512 /* DWORD serial, maxname, flags;*/
516 /* check to see if filename is a directory */
517 if (win32_stat(filename, &sbuf) < 0 || sbuf.st_mode & S_IFDIR == 0) {
521 /* get the file system characteristics */
522 /* if(GetFullPathName(filename, MAX_PATH, root, &dummy)) {
523 * if(dummy = strchr(root, '\\'))
525 * if(GetVolumeInformation(root, volname, MAX_PATH, &serial,
526 * &maxname, &flags, 0, 0)) {
527 * downcase = !(flags & FS_CASE_IS_PRESERVED);
534 /* Get us a DIR structure */
535 Newz(1303, p, 1, DIR);
539 /* Create the search pattern */
540 strcpy(scanname, filename);
542 if(index("/\\", *(scanname + strlen(scanname) - 1)) == NULL)
543 strcat(scanname, "/*");
545 strcat(scanname, "*");
547 /* do the FindFirstFile call */
548 fh = FindFirstFile(scanname, &FindData);
549 if(fh == INVALID_HANDLE_VALUE) {
553 /* now allocate the first part of the string table for
554 * the filenames that we find.
556 idx = strlen(FindData.cFileName)+1;
557 New(1304, p->start, idx, char);
558 if(p->start == NULL) {
559 CROAK("opendir: malloc failed!\n");
561 strcpy(p->start, FindData.cFileName);
567 /* loop finding all the files that match the wildcard
568 * (which should be all of them in this directory!).
569 * the variable idx should point one past the null terminator
570 * of the previous string found.
572 while (FindNextFile(fh, &FindData)) {
573 len = strlen(FindData.cFileName);
574 /* bump the string table size by enough for the
575 * new name and it's null terminator
577 Renew(p->start, idx+len+1, char);
578 if(p->start == NULL) {
579 CROAK("opendir: malloc failed!\n");
581 strcpy(&p->start[idx], FindData.cFileName);
583 * strlwr(&p->start[idx]);
595 /* Readdir just returns the current string pointer and bumps the
596 * string pointer to the nDllExport entry.
602 static int dummy = 0;
605 /* first set up the structure to return */
606 len = strlen(dirp->curr);
607 strcpy(dirp->dirstr.d_name, dirp->curr);
608 dirp->dirstr.d_namlen = len;
611 dirp->dirstr.d_ino = dummy++;
613 /* Now set up for the nDllExport call to readdir */
614 dirp->curr += len + 1;
615 if (dirp->curr >= (dirp->start + dirp->size)) {
619 return &(dirp->dirstr);
625 /* Telldir returns the current string pointer position */
629 return (long) dirp->curr;
633 /* Seekdir moves the string pointer to a previously saved position
637 seekdir(DIR *dirp, long loc)
639 dirp->curr = (char *)loc;
642 /* Rewinddir resets the string pointer to the start */
646 dirp->curr = dirp->start;
649 /* free the memory allocated by opendir */
653 Safefree(dirp->start);
666 * Just pretend that everyone is a superuser. NT will let us know if
667 * we don\'t really have permission to do something.
670 #define ROOT_UID ((uid_t)0)
671 #define ROOT_GID ((gid_t)0)
700 return (uid == ROOT_UID ? 0 : -1);
706 return (gid == ROOT_GID ? 0 : -1);
713 kill(int pid, int sig)
715 HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
717 if (hProcess == NULL) {
718 CROAK("kill process failed!\n");
721 if (!TerminateProcess(hProcess, sig))
722 CROAK("kill process failed!\n");
723 CloseHandle(hProcess);
734 ioctl(int i, unsigned int u, char *data)
736 CROAK("ioctl not implemented!\n");
742 sleep(unsigned int t)
752 myrename(char *OldFileName, char *newname)
754 if(_access(newname, 0) != -1) { /* file exists */
757 return rename(OldFileName, newname);
762 win32_stat(const char *path, struct stat *buffer)
765 const char *p = path;
766 int l = strlen(path);
770 switch(path[l - 1]) {
773 if (path[l - 2] != ':') {
774 strncpy(t, path, l - 1);
780 res = pIOSubSystem->pfnstat(p,buffer);
783 if (S_ISDIR(buffer->st_mode))
784 buffer->st_mode |= S_IWRITE | S_IEXEC;
785 else if (S_ISREG(buffer->st_mode)) {
786 if (l >= 4 && path[l-4] == '.') {
787 const char *e = path + l - 3;
788 if (strnicmp(e,"exe",3)
789 && strnicmp(e,"bat",3)
790 && strnicmp(e,"com",3)
791 && (IsWin95() || strnicmp(e,"cmd",3)))
792 buffer->st_mode &= ~S_IEXEC;
794 buffer->st_mode |= S_IEXEC;
797 buffer->st_mode &= ~S_IEXEC;
804 #ifndef USE_WIN32_RTL_ENV
807 win32_getenv(const char *name)
809 static char *curitem = Nullch;
810 static DWORD curlen = 512;
813 New(1305,curitem,curlen,char);
814 if (!(needlen = GetEnvironmentVariable(name,curitem,curlen)))
816 while (needlen > curlen) {
817 Renew(curitem,needlen,char);
819 needlen = GetEnvironmentVariable(name,curitem,curlen);
828 mytimes(struct tms *timebuf)
831 timebuf->tms_utime = t;
832 timebuf->tms_stime = 0;
833 timebuf->tms_cutime = 0;
834 timebuf->tms_cstime = 0;
841 myalarm(unsigned int sec)
843 /* we warn the usuage of alarm function */
845 WARN("dummy function alarm called, program might not function as expected\n");
850 * redirected io subsystem for all XS modules
857 return (pIOSubSystem->pfnerrno());
863 return (pIOSubSystem->pfnenviron());
866 /* the rest are the remapped stdio routines */
870 return (pIOSubSystem->pfnstderr());
876 return (pIOSubSystem->pfnstdin());
882 return (pIOSubSystem->pfnstdout());
886 win32_ferror(FILE *fp)
888 return (pIOSubSystem->pfnferror(fp));
895 return (pIOSubSystem->pfnfeof(fp));
899 * Since the errors returned by the socket error function
900 * WSAGetLastError() are not known by the library routine strerror
901 * we have to roll our own.
904 __declspec(thread) char strerror_buffer[512];
907 win32_strerror(int e)
909 #ifndef __BORLANDC__ /* Borland intolerance */
914 if(e < 0 || e > sys_nerr) {
918 if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
919 strerror_buffer, sizeof(strerror_buffer), NULL) == 0)
920 strcpy(strerror_buffer, "Unknown Error");
922 return strerror_buffer;
924 return pIOSubSystem->pfnstrerror(e);
928 win32_fprintf(FILE *fp, const char *format, ...)
931 va_start(marker, format); /* Initialize variable arguments. */
933 return (pIOSubSystem->pfnvfprintf(fp, format, marker));
937 win32_printf(const char *format, ...)
940 va_start(marker, format); /* Initialize variable arguments. */
942 return (pIOSubSystem->pfnvprintf(format, marker));
946 win32_vfprintf(FILE *fp, const char *format, va_list args)
948 return (pIOSubSystem->pfnvfprintf(fp, format, args));
952 win32_vprintf(const char *format, va_list args)
954 return (pIOSubSystem->pfnvprintf(format, args));
958 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
960 return pIOSubSystem->pfnfread(buf, size, count, fp);
964 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
966 return pIOSubSystem->pfnfwrite(buf, size, count, fp);
970 win32_fopen(const char *filename, const char *mode)
972 if (stricmp(filename, "/dev/null")==0)
973 return pIOSubSystem->pfnfopen("NUL", mode);
974 return pIOSubSystem->pfnfopen(filename, mode);
978 win32_fdopen( int handle, const char *mode)
980 return pIOSubSystem->pfnfdopen(handle, mode);
984 win32_freopen( const char *path, const char *mode, FILE *stream)
986 if (stricmp(path, "/dev/null")==0)
987 return pIOSubSystem->pfnfreopen("NUL", mode, stream);
988 return pIOSubSystem->pfnfreopen(path, mode, stream);
992 win32_fclose(FILE *pf)
994 return pIOSubSystem->pfnfclose(pf);
998 win32_fputs(const char *s,FILE *pf)
1000 return pIOSubSystem->pfnfputs(s, pf);
1004 win32_fputc(int c,FILE *pf)
1006 return pIOSubSystem->pfnfputc(c,pf);
1010 win32_ungetc(int c,FILE *pf)
1012 return pIOSubSystem->pfnungetc(c,pf);
1016 win32_getc(FILE *pf)
1018 return pIOSubSystem->pfngetc(pf);
1022 win32_fileno(FILE *pf)
1024 return pIOSubSystem->pfnfileno(pf);
1028 win32_clearerr(FILE *pf)
1030 pIOSubSystem->pfnclearerr(pf);
1035 win32_fflush(FILE *pf)
1037 return pIOSubSystem->pfnfflush(pf);
1041 win32_ftell(FILE *pf)
1043 return pIOSubSystem->pfnftell(pf);
1047 win32_fseek(FILE *pf,long offset,int origin)
1049 return pIOSubSystem->pfnfseek(pf, offset, origin);
1053 win32_fgetpos(FILE *pf,fpos_t *p)
1055 return pIOSubSystem->pfnfgetpos(pf, p);
1059 win32_fsetpos(FILE *pf,const fpos_t *p)
1061 return pIOSubSystem->pfnfsetpos(pf, p);
1065 win32_rewind(FILE *pf)
1067 pIOSubSystem->pfnrewind(pf);
1074 return pIOSubSystem->pfntmpfile();
1080 pIOSubSystem->pfnabort();
1085 win32_fstat(int fd,struct stat *bufptr)
1087 return pIOSubSystem->pfnfstat(fd,bufptr);
1091 win32_pipe(int *pfd, unsigned int size, int mode)
1093 return pIOSubSystem->pfnpipe(pfd, size, mode);
1097 win32_popen(const char *command, const char *mode)
1099 return pIOSubSystem->pfnpopen(command, mode);
1103 win32_pclose(FILE *pf)
1105 return pIOSubSystem->pfnpclose(pf);
1109 win32_setmode(int fd, int mode)
1111 return pIOSubSystem->pfnsetmode(fd, mode);
1115 win32_lseek(int fd, long offset, int origin)
1117 return pIOSubSystem->pfnlseek(fd, offset, origin);
1123 return pIOSubSystem->pfntell(fd);
1127 win32_open(const char *path, int flag, ...)
1133 pmode = va_arg(ap, int);
1136 if (stricmp(path, "/dev/null")==0)
1137 return pIOSubSystem->pfnopen("NUL", flag, pmode);
1138 return pIOSubSystem->pfnopen(path,flag,pmode);
1144 return pIOSubSystem->pfnclose(fd);
1150 return pIOSubSystem->pfneof(fd);
1156 return pIOSubSystem->pfndup(fd);
1160 win32_dup2(int fd1,int fd2)
1162 return pIOSubSystem->pfndup2(fd1,fd2);
1166 win32_read(int fd, void *buf, unsigned int cnt)
1168 return pIOSubSystem->pfnread(fd, buf, cnt);
1172 win32_write(int fd, const void *buf, unsigned int cnt)
1174 return pIOSubSystem->pfnwrite(fd, buf, cnt);
1178 win32_mkdir(const char *dir, int mode)
1180 return pIOSubSystem->pfnmkdir(dir); /* just ignore mode */
1184 win32_rmdir(const char *dir)
1186 return pIOSubSystem->pfnrmdir(dir);
1190 win32_chdir(const char *dir)
1192 return pIOSubSystem->pfnchdir(dir);
1196 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1198 return pIOSubSystem->pfnspawnvp(mode, cmdname, argv);
1202 win32_execvp(const char *cmdname, const char *const *argv)
1204 return pIOSubSystem->pfnexecvp(cmdname, argv);
1208 stolen_open_osfhandle(long handle, int flags)
1210 return pIOSubSystem->pfn_open_osfhandle(handle, flags);
1214 stolen_get_osfhandle(int fd)
1216 return pIOSubSystem->pfn_get_osfhandle(fd);
1224 win32_flock(int fd, int oper)
1227 croak("flock() unimplemented on this platform");
1230 return pIOSubSystem->pfnflock(fd, oper);
1237 SV *sv = sv_newmortal();
1238 /* Make one call with zero size - return value is required size */
1239 DWORD len = GetCurrentDirectory((DWORD)0,NULL);
1240 SvUPGRADE(sv,SVt_PV);
1242 SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
1245 * then it worked, set PV valid,
1246 * else leave it 'undef'
1260 croak("usage: Win32::SetCurrentDirectory($cwd)");
1261 if (SetCurrentDirectory(SvPV(ST(0),na)))
1268 XS(w32_GetNextAvailDrive)
1272 char root[] = "_:\\";
1275 if (GetDriveType(root) == 1) {
1284 XS(w32_GetLastError)
1287 XSRETURN_IV(GetLastError());
1295 DWORD size = sizeof(name);
1296 if (GetUserName(name,&size)) {
1297 /* size includes NULL */
1298 ST(0) = sv_2mortal(newSVpv(name,size-1));
1308 char name[MAX_COMPUTERNAME_LENGTH+1];
1309 DWORD size = sizeof(name);
1310 if (GetComputerName(name,&size)) {
1311 /* size does NOT include NULL :-( */
1312 ST(0) = sv_2mortal(newSVpv(name,size));
1324 DWORD size = sizeof(name);
1325 if (GetUserName(name,&size)) {
1327 DWORD sidlen = sizeof(sid);
1329 DWORD dnamelen = sizeof(dname);
1331 if (LookupAccountName(NULL, name, &sid, &sidlen,
1332 dname, &dnamelen, &snu)) {
1333 XSRETURN_PV(dname); /* all that for this */
1344 DWORD flags, filecomplen;
1345 if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
1346 &flags, fsname, sizeof(fsname))) {
1347 if (GIMME == G_ARRAY) {
1348 XPUSHs(sv_2mortal(newSVpv(fsname,0)));
1349 XPUSHs(sv_2mortal(newSViv(flags)));
1350 XPUSHs(sv_2mortal(newSViv(filecomplen)));
1354 XSRETURN_PV(fsname);
1360 XS(w32_GetOSVersion)
1363 OSVERSIONINFO osver;
1365 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1366 if (GetVersionEx(&osver)) {
1367 XPUSHs(newSVpv(osver.szCSDVersion, 0));
1368 XPUSHs(newSViv(osver.dwMajorVersion));
1369 XPUSHs(newSViv(osver.dwMinorVersion));
1370 XPUSHs(newSViv(osver.dwBuildNumber));
1371 XPUSHs(newSViv(osver.dwPlatformId));
1382 XSRETURN_IV(IsWinNT());
1389 XSRETURN_IV(IsWin95());
1393 XS(w32_FormatMessage)
1400 croak("usage: Win32::FormatMessage($errno)");
1402 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
1403 &source, SvIV(ST(0)), 0,
1404 msgbuf, sizeof(msgbuf)-1, NULL))
1405 XSRETURN_PV(msgbuf);
1415 PROCESS_INFORMATION stProcInfo;
1416 STARTUPINFO stStartInfo;
1417 BOOL bSuccess = FALSE;
1420 croak("usage: Win32::Spawn($cmdName, $args, $PID)");
1422 cmd = SvPV(ST(0),na);
1423 args = SvPV(ST(1), na);
1425 memset(&stStartInfo, 0, sizeof(stStartInfo)); /* Clear the block */
1426 stStartInfo.cb = sizeof(stStartInfo); /* Set the structure size */
1427 stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
1428 stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
1431 cmd, /* Image path */
1432 args, /* Arguments for command line */
1433 NULL, /* Default process security */
1434 NULL, /* Default thread security */
1435 FALSE, /* Must be TRUE to use std handles */
1436 NORMAL_PRIORITY_CLASS, /* No special scheduling */
1437 NULL, /* Inherit our environment block */
1438 NULL, /* Inherit our currrent directory */
1439 &stStartInfo, /* -> Startup info */
1440 &stProcInfo)) /* <- Process info (if OK) */
1442 CloseHandle(stProcInfo.hThread);/* library source code does this. */
1443 sv_setiv(ST(2), stProcInfo.dwProcessId);
1446 XSRETURN_IV(bSuccess);
1450 XS(w32_GetTickCount)
1453 XSRETURN_IV(GetTickCount());
1457 XS(w32_GetShortPathName)
1463 croak("usage: Win32::GetShortPathName($longPathName)");
1465 shortpath = sv_mortalcopy(ST(0));
1466 SvUPGRADE(shortpath, SVt_PV);
1467 /* src == target is allowed */
1468 if (GetShortPathName(SvPVX(shortpath), SvPVX(shortpath), SvCUR(shortpath)))
1478 char *file = __FILE__;
1481 /* XXX should be removed after checking with Nick */
1482 newXS("Win32::GetCurrentDirectory", w32_GetCwd, file);
1484 /* these names are Activeware compatible */
1485 newXS("Win32::GetCwd", w32_GetCwd, file);
1486 newXS("Win32::SetCwd", w32_SetCwd, file);
1487 newXS("Win32::GetNextAvailDrive", w32_GetNextAvailDrive, file);
1488 newXS("Win32::GetLastError", w32_GetLastError, file);
1489 newXS("Win32::LoginName", w32_LoginName, file);
1490 newXS("Win32::NodeName", w32_NodeName, file);
1491 newXS("Win32::DomainName", w32_DomainName, file);
1492 newXS("Win32::FsType", w32_FsType, file);
1493 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
1494 newXS("Win32::IsWinNT", w32_IsWinNT, file);
1495 newXS("Win32::IsWin95", w32_IsWin95, file);
1496 newXS("Win32::FormatMessage", w32_FormatMessage, file);
1497 newXS("Win32::Spawn", w32_Spawn, file);
1498 newXS("Win32::GetTickCount", w32_GetTickCount, file);
1499 newXS("Win32::GetShortPathName", w32_GetShortPathName, file);
1501 /* XXX Bloat Alert! The following Activeware preloads really
1502 * ought to be part of Win32::Sys::*, so they're not included
1505 /* LookupAccountName
1507 * InitiateSystemShutdown
1508 * AbortSystemShutdown
1509 * ExpandEnvrironmentStrings
1514 Perl_win32_init(int *argcp, char ***argvp)
1516 /* Disable floating point errors, Perl will trap the ones we
1517 * care about. VC++ RTL defaults to switching these off
1518 * already, but the Borland RTL doesn't. Since we don't
1519 * want to be at the vendor's whim on the default, we set
1520 * it explicitly here.
1522 _control87(MCW_EM, MCW_EM);