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, STRLEN *const len,
75 static void remove_dead_process(long deceased);
76 static long find_pid(int pid);
77 static char * qualified_path(const char *cmd);
78 static char * win32_get_xlib(const char *pl, const char *xlib,
79 const char *libname, STRLEN *const len);
82 static void remove_dead_pseudo_process(long child);
83 static long find_pseudo_pid(int pid);
86 int _fmode = O_TEXT; /* celib do not provide _fmode, so we define it here */
89 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
90 char w32_module_name[MAX_PATH+1];
93 static DWORD w32_platform = (DWORD)-1;
98 return (win32_os_id() == VER_PLATFORM_WIN32_WINDOWS);
104 return (win32_os_id() == VER_PLATFORM_WIN32_NT);
110 return (win32_os_id() == VER_PLATFORM_WIN32_CE);
114 set_w32_module_name(void)
117 XCEGetModuleFileNameA((HMODULE)((w32_perldll_handle == INVALID_HANDLE_VALUE)
118 ? XCEGetModuleHandleA(NULL)
119 : w32_perldll_handle),
120 w32_module_name, sizeof(w32_module_name));
122 /* normalize to forward slashes */
123 ptr = w32_module_name;
131 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
133 get_regstr_from(HKEY hkey, const char *valuename, SV **svp)
135 /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
138 const char *subkey = "Software\\Perl";
142 retval = XCERegOpenKeyExA(hkey, subkey, 0, KEY_READ, &handle);
143 if (retval == ERROR_SUCCESS) {
145 retval = XCERegQueryValueExA(handle, valuename, 0, &type, NULL, &datalen);
146 if (retval == ERROR_SUCCESS && type == REG_SZ) {
149 *svp = sv_2mortal(newSVpvn("",0));
150 SvGROW(*svp, datalen);
151 retval = XCERegQueryValueExA(handle, valuename, 0, NULL,
152 (PBYTE)SvPVX(*svp), &datalen);
153 if (retval == ERROR_SUCCESS) {
155 SvCUR_set(*svp,datalen-1);
163 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
165 get_regstr(const char *valuename, SV **svp)
167 char *str = get_regstr_from(HKEY_CURRENT_USER, valuename, svp);
169 str = get_regstr_from(HKEY_LOCAL_MACHINE, valuename, svp);
173 /* *prev_pathp (if non-NULL) is expected to be POK (valid allocated SvPVX(sv)) */
175 get_emd_part(SV **prev_pathp, STRLEN *const len, char *trailing_path, ...)
179 char mod_name[MAX_PATH+1];
183 int oldsize, newsize;
186 va_start(ap, trailing_path);
187 strip = va_arg(ap, char *);
189 sprintf(base, "%d.%d", (int)PERL_REVISION, (int)PERL_VERSION);
190 baselen = strlen(base);
192 if (!*w32_module_name) {
193 set_w32_module_name();
195 strcpy(mod_name, w32_module_name);
196 ptr = strrchr(mod_name, '/');
197 while (ptr && strip) {
198 /* look for directories to skip back */
201 ptr = strrchr(mod_name, '/');
202 /* avoid stripping component if there is no slash,
203 * or it doesn't match ... */
204 if (!ptr || stricmp(ptr+1, strip) != 0) {
205 /* ... but not if component matches m|5\.$patchlevel.*| */
206 if (!ptr || !(*strip == '5' && *(ptr+1) == '5'
207 && strncmp(strip, base, baselen) == 0
208 && strncmp(ptr+1, base, baselen) == 0))
214 strip = va_arg(ap, char *);
222 strcpy(++ptr, trailing_path);
224 /* only add directory if it exists */
225 if (XCEGetFileAttributesA(mod_name) != (DWORD) -1) {
226 /* directory exists */
229 *prev_pathp = sv_2mortal(newSVpvn("",0));
230 sv_catpvn(*prev_pathp, ";", 1);
231 sv_catpv(*prev_pathp, mod_name);
233 *len = SvCUR(*prev_pathp);
234 return SvPVX(*prev_pathp);
241 win32_get_privlib(const char *pl, STRLEN *const len)
244 char *stdlib = "lib";
245 char buffer[MAX_PATH+1];
248 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
249 sprintf(buffer, "%s-%s", stdlib, pl);
250 if (!get_regstr(buffer, &sv))
251 (void)get_regstr(stdlib, &sv);
253 /* $stdlib .= ";$EMD/../../lib" */
254 return get_emd_part(&sv, len, stdlib, ARCHNAME, "bin", NULL);
258 win32_get_xlib(const char *pl, const char *xlib, const char *libname,
263 char pathstr[MAX_PATH+1];
269 /* $HKCU{"$xlib-$]"} || $HKLM{"$xlib-$]"} . ---; */
270 sprintf(regstr, "%s-%s", xlib, pl);
271 (void)get_regstr(regstr, &sv1);
274 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/$]/lib"; */
275 sprintf(pathstr, "%s/%s/lib", libname, pl);
276 (void)get_emd_part(&sv1, NULL, pathstr, ARCHNAME, "bin", pl, NULL);
278 /* $HKCU{$xlib} || $HKLM{$xlib} . ---; */
279 (void)get_regstr(xlib, &sv2);
282 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/lib"; */
283 sprintf(pathstr, "%s/lib", libname);
284 (void)get_emd_part(&sv2, NULL, pathstr, ARCHNAME, "bin", pl, NULL);
291 sv_catpvn(sv1, ";", 1);
301 win32_get_sitelib(const char *pl, STRLEN *const len)
303 return win32_get_xlib(pl, "sitelib", "site", len);
306 #ifndef PERL_VENDORLIB_NAME
307 # define PERL_VENDORLIB_NAME "vendor"
311 win32_get_vendorlib(const char *pl, STRLEN *const len)
313 return win32_get_xlib(pl, "vendorlib", PERL_VENDORLIB_NAME, len);
317 has_shell_metachars(char *ptr)
323 * Scan string looking for redirection (< or >) or pipe
324 * characters (|) that are not in a quoted string.
325 * Shell variable interpolation (%VAR%) can also happen inside strings.
357 #if !defined(PERL_IMPLICIT_SYS)
358 /* since the current process environment is being updated in util.c
359 * the library functions will get the correct environment
362 Perl_my_popen(pTHX_ const char *cmd, const char *mode)
364 printf("popen(%s)\n", cmd);
366 Perl_croak(aTHX_ PL_no_func, "popen");
371 Perl_my_pclose(pTHX_ PerlIO *fp)
373 Perl_croak(aTHX_ PL_no_func, "pclose");
378 DllExport unsigned long
381 static OSVERSIONINFOA osver;
383 if (osver.dwPlatformId != w32_platform) {
384 memset(&osver, 0, sizeof(OSVERSIONINFOA));
385 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
386 XCEGetVersionExA(&osver);
387 w32_platform = osver.dwPlatformId;
389 return (unsigned long)w32_platform;
399 return -((int)w32_pseudo_id);
405 /* Tokenize a string. Words are null-separated, and the list
406 * ends with a doubled null. Any character (except null and
407 * including backslash) may be escaped by preceding it with a
408 * backslash (the backslash will be stripped).
409 * Returns number of words in result buffer.
412 tokenize(const char *str, char **dest, char ***destv)
414 char *retstart = NULL;
415 char **retvstart = 0;
419 int slen = strlen(str);
421 register char **retv;
422 Newx(ret, slen+2, char);
423 Newx(retv, (slen+3)/2, char*);
431 if (*ret == '\\' && *str)
433 else if (*ret == ' ') {
449 retvstart[items] = NULL;
459 win32_pipe(int *pfd, unsigned int size, int mode)
462 Perl_croak(aTHX_ PL_no_func, "pipe");
467 win32_times(struct tms *timebuf)
470 Perl_croak(aTHX_ PL_no_func, "times");
475 win32_signal(int sig, Sighandler_t subcode)
477 return xcesignal(sig, subcode);
484 if (!w32_perlshell_tokens) {
485 /* we don't use COMSPEC here for two reasons:
486 * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
487 * uncontrolled unportability of the ensuing scripts.
488 * 2. PERL5SHELL could be set to a shell that may not be fit for
489 * interactive use (which is what most programs look in COMSPEC
492 const char* defaultshell = (IsWinNT()
493 ? "cmd.exe /x/d/c" : "command.com /c");
494 const char *usershell = PerlEnv_getenv("PERL5SHELL");
495 w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
496 &w32_perlshell_tokens,
502 Perl_do_aspawn(pTHX_ SV *really, SV **mark, SV **sp)
504 PERL_ARGS_ASSERT_DO_ASPAWN;
506 Perl_croak(aTHX_ PL_no_func, "aspawn");
510 /* returns pointer to the next unquoted space or the end of the string */
512 find_next_space(const char *s)
514 bool in_quotes = FALSE;
516 /* ignore doubled backslashes, or backslash+quote */
517 if (*s == '\\' && (s[1] == '\\' || s[1] == '"')) {
520 /* keep track of when we're within quotes */
521 else if (*s == '"') {
523 in_quotes = !in_quotes;
525 /* break it up only at spaces that aren't in quotes */
526 else if (!in_quotes && isSPACE(*s))
536 do_spawn2(pTHX_ char *cmd, int exectype)
542 BOOL needToTry = TRUE;
545 /* Save an extra exec if possible. See if there are shell
546 * metacharacters in it */
547 if (!has_shell_metachars(cmd)) {
548 Newx(argv, strlen(cmd) / 2 + 2, char*);
549 Newx(cmd2, strlen(cmd) + 1, char);
552 for (s = cmd2; *s;) {
553 while (*s && isSPACE(*s))
557 s = find_next_space(s);
565 status = win32_spawnvp(P_WAIT, argv[0],
566 (const char* const*)argv);
568 case EXECF_SPAWN_NOWAIT:
569 status = win32_spawnvp(P_NOWAIT, argv[0],
570 (const char* const*)argv);
573 status = win32_execvp(argv[0], (const char* const*)argv);
576 if (status != -1 || errno == 0)
586 Newx(argv, w32_perlshell_items + 2, char*);
587 while (++i < w32_perlshell_items)
588 argv[i] = w32_perlshell_vec[i];
593 status = win32_spawnvp(P_WAIT, argv[0],
594 (const char* const*)argv);
596 case EXECF_SPAWN_NOWAIT:
597 status = win32_spawnvp(P_NOWAIT, argv[0],
598 (const char* const*)argv);
601 status = win32_execvp(argv[0], (const char* const*)argv);
607 if (exectype == EXECF_SPAWN_NOWAIT) {
609 PL_statusvalue = -1; /* >16bits hint for pp_system() */
613 if (ckWARN(WARN_EXEC))
614 Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't %s \"%s\": %s",
615 (exectype == EXECF_EXEC ? "exec" : "spawn"),
616 cmd, strerror(errno));
621 PL_statusvalue = status;
627 Perl_do_spawn(pTHX_ char *cmd)
629 PERL_ARGS_ASSERT_DO_SPAWN;
631 return do_spawn2(aTHX_ cmd, EXECF_SPAWN);
635 Perl_do_spawn_nowait(pTHX_ char *cmd)
637 PERL_ARGS_ASSERT_DO_SPAWN_NOWAIT;
639 return do_spawn2(aTHX_ cmd, EXECF_SPAWN_NOWAIT);
643 Perl_do_exec(pTHX_ const char *cmd)
645 PERL_ARGS_ASSERT_DO_EXEC;
647 do_spawn2(aTHX_ cmd, EXECF_EXEC);
651 /* The idea here is to read all the directory names into a string table
652 * (separated by nulls) and when one of the other dir functions is called
653 * return the pointer to the current file name.
656 win32_opendir(const char *filename)
662 char scanname[MAX_PATH+3];
664 WIN32_FIND_DATAA aFindData;
665 WIN32_FIND_DATAW wFindData;
667 char buffer[MAX_PATH*2];
668 WCHAR wbuffer[MAX_PATH+1];
671 len = strlen(filename);
675 /* check to see if filename is a directory */
676 if (win32_stat(filename, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode))
679 /* Get us a DIR structure */
682 /* Create the search pattern */
683 strcpy(scanname, filename);
685 /* bare drive name means look in cwd for drive */
686 if (len == 2 && isALPHA(scanname[0]) && scanname[1] == ':') {
687 scanname[len++] = '.';
688 scanname[len++] = '/';
690 else if (scanname[len-1] != '/' && scanname[len-1] != '\\') {
691 scanname[len++] = '/';
693 scanname[len++] = '*';
694 scanname[len] = '\0';
696 /* do the FindFirstFile call */
697 fh = FindFirstFile(PerlDir_mapA(scanname), &aFindData);
699 if (fh == INVALID_HANDLE_VALUE) {
700 DWORD err = GetLastError();
701 /* FindFirstFile() fails on empty drives! */
703 case ERROR_FILE_NOT_FOUND:
705 case ERROR_NO_MORE_FILES:
706 case ERROR_PATH_NOT_FOUND:
709 case ERROR_NOT_ENOUGH_MEMORY:
720 /* now allocate the first part of the string table for
721 * the filenames that we find.
723 ptr = aFindData.cFileName;
729 Newx(dirp->start, dirp->size, char);
730 strcpy(dirp->start, ptr);
732 dirp->end = dirp->curr = dirp->start;
738 /* Readdir just returns the current string pointer and bumps the
739 * string pointer to the nDllExport entry.
741 DllExport struct direct *
742 win32_readdir(DIR *dirp)
747 /* first set up the structure to return */
748 len = strlen(dirp->curr);
749 strcpy(dirp->dirstr.d_name, dirp->curr);
750 dirp->dirstr.d_namlen = len;
753 dirp->dirstr.d_ino = dirp->curr - dirp->start;
755 /* Now set up for the next call to readdir */
756 dirp->curr += len + 1;
757 if (dirp->curr >= dirp->end) {
761 WIN32_FIND_DATAW wFindData;
762 WIN32_FIND_DATAA aFindData;
763 char buffer[MAX_PATH*2];
765 /* finding the next file that matches the wildcard
766 * (which should be all of them in this directory!).
768 res = FindNextFile(dirp->handle, &aFindData);
770 ptr = aFindData.cFileName;
772 long endpos = dirp->end - dirp->start;
773 long newsize = endpos + strlen(ptr) + 1;
774 /* bump the string table size by enough for the
775 * new name and its null terminator */
776 while (newsize > dirp->size) {
777 long curpos = dirp->curr - dirp->start;
779 Renew(dirp->start, dirp->size, char);
780 dirp->curr = dirp->start + curpos;
782 strcpy(dirp->start + endpos, ptr);
783 dirp->end = dirp->start + newsize;
789 return &(dirp->dirstr);
795 /* Telldir returns the current string pointer position */
797 win32_telldir(DIR *dirp)
799 return (dirp->curr - dirp->start);
803 /* Seekdir moves the string pointer to a previously saved position
804 * (returned by telldir).
807 win32_seekdir(DIR *dirp, long loc)
809 dirp->curr = dirp->start + loc;
812 /* Rewinddir resets the string pointer to the start */
814 win32_rewinddir(DIR *dirp)
816 dirp->curr = dirp->start;
819 /* free the memory allocated by opendir */
821 win32_closedir(DIR *dirp)
824 if (dirp->handle != INVALID_HANDLE_VALUE)
825 FindClose(dirp->handle);
826 Safefree(dirp->start);
832 /////!!!!!!!!!!! return here and do right stuff!!!!
835 win32_opendir(const char *filename)
837 return opendir(filename);
840 DllExport struct direct *
841 win32_readdir(DIR *dirp)
843 return readdir(dirp);
847 win32_telldir(DIR *dirp)
850 Perl_croak(aTHX_ PL_no_func, "telldir");
855 win32_seekdir(DIR *dirp, long loc)
858 Perl_croak(aTHX_ PL_no_func, "seekdir");
862 win32_rewinddir(DIR *dirp)
865 Perl_croak(aTHX_ PL_no_func, "rewinddir");
869 win32_closedir(DIR *dirp)
877 win32_kill(int pid, int sig)
880 Perl_croak(aTHX_ PL_no_func, "kill");
885 win32_stat(const char *path, struct stat *sbuf)
887 return xcestat(path, sbuf);
891 win32_longpath(char *path)
896 #ifndef USE_WIN32_RTL_ENV
899 win32_getenv(const char *name)
901 return xcegetenv(name);
905 win32_putenv(const char *name)
907 return xceputenv(name);
913 filetime_to_clock(PFILETIME ft)
915 __int64 qw = ft->dwHighDateTime;
917 qw |= ft->dwLowDateTime;
918 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
922 /* fix utime() so it works on directories in NT */
924 filetime_from_time(PFILETIME pFileTime, time_t Time)
926 struct tm *pTM = localtime(&Time);
927 SYSTEMTIME SystemTime;
933 SystemTime.wYear = pTM->tm_year + 1900;
934 SystemTime.wMonth = pTM->tm_mon + 1;
935 SystemTime.wDay = pTM->tm_mday;
936 SystemTime.wHour = pTM->tm_hour;
937 SystemTime.wMinute = pTM->tm_min;
938 SystemTime.wSecond = pTM->tm_sec;
939 SystemTime.wMilliseconds = 0;
941 return SystemTimeToFileTime(&SystemTime, &LocalTime) &&
942 LocalFileTimeToFileTime(&LocalTime, pFileTime);
946 win32_unlink(const char *filename)
948 return xceunlink(filename);
952 win32_utime(const char *filename, struct utimbuf *times)
954 return xceutime(filename, (struct _utimbuf *) times);
958 win32_gettimeofday(struct timeval *tp, void *not_used)
960 return xcegettimeofday(tp,not_used);
964 win32_uname(struct utsname *name)
967 STRLEN nodemax = sizeof(name->nodename)-1;
968 OSVERSIONINFOA osver;
970 memset(&osver, 0, sizeof(OSVERSIONINFOA));
971 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
972 if (XCEGetVersionExA(&osver)) {
974 switch (osver.dwPlatformId) {
975 case VER_PLATFORM_WIN32_CE:
976 strcpy(name->sysname, "Windows CE");
978 case VER_PLATFORM_WIN32_WINDOWS:
979 strcpy(name->sysname, "Windows");
981 case VER_PLATFORM_WIN32_NT:
982 strcpy(name->sysname, "Windows NT");
984 case VER_PLATFORM_WIN32s:
985 strcpy(name->sysname, "Win32s");
988 strcpy(name->sysname, "Win32 Unknown");
993 sprintf(name->release, "%d.%d",
994 osver.dwMajorVersion, osver.dwMinorVersion);
997 sprintf(name->version, "Build %d",
998 osver.dwPlatformId == VER_PLATFORM_WIN32_NT
999 ? osver.dwBuildNumber : (osver.dwBuildNumber & 0xffff));
1000 if (osver.szCSDVersion[0]) {
1001 char *buf = name->version + strlen(name->version);
1002 sprintf(buf, " (%s)", osver.szCSDVersion);
1006 *name->sysname = '\0';
1007 *name->version = '\0';
1008 *name->release = '\0';
1012 hep = win32_gethostbyname("localhost");
1014 STRLEN len = strlen(hep->h_name);
1015 if (len <= nodemax) {
1016 strcpy(name->nodename, hep->h_name);
1019 strncpy(name->nodename, hep->h_name, nodemax);
1020 name->nodename[nodemax] = '\0';
1025 if (!XCEGetComputerNameA(name->nodename, &sz))
1026 *name->nodename = '\0';
1029 /* machine (architecture) */
1033 GetSystemInfo(&info);
1035 switch (info.wProcessorArchitecture) {
1036 case PROCESSOR_ARCHITECTURE_INTEL:
1037 arch = "x86"; break;
1038 case PROCESSOR_ARCHITECTURE_MIPS:
1039 arch = "mips"; break;
1040 case PROCESSOR_ARCHITECTURE_ALPHA:
1041 arch = "alpha"; break;
1042 case PROCESSOR_ARCHITECTURE_PPC:
1043 arch = "ppc"; break;
1044 case PROCESSOR_ARCHITECTURE_ARM:
1045 arch = "arm"; break;
1046 case PROCESSOR_HITACHI_SH3:
1047 arch = "sh3"; break;
1048 case PROCESSOR_SHx_SH3:
1049 arch = "sh3"; break;
1052 arch = "unknown"; break;
1054 strcpy(name->machine, arch);
1059 /* Timing related stuff */
1062 do_raise(pTHX_ int sig)
1064 if (sig < SIG_SIZE) {
1065 Sighandler_t handler = w32_sighandler[sig];
1066 if (handler == SIG_IGN) {
1069 else if (handler != SIG_DFL) {
1074 /* Choose correct default behaviour */
1090 /* Tell caller to exit thread/process as approriate */
1095 sig_terminate(pTHX_ int sig)
1097 Perl_warn(aTHX_ "Terminating on signal SIG%s(%d)\n",PL_sig_name[sig], sig);
1098 /* exit() seems to be safe, my_exit() or die() is a problem in ^C
1105 win32_async_check(pTHX)
1109 /* Passing PeekMessage -1 as HWND (2nd arg) only get PostThreadMessage() messages
1110 * and ignores window messages - should co-exist better with windows apps e.g. Tk
1112 while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE|PM_NOYIELD)) {
1114 switch(msg.message) {
1117 /* Perhaps some other messages could map to signals ? ... */
1120 /* Treat WM_QUIT like SIGHUP? */
1126 /* We use WM_USER to fake kill() with other signals */
1130 if (do_raise(aTHX_ sig)) {
1131 sig_terminate(aTHX_ sig);
1137 /* alarm() is a one-shot but SetTimer() repeats so kill it */
1139 KillTimer(NULL,w32_timerid);
1142 /* Now fake a call to signal handler */
1143 if (do_raise(aTHX_ 14)) {
1144 sig_terminate(aTHX_ 14);
1149 /* Otherwise do normal Win32 thing - in case it is useful */
1151 TranslateMessage(&msg);
1152 DispatchMessage(&msg);
1159 /* Above or other stuff may have set a signal flag */
1160 if (PL_sig_pending) {
1166 /* This function will not return until the timeout has elapsed, or until
1167 * one of the handles is ready. */
1169 win32_msgwait(pTHX_ DWORD count, LPHANDLE handles, DWORD timeout, LPDWORD resultp)
1171 /* We may need several goes at this - so compute when we stop */
1173 if (timeout != INFINITE) {
1174 ticks = GetTickCount();
1178 DWORD result = MsgWaitForMultipleObjects(count,handles,FALSE,timeout-ticks, QS_ALLEVENTS);
1181 if (result == WAIT_TIMEOUT) {
1182 /* Ran out of time - explicit return of zero to avoid -ve if we
1183 have scheduling issues
1187 if (timeout != INFINITE) {
1188 ticks = GetTickCount();
1190 if (result == WAIT_OBJECT_0 + count) {
1191 /* Message has arrived - check it */
1192 (void)win32_async_check(aTHX);
1195 /* Not timeout or message - one of handles is ready */
1199 /* compute time left to wait */
1200 ticks = timeout - ticks;
1201 /* If we are past the end say zero */
1202 return (ticks > 0) ? ticks : 0;
1205 static UINT timerid = 0;
1207 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
1210 KillTimer(NULL,timerid);
1215 DllExport unsigned int
1216 win32_sleep(unsigned int t)
1221 DllExport unsigned int
1222 win32_alarm(unsigned int sec)
1225 * the 'obvious' implentation is SetTimer() with a callback
1226 * which does whatever receiving SIGALRM would do
1227 * we cannot use SIGALRM even via raise() as it is not
1228 * one of the supported codes in <signal.h>
1230 * Snag is unless something is looking at the message queue
1231 * nothing happens :-(
1236 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
1238 Perl_croak_nocontext("Cannot set timer");
1244 KillTimer(NULL,timerid);
1251 #ifdef HAVE_DES_FCRYPT
1252 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
1256 win32_crypt(const char *txt, const char *salt)
1259 #ifdef HAVE_DES_FCRYPT
1261 return des_fcrypt(txt, salt, w32_crypt_buffer);
1263 Perl_croak(aTHX_ "The crypt() function is unimplemented due to excessive paranoia.");
1270 * redirected io subsystem for all XS modules
1283 return (&(environ));
1286 /* the rest are the remapped stdio routines */
1293 char *g_getlogin() {
1294 return "no-getlogin";
1310 win32_ferror(FILE *fp)
1312 return (ferror(fp));
1317 win32_feof(FILE *fp)
1323 * Since the errors returned by the socket error function
1324 * WSAGetLastError() are not known by the library routine strerror
1325 * we have to roll our own.
1329 win32_strerror(int e)
1331 return xcestrerror(e);
1335 win32_str_os_error(void *sv, DWORD dwErr)
1339 sv_setpvn((SV*)sv, "Error", 5);
1344 win32_fprintf(FILE *fp, const char *format, ...)
1347 va_start(marker, format); /* Initialize variable arguments. */
1349 return (vfprintf(fp, format, marker));
1353 win32_printf(const char *format, ...)
1356 va_start(marker, format); /* Initialize variable arguments. */
1358 return (vprintf(format, marker));
1362 win32_vfprintf(FILE *fp, const char *format, va_list args)
1364 return (vfprintf(fp, format, args));
1368 win32_vprintf(const char *format, va_list args)
1370 return (vprintf(format, args));
1374 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
1376 return fread(buf, size, count, fp);
1380 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
1382 return fwrite(buf, size, count, fp);
1386 win32_fopen(const char *filename, const char *mode)
1388 return xcefopen(filename, mode);
1392 win32_fdopen(int handle, const char *mode)
1394 return palm_fdopen(handle, mode);
1398 win32_freopen(const char *path, const char *mode, FILE *stream)
1400 return xcefreopen(path, mode, stream);
1404 win32_fclose(FILE *pf)
1406 return xcefclose(pf);
1410 win32_fputs(const char *s,FILE *pf)
1412 return fputs(s, pf);
1416 win32_fputc(int c,FILE *pf)
1422 win32_ungetc(int c,FILE *pf)
1424 return ungetc(c,pf);
1428 win32_getc(FILE *pf)
1434 win32_fileno(FILE *pf)
1436 return palm_fileno(pf);
1440 win32_clearerr(FILE *pf)
1447 win32_fflush(FILE *pf)
1453 win32_ftell(FILE *pf)
1459 win32_fseek(FILE *pf, Off_t offset,int origin)
1461 return fseek(pf, offset, origin);
1464 /* fpos_t seems to be int64 on hpc pro! Really stupid. */
1465 /* But maybe someday there will be such large disks in a hpc... */
1467 win32_fgetpos(FILE *pf, fpos_t *p)
1469 return fgetpos(pf, p);
1473 win32_fsetpos(FILE *pf, const fpos_t *p)
1475 return fsetpos(pf, p);
1479 win32_rewind(FILE *pf)
1481 fseek(pf, 0, SEEK_SET);
1489 char prefix[MAX_PATH+1];
1490 char filename[MAX_PATH+1];
1491 DWORD len = GetTempPath(MAX_PATH, prefix);
1492 if (len && len < MAX_PATH) {
1493 if (GetTempFileName(prefix, "plx", 0, filename)) {
1494 HANDLE fh = CreateFile(filename,
1495 DELETE | GENERIC_READ | GENERIC_WRITE,
1499 FILE_ATTRIBUTE_NORMAL
1500 | FILE_FLAG_DELETE_ON_CLOSE,
1502 if (fh != INVALID_HANDLE_VALUE) {
1503 int fd = win32_open_osfhandle((intptr_t)fh, 0);
1505 #if defined(__BORLANDC__)
1506 setmode(fd,O_BINARY);
1508 DEBUG_p(PerlIO_printf(Perl_debug_log,
1509 "Created tmpfile=%s\n",filename));
1521 int fd = win32_tmpfd();
1523 return win32_fdopen(fd, "w+b");
1536 win32_fstat(int fd, struct stat *sbufptr)
1538 return xcefstat(fd, sbufptr);
1542 win32_link(const char *oldname, const char *newname)
1545 Perl_croak(aTHX_ PL_no_func, "link");
1551 win32_rename(const char *oname, const char *newname)
1553 return xcerename(oname, newname);
1557 win32_setmode(int fd, int mode)
1559 /* currently 'celib' seem to have this function in src, but not
1560 * exported. When it will be, we'll uncomment following line.
1562 /* return xcesetmode(fd, mode); */
1567 win32_chsize(int fd, Off_t size)
1569 return chsize(fd, size);
1573 win32_lseek(int fd, Off_t offset, int origin)
1575 return xcelseek(fd, offset, origin);
1581 return xcelseek(fd, 0, SEEK_CUR);
1585 win32_open(const char *path, int flag, ...)
1591 pmode = va_arg(ap, int);
1594 return xceopen(path, flag, pmode);
1600 return xceclose(fd);
1607 Perl_croak(aTHX_ PL_no_func, "eof");
1614 return xcedup(fd); /* from celib/ceio.c; requires some more work on it */
1618 win32_dup2(int fd1,int fd2)
1620 return xcedup2(fd1,fd2);
1624 win32_read(int fd, void *buf, unsigned int cnt)
1626 return xceread(fd, buf, cnt);
1630 win32_write(int fd, const void *buf, unsigned int cnt)
1632 return xcewrite(fd, (void *) buf, cnt);
1636 win32_mkdir(const char *dir, int mode)
1638 return xcemkdir(dir);
1642 win32_rmdir(const char *dir)
1644 return xcermdir(dir);
1648 win32_chdir(const char *dir)
1650 return xcechdir(dir);
1654 win32_access(const char *path, int mode)
1656 return xceaccess(path, mode);
1660 win32_chmod(const char *path, int mode)
1662 return xcechmod(path, mode);
1666 create_command_line(char *cname, STRLEN clen, const char * const *args)
1673 bool bat_file = FALSE;
1674 bool cmd_shell = FALSE;
1675 bool dumb_shell = FALSE;
1676 bool extra_quotes = FALSE;
1677 bool quote_next = FALSE;
1680 cname = (char*)args[0];
1682 /* The NT cmd.exe shell has the following peculiarity that needs to be
1683 * worked around. It strips a leading and trailing dquote when any
1684 * of the following is true:
1685 * 1. the /S switch was used
1686 * 2. there are more than two dquotes
1687 * 3. there is a special character from this set: &<>()@^|
1688 * 4. no whitespace characters within the two dquotes
1689 * 5. string between two dquotes isn't an executable file
1690 * To work around this, we always add a leading and trailing dquote
1691 * to the string, if the first argument is either "cmd.exe" or "cmd",
1692 * and there were at least two or more arguments passed to cmd.exe
1693 * (not including switches).
1694 * XXX the above rules (from "cmd /?") don't seem to be applied
1695 * always, making for the convolutions below :-(
1699 clen = strlen(cname);
1702 && (stricmp(&cname[clen-4], ".bat") == 0
1703 || (IsWinNT() && stricmp(&cname[clen-4], ".cmd") == 0)))
1709 char *exe = strrchr(cname, '/');
1710 char *exe2 = strrchr(cname, '\\');
1717 if (stricmp(exe, "cmd.exe") == 0 || stricmp(exe, "cmd") == 0) {
1721 else if (stricmp(exe, "command.com") == 0
1722 || stricmp(exe, "command") == 0)
1729 DEBUG_p(PerlIO_printf(Perl_debug_log, "Args "));
1730 for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
1731 STRLEN curlen = strlen(arg);
1732 if (!(arg[0] == '"' && arg[curlen-1] == '"'))
1733 len += 2; /* assume quoting needed (worst case) */
1735 DEBUG_p(PerlIO_printf(Perl_debug_log, "[%s]",arg));
1737 DEBUG_p(PerlIO_printf(Perl_debug_log, "\n"));
1740 Newx(cmd, len, char);
1745 extra_quotes = TRUE;
1748 for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
1750 STRLEN curlen = strlen(arg);
1752 /* we want to protect empty arguments and ones with spaces with
1753 * dquotes, but only if they aren't already there */
1758 else if (quote_next) {
1759 /* see if it really is multiple arguments pretending to
1760 * be one and force a set of quotes around it */
1761 if (*find_next_space(arg))
1764 else if (!(arg[0] == '"' && curlen > 1 && arg[curlen-1] == '"')) {
1766 while (i < curlen) {
1767 if (isSPACE(arg[i])) {
1770 else if (arg[i] == '"') {
1794 && *arg == '/' /* see if arg is "/c", "/x/c", "/x/d/c" etc. */
1795 && stricmp(arg+curlen-2, "/c") == 0)
1797 /* is there a next argument? */
1798 if (args[index+1]) {
1799 /* are there two or more next arguments? */
1800 if (args[index+2]) {
1802 extra_quotes = TRUE;
1805 /* single argument, force quoting if it has spaces */
1821 qualified_path(const char *cmd)
1825 char *fullcmd, *curfullcmd;
1831 fullcmd = (char*)cmd;
1833 if (*fullcmd == '/' || *fullcmd == '\\')
1840 pathstr = PerlEnv_getenv("PATH");
1841 Newx(fullcmd, MAX_PATH+1, char);
1842 curfullcmd = fullcmd;
1847 /* start by appending the name to the current prefix */
1848 strcpy(curfullcmd, cmd);
1849 curfullcmd += cmdlen;
1851 /* if it doesn't end with '.', or has no extension, try adding
1852 * a trailing .exe first */
1853 if (cmd[cmdlen-1] != '.'
1854 && (cmdlen < 4 || cmd[cmdlen-4] != '.'))
1856 strcpy(curfullcmd, ".exe");
1857 res = GetFileAttributes(fullcmd);
1858 if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
1863 /* that failed, try the bare name */
1864 res = GetFileAttributes(fullcmd);
1865 if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
1868 /* quit if no other path exists, or if cmd already has path */
1869 if (!pathstr || !*pathstr || has_slash)
1872 /* skip leading semis */
1873 while (*pathstr == ';')
1876 /* build a new prefix from scratch */
1877 curfullcmd = fullcmd;
1878 while (*pathstr && *pathstr != ';') {
1879 if (*pathstr == '"') { /* foo;"baz;etc";bar */
1880 pathstr++; /* skip initial '"' */
1881 while (*pathstr && *pathstr != '"') {
1882 if ((STRLEN)(curfullcmd-fullcmd) < MAX_PATH-cmdlen-5)
1883 *curfullcmd++ = *pathstr;
1887 pathstr++; /* skip trailing '"' */
1890 if ((STRLEN)(curfullcmd-fullcmd) < MAX_PATH-cmdlen-5)
1891 *curfullcmd++ = *pathstr;
1896 pathstr++; /* skip trailing semi */
1897 if (curfullcmd > fullcmd /* append a dir separator */
1898 && curfullcmd[-1] != '/' && curfullcmd[-1] != '\\')
1900 *curfullcmd++ = '\\';
1908 /* The following are just place holders.
1909 * Some hosts may provide and environment that the OS is
1910 * not tracking, therefore, these host must provide that
1911 * environment and the current directory to CreateProcess
1915 win32_get_childenv(void)
1921 win32_free_childenv(void* d)
1926 win32_clearenv(void)
1928 char *envv = GetEnvironmentStrings();
1932 char *end = strchr(cur,'=');
1933 if (end && end != cur) {
1935 xcesetenv(cur, "", 0);
1937 cur = end + strlen(end+1)+2;
1939 else if ((len = strlen(cur)))
1942 FreeEnvironmentStrings(envv);
1946 win32_get_childdir(void)
1950 char szfilename[MAX_PATH+1];
1951 GetCurrentDirectoryA(MAX_PATH+1, szfilename);
1953 Newx(ptr, strlen(szfilename)+1, char);
1954 strcpy(ptr, szfilename);
1959 win32_free_childdir(char* d)
1965 /* XXX this needs to be made more compatible with the spawnvp()
1966 * provided by the various RTLs. In particular, searching for
1967 * *.{com,bat,cmd} files (as done by the RTLs) is unimplemented.
1968 * This doesn't significantly affect perl itself, because we
1969 * always invoke things using PERL5SHELL if a direct attempt to
1970 * spawn the executable fails.
1972 * XXX splitting and rejoining the commandline between do_aspawn()
1973 * and win32_spawnvp() could also be avoided.
1977 win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
1979 #ifdef USE_RTL_SPAWNVP
1980 return spawnvp(mode, cmdname, (char * const *)argv);
1987 STARTUPINFO StartupInfo;
1988 PROCESS_INFORMATION ProcessInformation;
1991 char *fullcmd = NULL;
1992 char *cname = (char *)cmdname;
1996 clen = strlen(cname);
1997 /* if command name contains dquotes, must remove them */
1998 if (strchr(cname, '"')) {
2000 Newx(cname,clen+1,char);
2013 cmd = create_command_line(cname, clen, argv);
2015 env = PerlEnv_get_childenv();
2016 dir = PerlEnv_get_childdir();
2019 case P_NOWAIT: /* asynch + remember result */
2020 if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) {
2025 /* Create a new process group so we can use GenerateConsoleCtrlEvent()
2028 /* not supported on CE create |= CREATE_NEW_PROCESS_GROUP; */
2031 case P_WAIT: /* synchronous execution */
2033 default: /* invalid mode */
2038 memset(&StartupInfo,0,sizeof(StartupInfo));
2039 StartupInfo.cb = sizeof(StartupInfo);
2040 memset(&tbl,0,sizeof(tbl));
2041 PerlEnv_get_child_IO(&tbl);
2042 StartupInfo.dwFlags = tbl.dwFlags;
2043 StartupInfo.dwX = tbl.dwX;
2044 StartupInfo.dwY = tbl.dwY;
2045 StartupInfo.dwXSize = tbl.dwXSize;
2046 StartupInfo.dwYSize = tbl.dwYSize;
2047 StartupInfo.dwXCountChars = tbl.dwXCountChars;
2048 StartupInfo.dwYCountChars = tbl.dwYCountChars;
2049 StartupInfo.dwFillAttribute = tbl.dwFillAttribute;
2050 StartupInfo.wShowWindow = tbl.wShowWindow;
2051 StartupInfo.hStdInput = tbl.childStdIn;
2052 StartupInfo.hStdOutput = tbl.childStdOut;
2053 StartupInfo.hStdError = tbl.childStdErr;
2054 if (StartupInfo.hStdInput == INVALID_HANDLE_VALUE &&
2055 StartupInfo.hStdOutput == INVALID_HANDLE_VALUE &&
2056 StartupInfo.hStdError == INVALID_HANDLE_VALUE)
2058 create |= CREATE_NEW_CONSOLE;
2061 StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
2063 if (w32_use_showwindow) {
2064 StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
2065 StartupInfo.wShowWindow = w32_showwindow;
2068 DEBUG_p(PerlIO_printf(Perl_debug_log, "Spawning [%s] with [%s]\n",
2071 if (!CreateProcess(cname, /* search PATH to find executable */
2072 cmd, /* executable, and its arguments */
2073 NULL, /* process attributes */
2074 NULL, /* thread attributes */
2075 TRUE, /* inherit handles */
2076 create, /* creation flags */
2077 (LPVOID)env, /* inherit environment */
2078 dir, /* inherit cwd */
2080 &ProcessInformation))
2082 /* initial NULL argument to CreateProcess() does a PATH
2083 * search, but it always first looks in the directory
2084 * where the current process was started, which behavior
2085 * is undesirable for backward compatibility. So we
2086 * jump through our own hoops by picking out the path
2087 * we really want it to use. */
2089 fullcmd = qualified_path(cname);
2091 if (cname != cmdname)
2094 DEBUG_p(PerlIO_printf(Perl_debug_log,
2095 "Retrying [%s] with same args\n",
2105 if (mode == P_NOWAIT) {
2106 /* asynchronous spawn -- store handle, return PID */
2107 ret = (int)ProcessInformation.dwProcessId;
2108 if (IsWin95() && ret < 0)
2111 w32_child_handles[w32_num_children] = ProcessInformation.hProcess;
2112 w32_child_pids[w32_num_children] = (DWORD)ret;
2117 win32_msgwait(aTHX_ 1, &ProcessInformation.hProcess, INFINITE, NULL);
2118 /* FIXME: if msgwait returned due to message perhaps forward the
2119 "signal" to the process
2121 GetExitCodeProcess(ProcessInformation.hProcess, &status);
2123 CloseHandle(ProcessInformation.hProcess);
2126 CloseHandle(ProcessInformation.hThread);
2129 PerlEnv_free_childenv(env);
2130 PerlEnv_free_childdir(dir);
2132 if (cname != cmdname)
2139 win32_execv(const char *cmdname, const char *const *argv)
2142 Perl_croak(aTHX_ PL_no_func, "execv");
2147 win32_execvp(const char *cmdname, const char *const *argv)
2150 Perl_croak(aTHX_ PL_no_func, "execvp");
2155 win32_perror(const char *str)
2161 win32_setbuf(FILE *pf, char *buf)
2164 Perl_croak(aTHX_ PL_no_func, "setbuf");
2168 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
2170 return setvbuf(pf, buf, type, size);
2174 win32_flushall(void)
2180 win32_fcloseall(void)
2186 win32_fgets(char *s, int n, FILE *pf)
2188 return fgets(s, n, pf);
2198 win32_fgetc(FILE *pf)
2204 win32_putc(int c, FILE *pf)
2210 win32_puts(const char *s)
2222 win32_putchar(int c)
2229 #ifndef USE_PERL_SBRK
2231 static char *committed = NULL;
2232 static char *base = NULL;
2233 static char *reserved = NULL;
2234 static char *brk = NULL;
2235 static DWORD pagesize = 0;
2236 static DWORD allocsize = 0;
2244 GetSystemInfo(&info);
2245 /* Pretend page size is larger so we don't perpetually
2246 * call the OS to commit just one page ...
2248 pagesize = info.dwPageSize << 3;
2249 allocsize = info.dwAllocationGranularity;
2251 /* This scheme fails eventually if request for contiguous
2252 * block is denied so reserve big blocks - this is only
2253 * address space not memory ...
2255 if (brk+need >= reserved)
2257 DWORD size = 64*1024*1024;
2259 if (committed && reserved && committed < reserved)
2261 /* Commit last of previous chunk cannot span allocations */
2262 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
2264 committed = reserved;
2266 /* Reserve some (more) space
2267 * Note this is a little sneaky, 1st call passes NULL as reserved
2268 * so lets system choose where we start, subsequent calls pass
2269 * the old end address so ask for a contiguous block
2271 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
2274 reserved = addr+size;
2289 if (brk > committed)
2291 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
2292 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
2307 win32_malloc(size_t size)
2309 return malloc(size);
2313 win32_calloc(size_t numitems, size_t size)
2315 return calloc(numitems,size);
2319 win32_realloc(void *block, size_t size)
2321 return realloc(block,size);
2325 win32_free(void *block)
2331 win32_open_osfhandle(intptr_t osfhandle, int flags)
2334 char fileflags=0; /* _osfile flags */
2336 Perl_croak_nocontext("win32_open_osfhandle() TBD on this platform");
2341 win32_get_osfhandle(int fd)
2344 char fileflags=0; /* _osfile flags */
2346 Perl_croak_nocontext("win32_get_osfhandle() TBD on this platform");
2351 win32_fdupopen(FILE *pf)
2356 int fileno = win32_dup(win32_fileno(pf));
2357 int fmode = palm_fgetmode(pfdup);
2359 fprintf(stderr,"DEBUG for win32_fdupopen()\n");
2361 /* open the file in the same mode */
2362 if(fmode & O_RDONLY) {
2366 else if(fmode & O_APPEND) {
2370 else if(fmode & O_RDWR) {
2376 /* it appears that the binmode is attached to the
2377 * file descriptor so binmode files will be handled
2380 pfdup = win32_fdopen(fileno, mode);
2382 /* move the file pointer to the same position */
2383 if (!fgetpos(pf, &pos)) {
2384 fsetpos(pfdup, &pos);
2390 win32_dynaload(const char* filename)
2395 hModule = XCELoadLibraryA(filename);
2400 /* this is needed by Cwd.pm... */
2407 SV *sv = sv_newmortal();
2409 xcegetcwd(buf, sizeof(buf));
2411 sv_setpv(sv, xcestrdup(buf));
2415 #ifndef INCOMPLETE_TAINTS
2416 SvTAINTED_on(ST(0));
2427 Perl_croak(aTHX_ "usage: Win32::SetCwd($cwd)");
2429 if (!xcechdir(SvPV_nolen(ST(0))))
2436 XS(w32_GetTickCount)
2439 DWORD msec = GetTickCount();
2447 XS(w32_GetOSVersion)
2450 OSVERSIONINFOA osver;
2452 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
2453 if (!XCEGetVersionExA(&osver)) {
2456 mXPUSHp(osver.szCSDVersion, strlen(osver.szCSDVersion));
2457 mXPUSHi(osver.dwMajorVersion);
2458 mXPUSHi(osver.dwMinorVersion);
2459 mXPUSHi(osver.dwBuildNumber);
2461 mXPUSHi(osver.dwPlatformId);
2470 XSRETURN_IV(IsWinNT());
2478 XSRETURN_IV(IsWin95());
2486 XSRETURN_IV(IsWinCE());
2496 if(SystemParametersInfoW(SPI_GETOEMINFO, sizeof(wbuf), wbuf, FALSE))
2497 WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, sizeof(buf), 0, 0);
2499 sprintf(buf, "SystemParametersInfo failed: %d", GetLastError());
2510 Perl_croak(aTHX_ "usage: Win32::Sleep($milliseconds)");
2521 Perl_croak(aTHX_ "usage: Win32::CopyFile($from, $to, $overwrite)");
2524 char szSourceFile[MAX_PATH+1];
2525 strcpy(szSourceFile, PerlDir_mapA(SvPV_nolen(ST(0))));
2526 bResult = XCECopyFileA(szSourceFile, SvPV_nolen(ST(1)),
2543 unsigned int flags = MB_OK;
2545 txt = SvPV_nolen(ST(0));
2547 if (items < 1 || items > 2)
2548 Perl_croak(aTHX_ "usage: Win32::MessageBox($txt, [$flags])");
2551 flags = SvIV(ST(1));
2553 res = XCEMessageBoxA(NULL, txt, "Perl", flags);
2559 XS(w32_GetPowerStatus)
2563 SYSTEM_POWER_STATUS_EX sps;
2565 if(GetSystemPowerStatusEx(&sps, TRUE) == FALSE)
2570 mXPUSHi(sps.ACLineStatus);
2571 mXPUSHi(sps.BatteryFlag);
2572 mXPUSHi(sps.BatteryLifePercent);
2573 mXPUSHi(sps.BatteryLifeTime);
2574 mXPUSHi(sps.BatteryFullLifeTime);
2575 mXPUSHi(sps.BackupBatteryFlag);
2576 mXPUSHi(sps.BackupBatteryLifePercent);
2577 mXPUSHi(sps.BackupBatteryLifeTime);
2578 mXPUSHi(sps.BackupBatteryFullLifeTime);
2590 SHELLEXECUTEINFO si;
2592 wchar_t wfile[MAX_PATH];
2596 Perl_croak(aTHX_ "usage: Win32::ShellEx($file, $verb)");
2598 file = SvPV_nolen(ST(0));
2599 verb = SvPV_nolen(ST(1));
2601 memset(&si, 0, sizeof(si));
2602 si.cbSize = sizeof(si);
2603 si.fMask = SEE_MASK_FLAG_NO_UI;
2605 MultiByteToWideChar(CP_ACP, 0, verb, -1,
2606 wverb, sizeof(wverb)/2);
2607 si.lpVerb = (TCHAR *)wverb;
2609 MultiByteToWideChar(CP_ACP, 0, file, -1,
2610 wfile, sizeof(wfile)/2);
2611 si.lpFile = (TCHAR *)wfile;
2613 if(ShellExecuteEx(&si) == FALSE)
2622 Perl_init_os_extras(void)
2625 char *file = __FILE__;
2628 w32_perlshell_tokens = NULL;
2629 w32_perlshell_items = -1;
2630 w32_fdpid = newAV(); /* XX needs to be in Perl_win32_init()? */
2631 Newx(w32_children, 1, child_tab);
2632 w32_num_children = 0;
2634 newXS("Win32::GetCwd", w32_GetCwd, file);
2635 newXS("Win32::SetCwd", w32_SetCwd, file);
2636 newXS("Win32::GetTickCount", w32_GetTickCount, file);
2637 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
2639 newXS("Win32::ShellEx", w32_ShellEx, file);
2641 newXS("Win32::IsWinNT", w32_IsWinNT, file);
2642 newXS("Win32::IsWin95", w32_IsWin95, file);
2643 newXS("Win32::IsWinCE", w32_IsWinCE, file);
2644 newXS("Win32::CopyFile", w32_CopyFile, file);
2645 newXS("Win32::Sleep", w32_Sleep, file);
2646 newXS("Win32::MessageBox", w32_MessageBox, file);
2647 newXS("Win32::GetPowerStatus", w32_GetPowerStatus, file);
2648 newXS("Win32::GetOemInfo", w32_GetOemInfo, file);
2657 fgets(buf, sizeof(buf), stdin);
2661 Perl_win32_init(int *argcp, char ***argvp)
2666 if((p = xcegetenv("PERLDEBUG")) && (p[0] == 'y' || p[0] == 'Y'))
2674 Perl_win32_term(void)
2684 win32_get_child_IO(child_IO_table* ptbl)
2686 ptbl->childStdIn = GetStdHandle(STD_INPUT_HANDLE);
2687 ptbl->childStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
2688 ptbl->childStdErr = GetStdHandle(STD_ERROR_HANDLE);
2691 win32_flock(int fd, int oper)
2694 Perl_croak(aTHX_ PL_no_func, "flock");
2699 win32_waitpid(int pid, int *status, int flags)
2702 Perl_croak(aTHX_ PL_no_func, "waitpid");
2707 win32_wait(int *status)
2710 Perl_croak(aTHX_ PL_no_func, "wait");
2715 wce_reopen_stdout(char *fname)
2717 if(xcefreopen(fname, "w", stdout) == NULL)
2728 printf("Hit RETURN");
2730 fgets(buf, sizeof(buf), stdin);
2734 /* //////////////////////////////////////////////////////////////////// */
2739 getcwd(char *buf, size_t size)
2741 return xcegetcwd(buf, size);
2752 win32_popenlist(const char *mode, IV narg, SV **args)
2755 Perl_croak(aTHX_ "List form of pipe open not implemented");
2760 * a popen() clone that respects PERL5SHELL
2762 * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
2766 win32_popen(const char *command, const char *mode)
2768 return _popen(command, mode);
2776 win32_pclose(PerlIO *pf)
2781 #ifdef HAVE_INTERP_INTERN
2785 win32_csighandler(int sig)
2788 dTHXa(PERL_GET_SIG_CONTEXT);
2789 Perl_warn(aTHX_ "Got signal %d",sig);
2795 Perl_sys_intern_init(pTHX)
2798 w32_perlshell_tokens = NULL;
2799 w32_perlshell_vec = (char**)NULL;
2800 w32_perlshell_items = 0;
2801 w32_fdpid = newAV();
2802 Newx(w32_children, 1, child_tab);
2803 w32_num_children = 0;
2804 # ifdef USE_ITHREADS
2806 Newx(w32_pseudo_children, 1, child_tab);
2807 w32_num_pseudo_children = 0;
2809 w32_init_socktype = 0;
2815 Perl_sys_intern_clear(pTHX)
2817 Safefree(w32_perlshell_tokens);
2818 Safefree(w32_perlshell_vec);
2819 /* NOTE: w32_fdpid is freed by sv_clean_all() */
2820 Safefree(w32_children);
2822 KillTimer(NULL,w32_timerid);
2825 # ifdef USE_ITHREADS
2826 Safefree(w32_pseudo_children);
2830 # ifdef USE_ITHREADS
2833 Perl_sys_intern_dup(pTHX_ struct interp_intern *src, struct interp_intern *dst)
2835 dst->perlshell_tokens = NULL;
2836 dst->perlshell_vec = (char**)NULL;
2837 dst->perlshell_items = 0;
2838 dst->fdpid = newAV();
2839 Newxz(dst->children, 1, child_tab);
2841 Newxz(dst->pseudo_children, 1, child_tab);
2842 dst->thr_intern.Winit_socktype = 0;
2844 dst->poll_count = 0;
2845 Copy(src->sigtable,dst->sigtable,SIG_SIZE,Sighandler_t);
2847 # endif /* USE_ITHREADS */
2848 #endif /* HAVE_INTERP_INTERN */
2850 // added to remove undefied symbol error in CodeWarrior compilation
2852 Perl_Ireentrant_buffer_ptr(aTHX)