1 /* WINCE.C - stuff for Windows CE
3 * Time-stamp: <26/10/01 15:25:20 keuchel@keuchelnt>
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
9 #define WIN32_LEAN_AND_MEAN
10 #define WIN32IO_IS_STDIO
14 #define PERLIO_NOT_STDIO 0
16 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
27 #define PERL_NO_GET_CONTEXT
38 #include "celib_defs.h"
41 #include "cewin32_defs.h"
42 #include "cecrt_defs.h"
44 #define GetCurrentDirectoryW XCEGetCurrentDirectoryW
47 #include "stdio-palmsize.h"
52 #define EXECF_SPAWN_NOWAIT 3
54 #if defined(PERL_IMPLICIT_SYS)
55 # undef win32_get_privlib
56 # define win32_get_privlib g_win32_get_privlib
57 # undef win32_get_sitelib
58 # define win32_get_sitelib g_win32_get_sitelib
59 # undef win32_get_vendorlib
60 # define win32_get_vendorlib g_win32_get_vendorlib
62 # define do_spawn g_do_spawn
64 # define getlogin g_getlogin
67 static void get_shell(void);
68 static long tokenize(const char *str, char **dest, char ***destv);
69 static int do_spawn2(pTHX_ char *cmd, int exectype);
70 static BOOL has_shell_metachars(char *ptr);
71 static long filetime_to_clock(PFILETIME ft);
72 static BOOL filetime_from_time(PFILETIME ft, time_t t);
73 static char * get_emd_part(SV **leading, char *trailing, ...);
74 static void remove_dead_process(long deceased);
75 static long find_pid(int pid);
76 static char * qualified_path(const char *cmd);
77 static char * win32_get_xlib(const char *pl, const char *xlib,
81 static void remove_dead_pseudo_process(long child);
82 static long find_pseudo_pid(int pid);
85 int _fmode = O_TEXT; /* celib do not provide _fmode, so we define it here */
88 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
89 char w32_module_name[MAX_PATH+1];
92 static DWORD w32_platform = (DWORD)-1;
97 return (win32_os_id() == VER_PLATFORM_WIN32_WINDOWS);
103 return (win32_os_id() == VER_PLATFORM_WIN32_NT);
109 return (win32_os_id() == VER_PLATFORM_WIN32_CE);
113 set_w32_module_name(void)
116 XCEGetModuleFileNameA((HMODULE)((w32_perldll_handle == INVALID_HANDLE_VALUE)
117 ? XCEGetModuleHandleA(NULL)
118 : w32_perldll_handle),
119 w32_module_name, sizeof(w32_module_name));
121 /* normalize to forward slashes */
122 ptr = w32_module_name;
130 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
132 get_regstr_from(HKEY hkey, const char *valuename, SV **svp)
134 /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
137 const char *subkey = "Software\\Perl";
141 retval = XCERegOpenKeyExA(hkey, subkey, 0, KEY_READ, &handle);
142 if (retval == ERROR_SUCCESS) {
144 retval = XCERegQueryValueExA(handle, valuename, 0, &type, NULL, &datalen);
145 if (retval == ERROR_SUCCESS && type == REG_SZ) {
148 *svp = sv_2mortal(newSVpvn("",0));
149 SvGROW(*svp, datalen);
150 retval = XCERegQueryValueExA(handle, valuename, 0, NULL,
151 (PBYTE)SvPVX(*svp), &datalen);
152 if (retval == ERROR_SUCCESS) {
154 SvCUR_set(*svp,datalen-1);
162 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
164 get_regstr(const char *valuename, SV **svp)
166 char *str = get_regstr_from(HKEY_CURRENT_USER, valuename, svp);
168 str = get_regstr_from(HKEY_LOCAL_MACHINE, valuename, svp);
172 /* *prev_pathp (if non-NULL) is expected to be POK (valid allocated SvPVX(sv)) */
174 get_emd_part(SV **prev_pathp, char *trailing_path, ...)
178 char mod_name[MAX_PATH+1];
182 int oldsize, newsize;
185 va_start(ap, trailing_path);
186 strip = va_arg(ap, char *);
188 sprintf(base, "%d.%d", (int)PERL_REVISION, (int)PERL_VERSION);
189 baselen = strlen(base);
191 if (!*w32_module_name) {
192 set_w32_module_name();
194 strcpy(mod_name, w32_module_name);
195 ptr = strrchr(mod_name, '/');
196 while (ptr && strip) {
197 /* look for directories to skip back */
200 ptr = strrchr(mod_name, '/');
201 /* avoid stripping component if there is no slash,
202 * or it doesn't match ... */
203 if (!ptr || stricmp(ptr+1, strip) != 0) {
204 /* ... but not if component matches m|5\.$patchlevel.*| */
205 if (!ptr || !(*strip == '5' && *(ptr+1) == '5'
206 && strncmp(strip, base, baselen) == 0
207 && strncmp(ptr+1, base, baselen) == 0))
213 strip = va_arg(ap, char *);
221 strcpy(++ptr, trailing_path);
223 /* only add directory if it exists */
224 if (XCEGetFileAttributesA(mod_name) != (DWORD) -1) {
225 /* directory exists */
228 *prev_pathp = sv_2mortal(newSVpvn("",0));
229 sv_catpvn(*prev_pathp, ";", 1);
230 sv_catpv(*prev_pathp, mod_name);
231 return SvPVX(*prev_pathp);
238 win32_get_privlib(const char *pl)
241 char *stdlib = "lib";
242 char buffer[MAX_PATH+1];
245 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
246 sprintf(buffer, "%s-%s", stdlib, pl);
247 if (!get_regstr(buffer, &sv))
248 (void)get_regstr(stdlib, &sv);
250 /* $stdlib .= ";$EMD/../../lib" */
251 return get_emd_part(&sv, stdlib, ARCHNAME, "bin", NULL);
255 win32_get_xlib(const char *pl, const char *xlib, const char *libname)
259 char pathstr[MAX_PATH+1];
265 /* $HKCU{"$xlib-$]"} || $HKLM{"$xlib-$]"} . ---; */
266 sprintf(regstr, "%s-%s", xlib, pl);
267 (void)get_regstr(regstr, &sv1);
270 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/$]/lib"; */
271 sprintf(pathstr, "%s/%s/lib", libname, pl);
272 (void)get_emd_part(&sv1, pathstr, ARCHNAME, "bin", pl, NULL);
274 /* $HKCU{$xlib} || $HKLM{$xlib} . ---; */
275 (void)get_regstr(xlib, &sv2);
278 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/lib"; */
279 sprintf(pathstr, "%s/lib", libname);
280 (void)get_emd_part(&sv2, pathstr, ARCHNAME, "bin", pl, NULL);
289 sv_catpvn(sv1, ";", 1);
296 win32_get_sitelib(const char *pl)
298 return win32_get_xlib(pl, "sitelib", "site");
301 #ifndef PERL_VENDORLIB_NAME
302 # define PERL_VENDORLIB_NAME "vendor"
306 win32_get_vendorlib(const char *pl)
308 return win32_get_xlib(pl, "vendorlib", PERL_VENDORLIB_NAME);
312 has_shell_metachars(char *ptr)
318 * Scan string looking for redirection (< or >) or pipe
319 * characters (|) that are not in a quoted string.
320 * Shell variable interpolation (%VAR%) can also happen inside strings.
352 #if !defined(PERL_IMPLICIT_SYS)
353 /* since the current process environment is being updated in util.c
354 * the library functions will get the correct environment
357 Perl_my_popen(pTHX_ const char *cmd, const char *mode)
359 printf("popen(%s)\n", cmd);
361 Perl_croak(aTHX_ PL_no_func, "popen");
366 Perl_my_pclose(pTHX_ PerlIO *fp)
368 Perl_croak(aTHX_ PL_no_func, "pclose");
373 DllExport unsigned long
376 static OSVERSIONINFOA osver;
378 if (osver.dwPlatformId != w32_platform) {
379 memset(&osver, 0, sizeof(OSVERSIONINFOA));
380 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
381 XCEGetVersionExA(&osver);
382 w32_platform = osver.dwPlatformId;
384 return (unsigned long)w32_platform;
394 return -((int)w32_pseudo_id);
400 /* Tokenize a string. Words are null-separated, and the list
401 * ends with a doubled null. Any character (except null and
402 * including backslash) may be escaped by preceding it with a
403 * backslash (the backslash will be stripped).
404 * Returns number of words in result buffer.
407 tokenize(const char *str, char **dest, char ***destv)
409 char *retstart = NULL;
410 char **retvstart = 0;
414 int slen = strlen(str);
416 register char **retv;
417 Newx(ret, slen+2, char);
418 Newx(retv, (slen+3)/2, char*);
426 if (*ret == '\\' && *str)
428 else if (*ret == ' ') {
444 retvstart[items] = NULL;
454 win32_pipe(int *pfd, unsigned int size, int mode)
457 Perl_croak(aTHX_ PL_no_func, "pipe");
462 win32_times(struct tms *timebuf)
465 Perl_croak(aTHX_ PL_no_func, "times");
470 win32_signal(int sig, Sighandler_t subcode)
472 return xcesignal(sig, subcode);
479 if (!w32_perlshell_tokens) {
480 /* we don't use COMSPEC here for two reasons:
481 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
482 * uncontrolled unportability of the ensuing scripts.
483 * 2. PERL5SHELL could be set to a shell that may not be fit for
484 * interactive use (which is what most programs look in COMSPEC
487 const char* defaultshell = (IsWinNT()
488 ? "cmd.exe /x/d/c" : "command.com /c");
489 const char *usershell = PerlEnv_getenv("PERL5SHELL");
490 w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
491 &w32_perlshell_tokens,
497 Perl_do_aspawn(pTHX_ SV *really, SV **mark, SV **sp)
499 PERL_ARGS_ASSERT_DO_ASPAWN;
501 Perl_croak(aTHX_ PL_no_func, "aspawn");
505 /* returns pointer to the next unquoted space or the end of the string */
507 find_next_space(const char *s)
509 bool in_quotes = FALSE;
511 /* ignore doubled backslashes, or backslash+quote */
512 if (*s == '\\' && (s[1] == '\\' || s[1] == '"')) {
515 /* keep track of when we're within quotes */
516 else if (*s == '"') {
518 in_quotes = !in_quotes;
520 /* break it up only at spaces that aren't in quotes */
521 else if (!in_quotes && isSPACE(*s))
531 do_spawn2(pTHX_ char *cmd, int exectype)
537 BOOL needToTry = TRUE;
540 /* Save an extra exec if possible. See if there are shell
541 * metacharacters in it */
542 if (!has_shell_metachars(cmd)) {
543 Newx(argv, strlen(cmd) / 2 + 2, char*);
544 Newx(cmd2, strlen(cmd) + 1, char);
547 for (s = cmd2; *s;) {
548 while (*s && isSPACE(*s))
552 s = find_next_space(s);
560 status = win32_spawnvp(P_WAIT, argv[0],
561 (const char* const*)argv);
563 case EXECF_SPAWN_NOWAIT:
564 status = win32_spawnvp(P_NOWAIT, argv[0],
565 (const char* const*)argv);
568 status = win32_execvp(argv[0], (const char* const*)argv);
571 if (status != -1 || errno == 0)
581 Newx(argv, w32_perlshell_items + 2, char*);
582 while (++i < w32_perlshell_items)
583 argv[i] = w32_perlshell_vec[i];
588 status = win32_spawnvp(P_WAIT, argv[0],
589 (const char* const*)argv);
591 case EXECF_SPAWN_NOWAIT:
592 status = win32_spawnvp(P_NOWAIT, argv[0],
593 (const char* const*)argv);
596 status = win32_execvp(argv[0], (const char* const*)argv);
602 if (exectype == EXECF_SPAWN_NOWAIT) {
604 PL_statusvalue = -1; /* >16bits hint for pp_system() */
608 if (ckWARN(WARN_EXEC))
609 Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't %s \"%s\": %s",
610 (exectype == EXECF_EXEC ? "exec" : "spawn"),
611 cmd, strerror(errno));
616 PL_statusvalue = status;
622 Perl_do_spawn(pTHX_ char *cmd)
624 PERL_ARGS_ASSERT_DO_SPAWN;
626 return do_spawn2(aTHX_ cmd, EXECF_SPAWN);
630 Perl_do_spawn_nowait(pTHX_ char *cmd)
632 PERL_ARGS_ASSERT_DO_SPAWN_NOWAIT;
634 return do_spawn2(aTHX_ cmd, EXECF_SPAWN_NOWAIT);
638 Perl_do_exec(pTHX_ const char *cmd)
640 PERL_ARGS_ASSERT_DO_EXEC;
642 do_spawn2(aTHX_ cmd, EXECF_EXEC);
646 /* The idea here is to read all the directory names into a string table
647 * (separated by nulls) and when one of the other dir functions is called
648 * return the pointer to the current file name.
651 win32_opendir(const char *filename)
657 char scanname[MAX_PATH+3];
659 WIN32_FIND_DATAA aFindData;
660 WIN32_FIND_DATAW wFindData;
662 char buffer[MAX_PATH*2];
663 WCHAR wbuffer[MAX_PATH+1];
666 len = strlen(filename);
670 /* check to see if filename is a directory */
671 if (win32_stat(filename, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode))
674 /* Get us a DIR structure */
677 /* Create the search pattern */
678 strcpy(scanname, filename);
680 /* bare drive name means look in cwd for drive */
681 if (len == 2 && isALPHA(scanname[0]) && scanname[1] == ':') {
682 scanname[len++] = '.';
683 scanname[len++] = '/';
685 else if (scanname[len-1] != '/' && scanname[len-1] != '\\') {
686 scanname[len++] = '/';
688 scanname[len++] = '*';
689 scanname[len] = '\0';
691 /* do the FindFirstFile call */
692 fh = FindFirstFile(PerlDir_mapA(scanname), &aFindData);
694 if (fh == INVALID_HANDLE_VALUE) {
695 DWORD err = GetLastError();
696 /* FindFirstFile() fails on empty drives! */
698 case ERROR_FILE_NOT_FOUND:
700 case ERROR_NO_MORE_FILES:
701 case ERROR_PATH_NOT_FOUND:
704 case ERROR_NOT_ENOUGH_MEMORY:
715 /* now allocate the first part of the string table for
716 * the filenames that we find.
718 ptr = aFindData.cFileName;
724 Newx(dirp->start, dirp->size, char);
725 strcpy(dirp->start, ptr);
727 dirp->end = dirp->curr = dirp->start;
733 /* Readdir just returns the current string pointer and bumps the
734 * string pointer to the nDllExport entry.
736 DllExport struct direct *
737 win32_readdir(DIR *dirp)
742 /* first set up the structure to return */
743 len = strlen(dirp->curr);
744 strcpy(dirp->dirstr.d_name, dirp->curr);
745 dirp->dirstr.d_namlen = len;
748 dirp->dirstr.d_ino = dirp->curr - dirp->start;
750 /* Now set up for the next call to readdir */
751 dirp->curr += len + 1;
752 if (dirp->curr >= dirp->end) {
756 WIN32_FIND_DATAW wFindData;
757 WIN32_FIND_DATAA aFindData;
758 char buffer[MAX_PATH*2];
760 /* finding the next file that matches the wildcard
761 * (which should be all of them in this directory!).
763 res = FindNextFile(dirp->handle, &aFindData);
765 ptr = aFindData.cFileName;
767 long endpos = dirp->end - dirp->start;
768 long newsize = endpos + strlen(ptr) + 1;
769 /* bump the string table size by enough for the
770 * new name and its null terminator */
771 while (newsize > dirp->size) {
772 long curpos = dirp->curr - dirp->start;
774 Renew(dirp->start, dirp->size, char);
775 dirp->curr = dirp->start + curpos;
777 strcpy(dirp->start + endpos, ptr);
778 dirp->end = dirp->start + newsize;
784 return &(dirp->dirstr);
790 /* Telldir returns the current string pointer position */
792 win32_telldir(DIR *dirp)
794 return (dirp->curr - dirp->start);
798 /* Seekdir moves the string pointer to a previously saved position
799 * (returned by telldir).
802 win32_seekdir(DIR *dirp, long loc)
804 dirp->curr = dirp->start + loc;
807 /* Rewinddir resets the string pointer to the start */
809 win32_rewinddir(DIR *dirp)
811 dirp->curr = dirp->start;
814 /* free the memory allocated by opendir */
816 win32_closedir(DIR *dirp)
819 if (dirp->handle != INVALID_HANDLE_VALUE)
820 FindClose(dirp->handle);
821 Safefree(dirp->start);
827 /////!!!!!!!!!!! return here and do right stuff!!!!
830 win32_opendir(const char *filename)
832 return opendir(filename);
835 DllExport struct direct *
836 win32_readdir(DIR *dirp)
838 return readdir(dirp);
842 win32_telldir(DIR *dirp)
845 Perl_croak(aTHX_ PL_no_func, "telldir");
850 win32_seekdir(DIR *dirp, long loc)
853 Perl_croak(aTHX_ PL_no_func, "seekdir");
857 win32_rewinddir(DIR *dirp)
860 Perl_croak(aTHX_ PL_no_func, "rewinddir");
864 win32_closedir(DIR *dirp)
872 win32_kill(int pid, int sig)
875 Perl_croak(aTHX_ PL_no_func, "kill");
880 win32_stat(const char *path, struct stat *sbuf)
882 return xcestat(path, sbuf);
886 win32_longpath(char *path)
891 #ifndef USE_WIN32_RTL_ENV
894 win32_getenv(const char *name)
896 return xcegetenv(name);
900 win32_putenv(const char *name)
902 return xceputenv(name);
908 filetime_to_clock(PFILETIME ft)
910 __int64 qw = ft->dwHighDateTime;
912 qw |= ft->dwLowDateTime;
913 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
917 /* fix utime() so it works on directories in NT */
919 filetime_from_time(PFILETIME pFileTime, time_t Time)
921 struct tm *pTM = localtime(&Time);
922 SYSTEMTIME SystemTime;
928 SystemTime.wYear = pTM->tm_year + 1900;
929 SystemTime.wMonth = pTM->tm_mon + 1;
930 SystemTime.wDay = pTM->tm_mday;
931 SystemTime.wHour = pTM->tm_hour;
932 SystemTime.wMinute = pTM->tm_min;
933 SystemTime.wSecond = pTM->tm_sec;
934 SystemTime.wMilliseconds = 0;
936 return SystemTimeToFileTime(&SystemTime, &LocalTime) &&
937 LocalFileTimeToFileTime(&LocalTime, pFileTime);
941 win32_unlink(const char *filename)
943 return xceunlink(filename);
947 win32_utime(const char *filename, struct utimbuf *times)
949 return xceutime(filename, (struct _utimbuf *) times);
953 win32_gettimeofday(struct timeval *tp, void *not_used)
955 return xcegettimeofday(tp,not_used);
959 win32_uname(struct utsname *name)
962 STRLEN nodemax = sizeof(name->nodename)-1;
963 OSVERSIONINFOA osver;
965 memset(&osver, 0, sizeof(OSVERSIONINFOA));
966 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
967 if (XCEGetVersionExA(&osver)) {
969 switch (osver.dwPlatformId) {
970 case VER_PLATFORM_WIN32_CE:
971 strcpy(name->sysname, "Windows CE");
973 case VER_PLATFORM_WIN32_WINDOWS:
974 strcpy(name->sysname, "Windows");
976 case VER_PLATFORM_WIN32_NT:
977 strcpy(name->sysname, "Windows NT");
979 case VER_PLATFORM_WIN32s:
980 strcpy(name->sysname, "Win32s");
983 strcpy(name->sysname, "Win32 Unknown");
988 sprintf(name->release, "%d.%d",
989 osver.dwMajorVersion, osver.dwMinorVersion);
992 sprintf(name->version, "Build %d",
993 osver.dwPlatformId == VER_PLATFORM_WIN32_NT
994 ? osver.dwBuildNumber : (osver.dwBuildNumber & 0xffff));
995 if (osver.szCSDVersion[0]) {
996 char *buf = name->version + strlen(name->version);
997 sprintf(buf, " (%s)", osver.szCSDVersion);
1001 *name->sysname = '\0';
1002 *name->version = '\0';
1003 *name->release = '\0';
1007 hep = win32_gethostbyname("localhost");
1009 STRLEN len = strlen(hep->h_name);
1010 if (len <= nodemax) {
1011 strcpy(name->nodename, hep->h_name);
1014 strncpy(name->nodename, hep->h_name, nodemax);
1015 name->nodename[nodemax] = '\0';
1020 if (!XCEGetComputerNameA(name->nodename, &sz))
1021 *name->nodename = '\0';
1024 /* machine (architecture) */
1028 GetSystemInfo(&info);
1030 switch (info.wProcessorArchitecture) {
1031 case PROCESSOR_ARCHITECTURE_INTEL:
1032 arch = "x86"; break;
1033 case PROCESSOR_ARCHITECTURE_MIPS:
1034 arch = "mips"; break;
1035 case PROCESSOR_ARCHITECTURE_ALPHA:
1036 arch = "alpha"; break;
1037 case PROCESSOR_ARCHITECTURE_PPC:
1038 arch = "ppc"; break;
1039 case PROCESSOR_ARCHITECTURE_ARM:
1040 arch = "arm"; break;
1041 case PROCESSOR_HITACHI_SH3:
1042 arch = "sh3"; break;
1043 case PROCESSOR_SHx_SH3:
1044 arch = "sh3"; break;
1047 arch = "unknown"; break;
1049 strcpy(name->machine, arch);
1054 /* Timing related stuff */
1057 do_raise(pTHX_ int sig)
1059 if (sig < SIG_SIZE) {
1060 Sighandler_t handler = w32_sighandler[sig];
1061 if (handler == SIG_IGN) {
1064 else if (handler != SIG_DFL) {
1069 /* Choose correct default behaviour */
1085 /* Tell caller to exit thread/process as approriate */
1090 sig_terminate(pTHX_ int sig)
1092 Perl_warn(aTHX_ "Terminating on signal SIG%s(%d)\n",PL_sig_name[sig], sig);
1093 /* exit() seems to be safe, my_exit() or die() is a problem in ^C
1100 win32_async_check(pTHX)
1104 /* Passing PeekMessage -1 as HWND (2nd arg) only get PostThreadMessage() messages
1105 * and ignores window messages - should co-exist better with windows apps e.g. Tk
1107 while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE|PM_NOYIELD)) {
1109 switch(msg.message) {
1112 /* Perhaps some other messages could map to signals ? ... */
1115 /* Treat WM_QUIT like SIGHUP? */
1121 /* We use WM_USER to fake kill() with other signals */
1125 if (do_raise(aTHX_ sig)) {
1126 sig_terminate(aTHX_ sig);
1132 /* alarm() is a one-shot but SetTimer() repeats so kill it */
1134 KillTimer(NULL,w32_timerid);
1137 /* Now fake a call to signal handler */
1138 if (do_raise(aTHX_ 14)) {
1139 sig_terminate(aTHX_ 14);
1144 /* Otherwise do normal Win32 thing - in case it is useful */
1146 TranslateMessage(&msg);
1147 DispatchMessage(&msg);
1154 /* Above or other stuff may have set a signal flag */
1155 if (PL_sig_pending) {
1161 /* This function will not return until the timeout has elapsed, or until
1162 * one of the handles is ready. */
1164 win32_msgwait(pTHX_ DWORD count, LPHANDLE handles, DWORD timeout, LPDWORD resultp)
1166 /* We may need several goes at this - so compute when we stop */
1168 if (timeout != INFINITE) {
1169 ticks = GetTickCount();
1173 DWORD result = MsgWaitForMultipleObjects(count,handles,FALSE,timeout-ticks, QS_ALLEVENTS);
1176 if (result == WAIT_TIMEOUT) {
1177 /* Ran out of time - explicit return of zero to avoid -ve if we
1178 have scheduling issues
1182 if (timeout != INFINITE) {
1183 ticks = GetTickCount();
1185 if (result == WAIT_OBJECT_0 + count) {
1186 /* Message has arrived - check it */
1187 (void)win32_async_check(aTHX);
1190 /* Not timeout or message - one of handles is ready */
1194 /* compute time left to wait */
1195 ticks = timeout - ticks;
1196 /* If we are past the end say zero */
1197 return (ticks > 0) ? ticks : 0;
1200 static UINT timerid = 0;
1202 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
1205 KillTimer(NULL,timerid);
1210 DllExport unsigned int
1211 win32_sleep(unsigned int t)
1216 DllExport unsigned int
1217 win32_alarm(unsigned int sec)
1220 * the 'obvious' implentation is SetTimer() with a callback
1221 * which does whatever receiving SIGALRM would do
1222 * we cannot use SIGALRM even via raise() as it is not
1223 * one of the supported codes in <signal.h>
1225 * Snag is unless something is looking at the message queue
1226 * nothing happens :-(
1231 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
1233 Perl_croak_nocontext("Cannot set timer");
1239 KillTimer(NULL,timerid);
1246 #ifdef HAVE_DES_FCRYPT
1247 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
1251 win32_crypt(const char *txt, const char *salt)
1254 #ifdef HAVE_DES_FCRYPT
1256 return des_fcrypt(txt, salt, w32_crypt_buffer);
1258 Perl_croak(aTHX_ "The crypt() function is unimplemented due to excessive paranoia.");
1265 * redirected io subsystem for all XS modules
1278 return (&(environ));
1281 /* the rest are the remapped stdio routines */
1288 char *g_getlogin() {
1289 return "no-getlogin";
1305 win32_ferror(FILE *fp)
1307 return (ferror(fp));
1312 win32_feof(FILE *fp)
1318 * Since the errors returned by the socket error function
1319 * WSAGetLastError() are not known by the library routine strerror
1320 * we have to roll our own.
1324 win32_strerror(int e)
1326 return xcestrerror(e);
1330 win32_str_os_error(void *sv, DWORD dwErr)
1334 sv_setpvn((SV*)sv, "Error", 5);
1339 win32_fprintf(FILE *fp, const char *format, ...)
1342 va_start(marker, format); /* Initialize variable arguments. */
1344 return (vfprintf(fp, format, marker));
1348 win32_printf(const char *format, ...)
1351 va_start(marker, format); /* Initialize variable arguments. */
1353 return (vprintf(format, marker));
1357 win32_vfprintf(FILE *fp, const char *format, va_list args)
1359 return (vfprintf(fp, format, args));
1363 win32_vprintf(const char *format, va_list args)
1365 return (vprintf(format, args));
1369 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
1371 return fread(buf, size, count, fp);
1375 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
1377 return fwrite(buf, size, count, fp);
1381 win32_fopen(const char *filename, const char *mode)
1383 return xcefopen(filename, mode);
1387 win32_fdopen(int handle, const char *mode)
1389 return palm_fdopen(handle, mode);
1393 win32_freopen(const char *path, const char *mode, FILE *stream)
1395 return xcefreopen(path, mode, stream);
1399 win32_fclose(FILE *pf)
1401 return xcefclose(pf);
1405 win32_fputs(const char *s,FILE *pf)
1407 return fputs(s, pf);
1411 win32_fputc(int c,FILE *pf)
1417 win32_ungetc(int c,FILE *pf)
1419 return ungetc(c,pf);
1423 win32_getc(FILE *pf)
1429 win32_fileno(FILE *pf)
1431 return palm_fileno(pf);
1435 win32_clearerr(FILE *pf)
1442 win32_fflush(FILE *pf)
1448 win32_ftell(FILE *pf)
1454 win32_fseek(FILE *pf, Off_t offset,int origin)
1456 return fseek(pf, offset, origin);
1459 /* fpos_t seems to be int64 on hpc pro! Really stupid. */
1460 /* But maybe someday there will be such large disks in a hpc... */
1462 win32_fgetpos(FILE *pf, fpos_t *p)
1464 return fgetpos(pf, p);
1468 win32_fsetpos(FILE *pf, const fpos_t *p)
1470 return fsetpos(pf, p);
1474 win32_rewind(FILE *pf)
1476 fseek(pf, 0, SEEK_SET);
1484 char prefix[MAX_PATH+1];
1485 char filename[MAX_PATH+1];
1486 DWORD len = GetTempPath(MAX_PATH, prefix);
1487 if (len && len < MAX_PATH) {
1488 if (GetTempFileName(prefix, "plx", 0, filename)) {
1489 HANDLE fh = CreateFile(filename,
1490 DELETE | GENERIC_READ | GENERIC_WRITE,
1494 FILE_ATTRIBUTE_NORMAL
1495 | FILE_FLAG_DELETE_ON_CLOSE,
1497 if (fh != INVALID_HANDLE_VALUE) {
1498 int fd = win32_open_osfhandle((intptr_t)fh, 0);
1500 #if defined(__BORLANDC__)
1501 setmode(fd,O_BINARY);
1503 DEBUG_p(PerlIO_printf(Perl_debug_log,
1504 "Created tmpfile=%s\n",filename));
1516 int fd = win32_tmpfd();
1518 return win32_fdopen(fd, "w+b");
1531 win32_fstat(int fd, struct stat *sbufptr)
1533 return xcefstat(fd, sbufptr);
1537 win32_link(const char *oldname, const char *newname)
1540 Perl_croak(aTHX_ PL_no_func, "link");
1546 win32_rename(const char *oname, const char *newname)
1548 return xcerename(oname, newname);
1552 win32_setmode(int fd, int mode)
1554 /* currently 'celib' seem to have this function in src, but not
1555 * exported. When it will be, we'll uncomment following line.
1557 /* return xcesetmode(fd, mode); */
1562 win32_chsize(int fd, Off_t size)
1564 return chsize(fd, size);
1568 win32_lseek(int fd, Off_t offset, int origin)
1570 return xcelseek(fd, offset, origin);
1576 return xcelseek(fd, 0, SEEK_CUR);
1580 win32_open(const char *path, int flag, ...)
1586 pmode = va_arg(ap, int);
1589 return xceopen(path, flag, pmode);
1595 return xceclose(fd);
1602 Perl_croak(aTHX_ PL_no_func, "eof");
1609 return xcedup(fd); /* from celib/ceio.c; requires some more work on it */
1613 win32_dup2(int fd1,int fd2)
1615 return xcedup2(fd1,fd2);
1619 win32_read(int fd, void *buf, unsigned int cnt)
1621 return xceread(fd, buf, cnt);
1625 win32_write(int fd, const void *buf, unsigned int cnt)
1627 return xcewrite(fd, (void *) buf, cnt);
1631 win32_mkdir(const char *dir, int mode)
1633 return xcemkdir(dir);
1637 win32_rmdir(const char *dir)
1639 return xcermdir(dir);
1643 win32_chdir(const char *dir)
1645 return xcechdir(dir);
1649 win32_access(const char *path, int mode)
1651 return xceaccess(path, mode);
1655 win32_chmod(const char *path, int mode)
1657 return xcechmod(path, mode);
1661 create_command_line(char *cname, STRLEN clen, const char * const *args)
1668 bool bat_file = FALSE;
1669 bool cmd_shell = FALSE;
1670 bool dumb_shell = FALSE;
1671 bool extra_quotes = FALSE;
1672 bool quote_next = FALSE;
1675 cname = (char*)args[0];
1677 /* The NT cmd.exe shell has the following peculiarity that needs to be
1678 * worked around. It strips a leading and trailing dquote when any
1679 * of the following is true:
1680 * 1. the /S switch was used
1681 * 2. there are more than two dquotes
1682 * 3. there is a special character from this set: &<>()@^|
1683 * 4. no whitespace characters within the two dquotes
1684 * 5. string between two dquotes isn't an executable file
1685 * To work around this, we always add a leading and trailing dquote
1686 * to the string, if the first argument is either "cmd.exe" or "cmd",
1687 * and there were at least two or more arguments passed to cmd.exe
1688 * (not including switches).
1689 * XXX the above rules (from "cmd /?") don't seem to be applied
1690 * always, making for the convolutions below :-(
1694 clen = strlen(cname);
1697 && (stricmp(&cname[clen-4], ".bat") == 0
1698 || (IsWinNT() && stricmp(&cname[clen-4], ".cmd") == 0)))
1704 char *exe = strrchr(cname, '/');
1705 char *exe2 = strrchr(cname, '\\');
1712 if (stricmp(exe, "cmd.exe") == 0 || stricmp(exe, "cmd") == 0) {
1716 else if (stricmp(exe, "command.com") == 0
1717 || stricmp(exe, "command") == 0)
1724 DEBUG_p(PerlIO_printf(Perl_debug_log, "Args "));
1725 for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
1726 STRLEN curlen = strlen(arg);
1727 if (!(arg[0] == '"' && arg[curlen-1] == '"'))
1728 len += 2; /* assume quoting needed (worst case) */
1730 DEBUG_p(PerlIO_printf(Perl_debug_log, "[%s]",arg));
1732 DEBUG_p(PerlIO_printf(Perl_debug_log, "\n"));
1735 Newx(cmd, len, char);
1740 extra_quotes = TRUE;
1743 for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
1745 STRLEN curlen = strlen(arg);
1747 /* we want to protect empty arguments and ones with spaces with
1748 * dquotes, but only if they aren't already there */
1753 else if (quote_next) {
1754 /* see if it really is multiple arguments pretending to
1755 * be one and force a set of quotes around it */
1756 if (*find_next_space(arg))
1759 else if (!(arg[0] == '"' && curlen > 1 && arg[curlen-1] == '"')) {
1761 while (i < curlen) {
1762 if (isSPACE(arg[i])) {
1765 else if (arg[i] == '"') {
1789 && *arg == '/' /* see if arg is "/c", "/x/c", "/x/d/c" etc. */
1790 && stricmp(arg+curlen-2, "/c") == 0)
1792 /* is there a next argument? */
1793 if (args[index+1]) {
1794 /* are there two or more next arguments? */
1795 if (args[index+2]) {
1797 extra_quotes = TRUE;
1800 /* single argument, force quoting if it has spaces */
1816 qualified_path(const char *cmd)
1820 char *fullcmd, *curfullcmd;
1826 fullcmd = (char*)cmd;
1828 if (*fullcmd == '/' || *fullcmd == '\\')
1835 pathstr = PerlEnv_getenv("PATH");
1836 Newx(fullcmd, MAX_PATH+1, char);
1837 curfullcmd = fullcmd;
1842 /* start by appending the name to the current prefix */
1843 strcpy(curfullcmd, cmd);
1844 curfullcmd += cmdlen;
1846 /* if it doesn't end with '.', or has no extension, try adding
1847 * a trailing .exe first */
1848 if (cmd[cmdlen-1] != '.'
1849 && (cmdlen < 4 || cmd[cmdlen-4] != '.'))
1851 strcpy(curfullcmd, ".exe");
1852 res = GetFileAttributes(fullcmd);
1853 if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
1858 /* that failed, try the bare name */
1859 res = GetFileAttributes(fullcmd);
1860 if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
1863 /* quit if no other path exists, or if cmd already has path */
1864 if (!pathstr || !*pathstr || has_slash)
1867 /* skip leading semis */
1868 while (*pathstr == ';')
1871 /* build a new prefix from scratch */
1872 curfullcmd = fullcmd;
1873 while (*pathstr && *pathstr != ';') {
1874 if (*pathstr == '"') { /* foo;"baz;etc";bar */
1875 pathstr++; /* skip initial '"' */
1876 while (*pathstr && *pathstr != '"') {
1877 if ((STRLEN)(curfullcmd-fullcmd) < MAX_PATH-cmdlen-5)
1878 *curfullcmd++ = *pathstr;
1882 pathstr++; /* skip trailing '"' */
1885 if ((STRLEN)(curfullcmd-fullcmd) < MAX_PATH-cmdlen-5)
1886 *curfullcmd++ = *pathstr;
1891 pathstr++; /* skip trailing semi */
1892 if (curfullcmd > fullcmd /* append a dir separator */
1893 && curfullcmd[-1] != '/' && curfullcmd[-1] != '\\')
1895 *curfullcmd++ = '\\';
1903 /* The following are just place holders.
1904 * Some hosts may provide and environment that the OS is
1905 * not tracking, therefore, these host must provide that
1906 * environment and the current directory to CreateProcess
1910 win32_get_childenv(void)
1916 win32_free_childenv(void* d)
1921 win32_clearenv(void)
1923 char *envv = GetEnvironmentStrings();
1927 char *end = strchr(cur,'=');
1928 if (end && end != cur) {
1930 xcesetenv(cur, "", 0);
1932 cur = end + strlen(end+1)+2;
1934 else if ((len = strlen(cur)))
1937 FreeEnvironmentStrings(envv);
1941 win32_get_childdir(void)
1945 char szfilename[MAX_PATH+1];
1946 GetCurrentDirectoryA(MAX_PATH+1, szfilename);
1948 Newx(ptr, strlen(szfilename)+1, char);
1949 strcpy(ptr, szfilename);
1954 win32_free_childdir(char* d)
1960 /* XXX this needs to be made more compatible with the spawnvp()
1961 * provided by the various RTLs. In particular, searching for
1962 * *.{com,bat,cmd} files (as done by the RTLs) is unimplemented.
1963 * This doesn't significantly affect perl itself, because we
1964 * always invoke things using PERL5SHELL if a direct attempt to
1965 * spawn the executable fails.
1967 * XXX splitting and rejoining the commandline between do_aspawn()
1968 * and win32_spawnvp() could also be avoided.
1972 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1974 #ifdef USE_RTL_SPAWNVP
1975 return spawnvp(mode, cmdname, (char * const *)argv);
1982 STARTUPINFO StartupInfo;
1983 PROCESS_INFORMATION ProcessInformation;
1986 char *fullcmd = NULL;
1987 char *cname = (char *)cmdname;
1991 clen = strlen(cname);
1992 /* if command name contains dquotes, must remove them */
1993 if (strchr(cname, '"')) {
1995 Newx(cname,clen+1,char);
2008 cmd = create_command_line(cname, clen, argv);
2010 env = PerlEnv_get_childenv();
2011 dir = PerlEnv_get_childdir();
2014 case P_NOWAIT: /* asynch + remember result */
2015 if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) {
2020 /* Create a new process group so we can use GenerateConsoleCtrlEvent()
2023 /* not supported on CE create |= CREATE_NEW_PROCESS_GROUP; */
2026 case P_WAIT: /* synchronous execution */
2028 default: /* invalid mode */
2033 memset(&StartupInfo,0,sizeof(StartupInfo));
2034 StartupInfo.cb = sizeof(StartupInfo);
2035 memset(&tbl,0,sizeof(tbl));
2036 PerlEnv_get_child_IO(&tbl);
2037 StartupInfo.dwFlags = tbl.dwFlags;
2038 StartupInfo.dwX = tbl.dwX;
2039 StartupInfo.dwY = tbl.dwY;
2040 StartupInfo.dwXSize = tbl.dwXSize;
2041 StartupInfo.dwYSize = tbl.dwYSize;
2042 StartupInfo.dwXCountChars = tbl.dwXCountChars;
2043 StartupInfo.dwYCountChars = tbl.dwYCountChars;
2044 StartupInfo.dwFillAttribute = tbl.dwFillAttribute;
2045 StartupInfo.wShowWindow = tbl.wShowWindow;
2046 StartupInfo.hStdInput = tbl.childStdIn;
2047 StartupInfo.hStdOutput = tbl.childStdOut;
2048 StartupInfo.hStdError = tbl.childStdErr;
2049 if (StartupInfo.hStdInput == INVALID_HANDLE_VALUE &&
2050 StartupInfo.hStdOutput == INVALID_HANDLE_VALUE &&
2051 StartupInfo.hStdError == INVALID_HANDLE_VALUE)
2053 create |= CREATE_NEW_CONSOLE;
2056 StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
2058 if (w32_use_showwindow) {
2059 StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
2060 StartupInfo.wShowWindow = w32_showwindow;
2063 DEBUG_p(PerlIO_printf(Perl_debug_log, "Spawning [%s] with [%s]\n",
2066 if (!CreateProcess(cname, /* search PATH to find executable */
2067 cmd, /* executable, and its arguments */
2068 NULL, /* process attributes */
2069 NULL, /* thread attributes */
2070 TRUE, /* inherit handles */
2071 create, /* creation flags */
2072 (LPVOID)env, /* inherit environment */
2073 dir, /* inherit cwd */
2075 &ProcessInformation))
2077 /* initial NULL argument to CreateProcess() does a PATH
2078 * search, but it always first looks in the directory
2079 * where the current process was started, which behavior
2080 * is undesirable for backward compatibility. So we
2081 * jump through our own hoops by picking out the path
2082 * we really want it to use. */
2084 fullcmd = qualified_path(cname);
2086 if (cname != cmdname)
2089 DEBUG_p(PerlIO_printf(Perl_debug_log,
2090 "Retrying [%s] with same args\n",
2100 if (mode == P_NOWAIT) {
2101 /* asynchronous spawn -- store handle, return PID */
2102 ret = (int)ProcessInformation.dwProcessId;
2103 if (IsWin95() && ret < 0)
2106 w32_child_handles[w32_num_children] = ProcessInformation.hProcess;
2107 w32_child_pids[w32_num_children] = (DWORD)ret;
2112 win32_msgwait(aTHX_ 1, &ProcessInformation.hProcess, INFINITE, NULL);
2113 /* FIXME: if msgwait returned due to message perhaps forward the
2114 "signal" to the process
2116 GetExitCodeProcess(ProcessInformation.hProcess, &status);
2118 CloseHandle(ProcessInformation.hProcess);
2121 CloseHandle(ProcessInformation.hThread);
2124 PerlEnv_free_childenv(env);
2125 PerlEnv_free_childdir(dir);
2127 if (cname != cmdname)
2134 win32_execv(const char *cmdname, const char *const *argv)
2137 Perl_croak(aTHX_ PL_no_func, "execv");
2142 win32_execvp(const char *cmdname, const char *const *argv)
2145 Perl_croak(aTHX_ PL_no_func, "execvp");
2150 win32_perror(const char *str)
2156 win32_setbuf(FILE *pf, char *buf)
2159 Perl_croak(aTHX_ PL_no_func, "setbuf");
2163 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
2165 return setvbuf(pf, buf, type, size);
2169 win32_flushall(void)
2175 win32_fcloseall(void)
2181 win32_fgets(char *s, int n, FILE *pf)
2183 return fgets(s, n, pf);
2193 win32_fgetc(FILE *pf)
2199 win32_putc(int c, FILE *pf)
2205 win32_puts(const char *s)
2217 win32_putchar(int c)
2224 #ifndef USE_PERL_SBRK
2226 static char *committed = NULL;
2227 static char *base = NULL;
2228 static char *reserved = NULL;
2229 static char *brk = NULL;
2230 static DWORD pagesize = 0;
2231 static DWORD allocsize = 0;
2239 GetSystemInfo(&info);
2240 /* Pretend page size is larger so we don't perpetually
2241 * call the OS to commit just one page ...
2243 pagesize = info.dwPageSize << 3;
2244 allocsize = info.dwAllocationGranularity;
2246 /* This scheme fails eventually if request for contiguous
2247 * block is denied so reserve big blocks - this is only
2248 * address space not memory ...
2250 if (brk+need >= reserved)
2252 DWORD size = 64*1024*1024;
2254 if (committed && reserved && committed < reserved)
2256 /* Commit last of previous chunk cannot span allocations */
2257 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
2259 committed = reserved;
2261 /* Reserve some (more) space
2262 * Note this is a little sneaky, 1st call passes NULL as reserved
2263 * so lets system choose where we start, subsequent calls pass
2264 * the old end address so ask for a contiguous block
2266 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
2269 reserved = addr+size;
2284 if (brk > committed)
2286 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
2287 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
2302 win32_malloc(size_t size)
2304 return malloc(size);
2308 win32_calloc(size_t numitems, size_t size)
2310 return calloc(numitems,size);
2314 win32_realloc(void *block, size_t size)
2316 return realloc(block,size);
2320 win32_free(void *block)
2326 win32_open_osfhandle(intptr_t osfhandle, int flags)
2329 char fileflags=0; /* _osfile flags */
2331 Perl_croak_nocontext("win32_open_osfhandle() TBD on this platform");
2336 win32_get_osfhandle(int fd)
2339 char fileflags=0; /* _osfile flags */
2341 Perl_croak_nocontext("win32_get_osfhandle() TBD on this platform");
2346 win32_fdupopen(FILE *pf)
2351 int fileno = win32_dup(win32_fileno(pf));
2352 int fmode = palm_fgetmode(pfdup);
2354 fprintf(stderr,"DEBUG for win32_fdupopen()\n");
2356 /* open the file in the same mode */
2357 if(fmode & O_RDONLY) {
2361 else if(fmode & O_APPEND) {
2365 else if(fmode & O_RDWR) {
2371 /* it appears that the binmode is attached to the
2372 * file descriptor so binmode files will be handled
2375 pfdup = win32_fdopen(fileno, mode);
2377 /* move the file pointer to the same position */
2378 if (!fgetpos(pf, &pos)) {
2379 fsetpos(pfdup, &pos);
2385 win32_dynaload(const char* filename)
2390 hModule = XCELoadLibraryA(filename);
2395 /* this is needed by Cwd.pm... */
2402 SV *sv = sv_newmortal();
2404 xcegetcwd(buf, sizeof(buf));
2406 sv_setpv(sv, xcestrdup(buf));
2410 #ifndef INCOMPLETE_TAINTS
2411 SvTAINTED_on(ST(0));
2422 Perl_croak(aTHX_ "usage: Win32::SetCwd($cwd)");
2424 if (!xcechdir(SvPV_nolen(ST(0))))
2431 XS(w32_GetTickCount)
2434 DWORD msec = GetTickCount();
2442 XS(w32_GetOSVersion)
2445 OSVERSIONINFOA osver;
2447 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
2448 if (!XCEGetVersionExA(&osver)) {
2451 mXPUSHp(osver.szCSDVersion, strlen(osver.szCSDVersion));
2452 mXPUSHi(osver.dwMajorVersion);
2453 mXPUSHi(osver.dwMinorVersion);
2454 mXPUSHi(osver.dwBuildNumber);
2456 mXPUSHi(osver.dwPlatformId);
2465 XSRETURN_IV(IsWinNT());
2473 XSRETURN_IV(IsWin95());
2481 XSRETURN_IV(IsWinCE());
2491 if(SystemParametersInfoW(SPI_GETOEMINFO, sizeof(wbuf), wbuf, FALSE))
2492 WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, sizeof(buf), 0, 0);
2494 sprintf(buf, "SystemParametersInfo failed: %d", GetLastError());
2505 Perl_croak(aTHX_ "usage: Win32::Sleep($milliseconds)");
2516 Perl_croak(aTHX_ "usage: Win32::CopyFile($from, $to, $overwrite)");
2519 char szSourceFile[MAX_PATH+1];
2520 strcpy(szSourceFile, PerlDir_mapA(SvPV_nolen(ST(0))));
2521 bResult = XCECopyFileA(szSourceFile, SvPV_nolen(ST(1)),
2538 unsigned int flags = MB_OK;
2540 txt = SvPV_nolen(ST(0));
2542 if (items < 1 || items > 2)
2543 Perl_croak(aTHX_ "usage: Win32::MessageBox($txt, [$flags])");
2546 flags = SvIV(ST(1));
2548 res = XCEMessageBoxA(NULL, txt, "Perl", flags);
2554 XS(w32_GetPowerStatus)
2558 SYSTEM_POWER_STATUS_EX sps;
2560 if(GetSystemPowerStatusEx(&sps, TRUE) == FALSE)
2565 mXPUSHi(sps.ACLineStatus);
2566 mXPUSHi(sps.BatteryFlag);
2567 mXPUSHi(sps.BatteryLifePercent);
2568 mXPUSHi(sps.BatteryLifeTime);
2569 mXPUSHi(sps.BatteryFullLifeTime);
2570 mXPUSHi(sps.BackupBatteryFlag);
2571 mXPUSHi(sps.BackupBatteryLifePercent);
2572 mXPUSHi(sps.BackupBatteryLifeTime);
2573 mXPUSHi(sps.BackupBatteryFullLifeTime);
2585 SHELLEXECUTEINFO si;
2587 wchar_t wfile[MAX_PATH];
2591 Perl_croak(aTHX_ "usage: Win32::ShellEx($file, $verb)");
2593 file = SvPV_nolen(ST(0));
2594 verb = SvPV_nolen(ST(1));
2596 memset(&si, 0, sizeof(si));
2597 si.cbSize = sizeof(si);
2598 si.fMask = SEE_MASK_FLAG_NO_UI;
2600 MultiByteToWideChar(CP_ACP, 0, verb, -1,
2601 wverb, sizeof(wverb)/2);
2602 si.lpVerb = (TCHAR *)wverb;
2604 MultiByteToWideChar(CP_ACP, 0, file, -1,
2605 wfile, sizeof(wfile)/2);
2606 si.lpFile = (TCHAR *)wfile;
2608 if(ShellExecuteEx(&si) == FALSE)
2617 Perl_init_os_extras(void)
2620 char *file = __FILE__;
2623 w32_perlshell_tokens = NULL;
2624 w32_perlshell_items = -1;
2625 w32_fdpid = newAV(); /* XX needs to be in Perl_win32_init()? */
2626 Newx(w32_children, 1, child_tab);
2627 w32_num_children = 0;
2629 newXS("Win32::GetCwd", w32_GetCwd, file);
2630 newXS("Win32::SetCwd", w32_SetCwd, file);
2631 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2632 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2634 newXS("Win32::ShellEx", w32_ShellEx, file);
2636 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2637 newXS("Win32::IsWin95", w32_IsWin95, file);
2638 newXS("Win32::IsWinCE", w32_IsWinCE, file);
2639 newXS("Win32::CopyFile", w32_CopyFile, file);
2640 newXS("Win32::Sleep", w32_Sleep, file);
2641 newXS("Win32::MessageBox", w32_MessageBox, file);
2642 newXS("Win32::GetPowerStatus", w32_GetPowerStatus, file);
2643 newXS("Win32::GetOemInfo", w32_GetOemInfo, file);
2652 fgets(buf, sizeof(buf), stdin);
2656 Perl_win32_init(int *argcp, char ***argvp)
2661 if((p = xcegetenv("PERLDEBUG")) && (p[0] == 'y' || p[0] == 'Y'))
2669 Perl_win32_term(void)
2679 win32_get_child_IO(child_IO_table* ptbl)
2681 ptbl->childStdIn = GetStdHandle(STD_INPUT_HANDLE);
2682 ptbl->childStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
2683 ptbl->childStdErr = GetStdHandle(STD_ERROR_HANDLE);
2686 win32_flock(int fd, int oper)
2689 Perl_croak(aTHX_ PL_no_func, "flock");
2694 win32_waitpid(int pid, int *status, int flags)
2697 Perl_croak(aTHX_ PL_no_func, "waitpid");
2702 win32_wait(int *status)
2705 Perl_croak(aTHX_ PL_no_func, "wait");
2710 wce_reopen_stdout(char *fname)
2712 if(xcefreopen(fname, "w", stdout) == NULL)
2723 printf("Hit RETURN");
2725 fgets(buf, sizeof(buf), stdin);
2729 /* //////////////////////////////////////////////////////////////////// */
2734 getcwd(char *buf, size_t size)
2736 return xcegetcwd(buf, size);
2747 win32_popenlist(const char *mode, IV narg, SV **args)
2750 Perl_croak(aTHX_ "List form of pipe open not implemented");
2755 * a popen() clone that respects PERL5SHELL
2757 * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
2761 win32_popen(const char *command, const char *mode)
2763 return _popen(command, mode);
2771 win32_pclose(PerlIO *pf)
2776 #ifdef HAVE_INTERP_INTERN
2780 win32_csighandler(int sig)
2783 dTHXa(PERL_GET_SIG_CONTEXT);
2784 Perl_warn(aTHX_ "Got signal %d",sig);
2790 Perl_sys_intern_init(pTHX)
2793 w32_perlshell_tokens = NULL;
2794 w32_perlshell_vec = (char**)NULL;
2795 w32_perlshell_items = 0;
2796 w32_fdpid = newAV();
2797 Newx(w32_children, 1, child_tab);
2798 w32_num_children = 0;
2799 # ifdef USE_ITHREADS
2801 Newx(w32_pseudo_children, 1, child_tab);
2802 w32_num_pseudo_children = 0;
2804 w32_init_socktype = 0;
2810 Perl_sys_intern_clear(pTHX)
2812 Safefree(w32_perlshell_tokens);
2813 Safefree(w32_perlshell_vec);
2814 /* NOTE: w32_fdpid is freed by sv_clean_all() */
2815 Safefree(w32_children);
2817 KillTimer(NULL,w32_timerid);
2820 # ifdef USE_ITHREADS
2821 Safefree(w32_pseudo_children);
2825 # ifdef USE_ITHREADS
2828 Perl_sys_intern_dup(pTHX_ struct interp_intern *src, struct interp_intern *dst)
2830 dst->perlshell_tokens = NULL;
2831 dst->perlshell_vec = (char**)NULL;
2832 dst->perlshell_items = 0;
2833 dst->fdpid = newAV();
2834 Newxz(dst->children, 1, child_tab);
2836 Newxz(dst->pseudo_children, 1, child_tab);
2837 dst->thr_intern.Winit_socktype = 0;
2839 dst->poll_count = 0;
2840 Copy(src->sigtable,dst->sigtable,SIG_SIZE,Sighandler_t);
2842 # endif /* USE_ITHREADS */
2843 #endif /* HAVE_INTERP_INTERN */
2845 // added to remove undefied symbol error in CodeWarrior compilation
2847 Perl_Ireentrant_buffer_ptr(aTHX)