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
13 #define PERLIO_NOT_STDIO 0
15 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
26 #define PERL_NO_GET_CONTEXT
36 #include "celib_defs.h"
39 #include "cewin32_defs.h"
40 #include "cecrt_defs.h"
43 #include "stdio-palmsize.h"
48 #define EXECF_SPAWN_NOWAIT 3
50 #if defined(PERL_IMPLICIT_SYS)
51 # undef win32_get_privlib
52 # define win32_get_privlib g_win32_get_privlib
53 # undef win32_get_sitelib
54 # define win32_get_sitelib g_win32_get_sitelib
55 # undef win32_get_vendorlib
56 # define win32_get_vendorlib g_win32_get_vendorlib
58 # define do_spawn g_do_spawn
60 # define getlogin g_getlogin
63 static long filetime_to_clock(PFILETIME ft);
64 static BOOL filetime_from_time(PFILETIME ft, time_t t);
65 static char * get_emd_part(SV **leading, char *trailing, ...);
66 static char * win32_get_xlib(const char *pl, const char *xlib,
70 HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE;
71 char w32_module_name[MAX_PATH+1];
74 static DWORD w32_platform = (DWORD)-1;
79 return (win32_os_id() == VER_PLATFORM_WIN32_WINDOWS);
85 return (win32_os_id() == VER_PLATFORM_WIN32_NT);
91 return (win32_os_id() == VER_PLATFORM_WIN32_CE);
95 set_w32_module_name(void)
98 XCEGetModuleFileNameA((HMODULE)((w32_perldll_handle == INVALID_HANDLE_VALUE)
99 ? XCEGetModuleHandleA(NULL)
100 : w32_perldll_handle),
101 w32_module_name, sizeof(w32_module_name));
103 /* normalize to forward slashes */
104 ptr = w32_module_name;
112 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
114 get_regstr_from(HKEY hkey, const char *valuename, SV **svp)
116 /* Retrieve a REG_SZ or REG_EXPAND_SZ from the registry */
119 const char *subkey = "Software\\Perl";
123 retval = XCERegOpenKeyExA(hkey, subkey, 0, KEY_READ, &handle);
124 if (retval == ERROR_SUCCESS) {
126 retval = XCERegQueryValueExA(handle, valuename, 0, &type, NULL, &datalen);
127 if (retval == ERROR_SUCCESS && type == REG_SZ) {
130 *svp = sv_2mortal(newSVpvn("",0));
131 SvGROW(*svp, datalen);
132 retval = XCERegQueryValueExA(handle, valuename, 0, NULL,
133 (PBYTE)SvPVX(*svp), &datalen);
134 if (retval == ERROR_SUCCESS) {
136 SvCUR_set(*svp,datalen-1);
144 /* *svp (if non-NULL) is expected to be POK (valid allocated SvPVX(*svp)) */
146 get_regstr(const char *valuename, SV **svp)
148 char *str = get_regstr_from(HKEY_CURRENT_USER, valuename, svp);
150 str = get_regstr_from(HKEY_LOCAL_MACHINE, valuename, svp);
154 /* *prev_pathp (if non-NULL) is expected to be POK (valid allocated SvPVX(sv)) */
156 get_emd_part(SV **prev_pathp, char *trailing_path, ...)
160 char mod_name[MAX_PATH+1];
164 int oldsize, newsize;
167 va_start(ap, trailing_path);
168 strip = va_arg(ap, char *);
170 sprintf(base, "%d.%d", (int)PERL_REVISION, (int)PERL_VERSION);
171 baselen = strlen(base);
173 if (!*w32_module_name) {
174 set_w32_module_name();
176 strcpy(mod_name, w32_module_name);
177 ptr = strrchr(mod_name, '/');
178 while (ptr && strip) {
179 /* look for directories to skip back */
182 ptr = strrchr(mod_name, '/');
183 /* avoid stripping component if there is no slash,
184 * or it doesn't match ... */
185 if (!ptr || stricmp(ptr+1, strip) != 0) {
186 /* ... but not if component matches m|5\.$patchlevel.*| */
187 if (!ptr || !(*strip == '5' && *(ptr+1) == '5'
188 && strncmp(strip, base, baselen) == 0
189 && strncmp(ptr+1, base, baselen) == 0))
195 strip = va_arg(ap, char *);
203 strcpy(++ptr, trailing_path);
205 /* only add directory if it exists */
206 if (XCEGetFileAttributesA(mod_name) != (DWORD) -1) {
207 /* directory exists */
210 *prev_pathp = sv_2mortal(newSVpvn("",0));
211 sv_catpvn(*prev_pathp, ";", 1);
212 sv_catpv(*prev_pathp, mod_name);
213 return SvPVX(*prev_pathp);
220 win32_get_privlib(const char *pl)
223 char *stdlib = "lib";
224 char buffer[MAX_PATH+1];
227 /* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
228 sprintf(buffer, "%s-%s", stdlib, pl);
229 if (!get_regstr(buffer, &sv))
230 (void)get_regstr(stdlib, &sv);
232 /* $stdlib .= ";$EMD/../../lib" */
233 return get_emd_part(&sv, stdlib, ARCHNAME, "bin", Nullch);
237 win32_get_xlib(const char *pl, const char *xlib, const char *libname)
241 char pathstr[MAX_PATH+1];
247 /* $HKCU{"$xlib-$]"} || $HKLM{"$xlib-$]"} . ---; */
248 sprintf(regstr, "%s-%s", xlib, pl);
249 (void)get_regstr(regstr, &sv1);
252 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/$]/lib"; */
253 sprintf(pathstr, "%s/%s/lib", libname, pl);
254 (void)get_emd_part(&sv1, pathstr, ARCHNAME, "bin", pl, Nullch);
256 /* $HKCU{$xlib} || $HKLM{$xlib} . ---; */
257 (void)get_regstr(xlib, &sv2);
260 * ";$EMD/" . ((-d $EMD/../../../$]) ? "../../.." : "../.."). "/$libname/lib"; */
261 sprintf(pathstr, "%s/lib", libname);
262 (void)get_emd_part(&sv2, pathstr, ARCHNAME, "bin", pl, Nullch);
271 sv_catpvn(sv1, ";", 1);
278 win32_get_sitelib(const char *pl)
280 return win32_get_xlib(pl, "sitelib", "site");
283 #ifndef PERL_VENDORLIB_NAME
284 # define PERL_VENDORLIB_NAME "vendor"
288 win32_get_vendorlib(const char *pl)
290 return win32_get_xlib(pl, "vendorlib", PERL_VENDORLIB_NAME);
293 #if !defined(PERL_IMPLICIT_SYS)
294 /* since the current process environment is being updated in util.c
295 * the library functions will get the correct environment
298 Perl_my_popen(pTHX_ char *cmd, char *mode)
300 printf("popen(%s)\n", cmd);
302 Perl_croak(aTHX_ PL_no_func, "popen");
307 Perl_my_pclose(pTHX_ PerlIO *fp)
309 Perl_croak(aTHX_ PL_no_func, "pclose");
314 DllExport unsigned long
317 static OSVERSIONINFOA osver;
319 if (osver.dwPlatformId != w32_platform) {
320 memset(&osver, 0, sizeof(OSVERSIONINFOA));
321 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
322 XCEGetVersionExA(&osver);
323 w32_platform = osver.dwPlatformId;
325 return (unsigned long)w32_platform;
335 Perl_do_exec(pTHX_ char *cmd)
337 Perl_croak_nocontext("exec() unimplemented on this platform");
342 win32_pipe(int *pfd, unsigned int size, int mode)
344 Perl_croak(aTHX_ PL_no_func, "pipe");
349 win32_times(struct tms *timebuf)
351 Perl_croak(aTHX_ PL_no_func, "times");
359 Perl_croak_nocontext("signal() TBD on this platform");
376 win32_opendir(char *filename)
378 return opendir(filename);
381 DllExport struct direct *
382 win32_readdir(DIR *dirp)
384 return readdir(dirp);
388 win32_telldir(DIR *dirp)
390 Perl_croak(aTHX_ PL_no_func, "telldir");
395 win32_seekdir(DIR *dirp, long loc)
397 Perl_croak(aTHX_ PL_no_func, "seekdir");
401 win32_rewinddir(DIR *dirp)
403 Perl_croak(aTHX_ PL_no_func, "rewinddir");
407 win32_closedir(DIR *dirp)
414 win32_kill(int pid, int sig)
416 Perl_croak(aTHX_ PL_no_func, "kill");
420 DllExport unsigned int
421 win32_sleep(unsigned int t)
427 win32_stat(const char *path, struct stat *sbuf)
429 return xcestat(path, sbuf);
433 win32_longpath(char *path)
438 #ifndef USE_WIN32_RTL_ENV
441 win32_getenv(const char *name)
443 return xcegetenv(name);
447 win32_putenv(const char *name)
449 return xceputenv(name);
455 filetime_to_clock(PFILETIME ft)
457 __int64 qw = ft->dwHighDateTime;
459 qw |= ft->dwLowDateTime;
460 qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
464 /* fix utime() so it works on directories in NT */
466 filetime_from_time(PFILETIME pFileTime, time_t Time)
468 struct tm *pTM = localtime(&Time);
469 SYSTEMTIME SystemTime;
475 SystemTime.wYear = pTM->tm_year + 1900;
476 SystemTime.wMonth = pTM->tm_mon + 1;
477 SystemTime.wDay = pTM->tm_mday;
478 SystemTime.wHour = pTM->tm_hour;
479 SystemTime.wMinute = pTM->tm_min;
480 SystemTime.wSecond = pTM->tm_sec;
481 SystemTime.wMilliseconds = 0;
483 return SystemTimeToFileTime(&SystemTime, &LocalTime) &&
484 LocalFileTimeToFileTime(&LocalTime, pFileTime);
488 win32_unlink(const char *filename)
490 return xceunlink(filename);
494 win32_utime(const char *filename, struct utimbuf *times)
496 return xceutime(filename, (struct _utimbuf *) times);
500 win32_uname(struct utsname *name)
503 STRLEN nodemax = sizeof(name->nodename)-1;
504 OSVERSIONINFOA osver;
506 memset(&osver, 0, sizeof(OSVERSIONINFOA));
507 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
508 if (XCEGetVersionExA(&osver)) {
510 switch (osver.dwPlatformId) {
511 case VER_PLATFORM_WIN32_CE:
512 strcpy(name->sysname, "Windows CE");
514 case VER_PLATFORM_WIN32_WINDOWS:
515 strcpy(name->sysname, "Windows");
517 case VER_PLATFORM_WIN32_NT:
518 strcpy(name->sysname, "Windows NT");
520 case VER_PLATFORM_WIN32s:
521 strcpy(name->sysname, "Win32s");
524 strcpy(name->sysname, "Win32 Unknown");
529 sprintf(name->release, "%d.%d",
530 osver.dwMajorVersion, osver.dwMinorVersion);
533 sprintf(name->version, "Build %d",
534 osver.dwPlatformId == VER_PLATFORM_WIN32_NT
535 ? osver.dwBuildNumber : (osver.dwBuildNumber & 0xffff));
536 if (osver.szCSDVersion[0]) {
537 char *buf = name->version + strlen(name->version);
538 sprintf(buf, " (%s)", osver.szCSDVersion);
542 *name->sysname = '\0';
543 *name->version = '\0';
544 *name->release = '\0';
548 hep = win32_gethostbyname("localhost");
550 STRLEN len = strlen(hep->h_name);
551 if (len <= nodemax) {
552 strcpy(name->nodename, hep->h_name);
555 strncpy(name->nodename, hep->h_name, nodemax);
556 name->nodename[nodemax] = '\0';
561 if (!XCEGetComputerNameA(name->nodename, &sz))
562 *name->nodename = '\0';
565 /* machine (architecture) */
569 GetSystemInfo(&info);
571 switch (info.wProcessorArchitecture) {
572 case PROCESSOR_ARCHITECTURE_INTEL:
574 case PROCESSOR_ARCHITECTURE_MIPS:
575 arch = "mips"; break;
576 case PROCESSOR_ARCHITECTURE_ALPHA:
577 arch = "alpha"; break;
578 case PROCESSOR_ARCHITECTURE_PPC:
580 case PROCESSOR_ARCHITECTURE_ARM:
582 case PROCESSOR_HITACHI_SH3:
584 case PROCESSOR_SHx_SH3:
588 arch = "unknown"; break;
590 strcpy(name->machine, arch);
595 static UINT timerid = 0;
597 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
600 KillTimer(NULL,timerid);
605 DllExport unsigned int
606 win32_alarm(unsigned int sec)
609 * the 'obvious' implentation is SetTimer() with a callback
610 * which does whatever receiving SIGALRM would do
611 * we cannot use SIGALRM even via raise() as it is not
612 * one of the supported codes in <signal.h>
614 * Snag is unless something is looking at the message queue
615 * nothing happens :-(
620 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
622 Perl_croak_nocontext("Cannot set timer");
628 KillTimer(NULL,timerid);
635 #ifdef HAVE_DES_FCRYPT
636 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
640 win32_crypt(const char *txt, const char *salt)
643 #ifdef HAVE_DES_FCRYPT
645 return des_fcrypt(txt, salt, w32_crypt_buffer);
647 Perl_croak(aTHX_ "The crypt() function is unimplemented due to excessive paranoia.");
652 /* C doesn't like repeat struct definitions */
654 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
657 #define _CRTIMP __declspec(dllimport)
661 * Control structure for lowio file handles
664 long osfhnd; /* underlying OS file HANDLE */
665 char osfile; /* attributes of file (e.g., open in text mode?) */
666 char pipech; /* one char buffer for handles opened on pipes */
668 CRITICAL_SECTION lock;
673 * Array of arrays of control structures for lowio files.
675 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
678 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
679 * array of ioinfo structs.
684 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
686 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
689 * Access macros for getting at an ioinfo struct and its fields from a
692 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
693 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
694 #define _osfile(i) (_pioinfo(i)->osfile)
695 #define _pipech(i) (_pioinfo(i)->pipech)
700 * redirected io subsystem for all XS modules
710 /* the rest are the remapped stdio routines */
730 win32_ferror(FILE *fp)
743 * Since the errors returned by the socket error function
744 * WSAGetLastError() are not known by the library routine strerror
745 * we have to roll our own.
749 win32_strerror(int e)
751 return xcestrerror(e);
755 win32_str_os_error(void *sv, DWORD dwErr)
759 sv_setpvn((SV*)sv, "Error", 5);
764 win32_fprintf(FILE *fp, const char *format, ...)
767 va_start(marker, format); /* Initialize variable arguments. */
769 return (vfprintf(fp, format, marker));
773 win32_printf(const char *format, ...)
776 va_start(marker, format); /* Initialize variable arguments. */
778 return (vprintf(format, marker));
782 win32_vfprintf(FILE *fp, const char *format, va_list args)
784 return (vfprintf(fp, format, args));
788 win32_vprintf(const char *format, va_list args)
790 return (vprintf(format, args));
794 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
796 return fread(buf, size, count, fp);
800 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
802 return fwrite(buf, size, count, fp);
806 win32_fopen(const char *filename, const char *mode)
808 return xcefopen(filename, mode);
812 win32_fdopen(int handle, const char *mode)
814 return palm_fdopen(handle, mode);
818 win32_freopen(const char *path, const char *mode, FILE *stream)
820 return xcefreopen(path, mode, stream);
824 win32_fclose(FILE *pf)
826 return xcefclose(pf);
830 win32_fputs(const char *s,FILE *pf)
836 win32_fputc(int c,FILE *pf)
842 win32_ungetc(int c,FILE *pf)
854 win32_fileno(FILE *pf)
856 return palm_fileno(pf);
860 win32_clearerr(FILE *pf)
867 win32_fflush(FILE *pf)
873 win32_ftell(FILE *pf)
879 win32_fseek(FILE *pf,long offset,int origin)
881 return fseek(pf, offset, origin);
884 /* fpos_t seems to be int64 on hpc pro! Really stupid. */
885 /* But maybe someday there will be such large disks in a hpc... */
887 win32_fgetpos(FILE *pf, fpos_t *p)
889 return fgetpos(pf, p);
893 win32_fsetpos(FILE *pf, const fpos_t *p)
895 return fsetpos(pf, p);
899 win32_rewind(FILE *pf)
901 fseek(pf, 0, SEEK_SET);
908 Perl_croak(aTHX_ PL_no_func, "tmpfile");
922 win32_fstat(int fd, struct stat *sbufptr)
924 return xcefstat(fd, sbufptr);
928 win32_link(const char *oldname, const char *newname)
930 Perl_croak(aTHX_ PL_no_func, "link");
936 win32_rename(const char *oname, const char *newname)
938 return xcerename(oname, newname);
942 win32_setmode(int fd, int mode)
946 Perl_croak(aTHX_ PL_no_func, "setmode");
953 win32_lseek(int fd, long offset, int origin)
955 return xcelseek(fd, offset, origin);
961 return xcelseek(fd, 0, SEEK_CUR);
965 win32_open(const char *path, int flag, ...)
971 pmode = va_arg(ap, int);
974 return xceopen(path, flag, pmode);
986 Perl_croak(aTHX_ PL_no_func, "eof");
993 Perl_croak(aTHX_ PL_no_func, "dup");
998 win32_dup2(int fd1,int fd2)
1000 Perl_croak(aTHX_ PL_no_func, "dup2");
1005 win32_read(int fd, void *buf, unsigned int cnt)
1007 return xceread(fd, buf, cnt);
1011 win32_write(int fd, const void *buf, unsigned int cnt)
1013 return xcewrite(fd, (void *) buf, cnt);
1017 win32_mkdir(const char *dir, int mode)
1019 return xcemkdir(dir);
1023 win32_rmdir(const char *dir)
1025 return xcermdir(dir);
1029 win32_chdir(const char *dir)
1031 return xcechdir(dir);
1035 win32_access(const char *path, int mode)
1037 return xceaccess(path, mode);
1041 win32_chmod(const char *path, int mode)
1043 return xcechmod(path, mode);
1047 win32_perror(const char *str)
1053 win32_setbuf(FILE *pf, char *buf)
1055 Perl_croak(aTHX_ PL_no_func, "setbuf");
1059 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1061 return setvbuf(pf, buf, type, size);
1065 win32_flushall(void)
1071 win32_fcloseall(void)
1077 win32_fgets(char *s, int n, FILE *pf)
1079 return fgets(s, n, pf);
1089 win32_fgetc(FILE *pf)
1095 win32_putc(int c, FILE *pf)
1101 win32_puts(const char *s)
1113 win32_putchar(int c)
1120 #ifndef USE_PERL_SBRK
1122 static char *committed = NULL;
1123 static char *base = NULL;
1124 static char *reserved = NULL;
1125 static char *brk = NULL;
1126 static DWORD pagesize = 0;
1127 static DWORD allocsize = 0;
1135 GetSystemInfo(&info);
1136 /* Pretend page size is larger so we don't perpetually
1137 * call the OS to commit just one page ...
1139 pagesize = info.dwPageSize << 3;
1140 allocsize = info.dwAllocationGranularity;
1142 /* This scheme fails eventually if request for contiguous
1143 * block is denied so reserve big blocks - this is only
1144 * address space not memory ...
1146 if (brk+need >= reserved)
1148 DWORD size = 64*1024*1024;
1150 if (committed && reserved && committed < reserved)
1152 /* Commit last of previous chunk cannot span allocations */
1153 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
1155 committed = reserved;
1157 /* Reserve some (more) space
1158 * Note this is a little sneaky, 1st call passes NULL as reserved
1159 * so lets system choose where we start, subsequent calls pass
1160 * the old end address so ask for a contiguous block
1162 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
1165 reserved = addr+size;
1180 if (brk > committed)
1182 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
1183 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
1198 win32_malloc(size_t size)
1200 return malloc(size);
1204 win32_calloc(size_t numitems, size_t size)
1206 return calloc(numitems,size);
1210 win32_realloc(void *block, size_t size)
1212 return realloc(block,size);
1216 win32_free(void *block)
1222 win32_execv(const char *cmdname, const char *const *argv)
1224 Perl_croak(aTHX_ PL_no_func, "execv");
1229 win32_execvp(const char *cmdname, const char *const *argv)
1231 Perl_croak(aTHX_ PL_no_func, "execvp");
1236 win32_dynaload(const char* filename)
1241 hModule = XCELoadLibraryA(filename);
1246 /* this is needed by Cwd.pm... */
1253 SV *sv = sv_newmortal();
1255 xcegetcwd(buf, sizeof(buf));
1257 sv_setpv(sv, xcestrdup(buf));
1261 #ifndef INCOMPLETE_TAINTS
1262 SvTAINTED_on(ST(0));
1273 Perl_croak(aTHX_ "usage: Win32::SetCwd($cwd)");
1275 if (!xcechdir(SvPV_nolen(ST(0))))
1282 XS(w32_GetTickCount)
1285 DWORD msec = GetTickCount();
1293 XS(w32_GetOSVersion)
1296 OSVERSIONINFOA osver;
1298 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
1299 if (!XCEGetVersionExA(&osver)) {
1302 XPUSHs(newSVpvn(osver.szCSDVersion, strlen(osver.szCSDVersion)));
1303 XPUSHs(newSViv(osver.dwMajorVersion));
1304 XPUSHs(newSViv(osver.dwMinorVersion));
1305 XPUSHs(newSViv(osver.dwBuildNumber));
1307 XPUSHs(newSViv(osver.dwPlatformId));
1316 XSRETURN_IV(IsWinNT());
1324 XSRETURN_IV(IsWin95());
1332 XSRETURN_IV(IsWinCE());
1342 if(SystemParametersInfoW(SPI_GETOEMINFO, sizeof(wbuf), wbuf, FALSE))
1343 WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, sizeof(buf), 0, 0);
1345 sprintf(buf, "SystemParametersInfo failed: %d", GetLastError());
1356 Perl_croak(aTHX_ "usage: Win32::Sleep($milliseconds)");
1367 Perl_croak(aTHX_ "usage: Win32::CopyFile($from, $to, $overwrite)");
1370 char szSourceFile[MAX_PATH+1];
1371 strcpy(szSourceFile, PerlDir_mapA(SvPV_nolen(ST(0))));
1372 bResult = XCECopyFileA(szSourceFile, SvPV_nolen(ST(1)),
1389 unsigned int flags = MB_OK;
1391 txt = SvPV_nolen(ST(0));
1393 if (items < 1 || items > 2)
1394 Perl_croak(aTHX_ "usage: Win32::MessageBox($txt, [$flags])");
1397 flags = SvIV(ST(1));
1399 res = XCEMessageBoxA(NULL, txt, "Perl", flags);
1405 XS(w32_GetPowerStatus)
1409 SYSTEM_POWER_STATUS_EX sps;
1411 if(GetSystemPowerStatusEx(&sps, TRUE) == FALSE)
1416 XPUSHs(newSViv(sps.ACLineStatus));
1417 XPUSHs(newSViv(sps.BatteryFlag));
1418 XPUSHs(newSViv(sps.BatteryLifePercent));
1419 XPUSHs(newSViv(sps.BatteryLifeTime));
1420 XPUSHs(newSViv(sps.BatteryFullLifeTime));
1421 XPUSHs(newSViv(sps.BackupBatteryFlag));
1422 XPUSHs(newSViv(sps.BackupBatteryLifePercent));
1423 XPUSHs(newSViv(sps.BackupBatteryLifeTime));
1424 XPUSHs(newSViv(sps.BackupBatteryFullLifeTime));
1436 SHELLEXECUTEINFO si;
1438 wchar_t wfile[MAX_PATH];
1442 Perl_croak(aTHX_ "usage: Win32::ShellEx($file, $verb)");
1444 file = SvPV_nolen(ST(0));
1445 verb = SvPV_nolen(ST(1));
1447 memset(&si, 0, sizeof(si));
1448 si.cbSize = sizeof(si);
1449 si.fMask = SEE_MASK_FLAG_NO_UI;
1451 MultiByteToWideChar(CP_ACP, 0, verb, -1,
1452 wverb, sizeof(wverb)/2);
1453 si.lpVerb = (TCHAR *)wverb;
1455 MultiByteToWideChar(CP_ACP, 0, file, -1,
1456 wfile, sizeof(wfile)/2);
1457 si.lpFile = (TCHAR *)wfile;
1459 if(ShellExecuteEx(&si) == FALSE)
1468 Perl_init_os_extras(void)
1471 char *file = __FILE__;
1474 w32_perlshell_tokens = Nullch;
1475 w32_perlshell_items = -1;
1476 w32_fdpid = newAV(); /* XX needs to be in Perl_win32_init()? */
1477 New(1313, w32_children, 1, child_tab);
1478 w32_num_children = 0;
1480 newXS("Win32::GetCwd", w32_GetCwd, file);
1481 newXS("Win32::SetCwd", w32_SetCwd, file);
1482 newXS("Win32::GetTickCount", w32_GetTickCount, file);
1483 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
1485 newXS("Win32::ShellEx", w32_ShellEx, file);
1487 newXS("Win32::IsWinNT", w32_IsWinNT, file);
1488 newXS("Win32::IsWin95", w32_IsWin95, file);
1489 newXS("Win32::IsWinCE", w32_IsWinCE, file);
1490 newXS("Win32::CopyFile", w32_CopyFile, file);
1491 newXS("Win32::Sleep", w32_Sleep, file);
1492 newXS("Win32::MessageBox", w32_MessageBox, file);
1493 newXS("Win32::GetPowerStatus", w32_GetPowerStatus, file);
1494 newXS("Win32::GetOemInfo", w32_GetOemInfo, file);
1503 fgets(buf, sizeof(buf), stdin);
1507 Perl_win32_init(int *argcp, char ***argvp)
1512 if((p = xcegetenv("PERLDEBUG")) && (p[0] == 'y' || p[0] == 'Y'))
1520 win32_flock(int fd, int oper)
1522 Perl_croak(aTHX_ PL_no_func, "flock");
1527 win32_waitpid(int pid, int *status, int flags)
1529 Perl_croak(aTHX_ PL_no_func, "waitpid");
1534 win32_wait(int *status)
1536 Perl_croak(aTHX_ PL_no_func, "wait");
1543 return xcesystem(cmd);
1547 do_aspawn(void *vreally, void **vmark, void **vsp)
1549 Perl_croak(aTHX_ PL_no_func, "aspawn");
1554 wce_reopen_stdout(char *fname)
1556 if(xcefreopen(fname, "w", stdout) == NULL)
1567 printf("Hit RETURN");
1569 fgets(buf, sizeof(buf), stdin);
1573 /* //////////////////////////////////////////////////////////////////// */
1576 win32_argv2utf8(int argc, char** argv)
1582 Perl_sys_intern_init(pTHX)
1584 w32_perlshell_tokens = Nullch;
1585 w32_perlshell_vec = (char**)NULL;
1586 w32_perlshell_items = 0;
1587 w32_fdpid = newAV();
1588 New(1313, w32_children, 1, child_tab);
1589 w32_num_children = 0;
1590 # ifdef USE_ITHREADS
1592 New(1313, w32_pseudo_children, 1, child_tab);
1593 w32_num_pseudo_children = 0;
1597 w32_init_socktype = 0;
1602 Perl_sys_intern_clear(pTHX)
1604 Safefree(w32_perlshell_tokens);
1605 Safefree(w32_perlshell_vec);
1606 /* NOTE: w32_fdpid is freed by sv_clean_all() */
1607 Safefree(w32_children);
1608 # ifdef USE_ITHREADS
1609 Safefree(w32_pseudo_children);
1613 /* //////////////////////////////////////////////////////////////////// */
1618 getcwd(char *buf, size_t size)
1620 return xcegetcwd(buf, size);
1630 win32_open_osfhandle(intptr_t osfhandle, int flags)
1633 char fileflags=0; /* _osfile flags */
1635 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_open_osfhandle)", "error", 0);
1636 Perl_croak_nocontext("win32_open_osfhandle() TBD on this platform");
1641 win32_get_osfhandle(intptr_t osfhandle, int flags)
1644 char fileflags=0; /* _osfile flags */
1646 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_get_osfhandle)", "error", 0);
1647 Perl_croak_nocontext("win32_get_osfhandle() TBD on this platform");
1652 * a popen() clone that respects PERL5SHELL
1654 * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
1658 win32_popen(const char *command, const char *mode)
1660 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_popen)", "error", 0);
1661 Perl_croak_nocontext("win32_popen() TBD on this platform");
1669 win32_pclose(PerlIO *pf)
1671 #ifdef USE_RTL_POPEN
1675 int childpid, status;
1679 sv = *av_fetch(w32_fdpid, PerlIO_fileno(pf), TRUE);
1682 childpid = SvIVX(sv);
1699 if (win32_waitpid(childpid, &status, 0) == -1)
1704 #endif /* USE_RTL_POPEN */
1708 win32_fdupopen(FILE *pf)
1713 int fileno = win32_dup(win32_fileno(pf));
1715 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in .../wince/wince.c(win32_fdupopen)", "Perl(developer)", 0);
1716 Perl_croak_nocontext("win32_fdupopen() TBD on this platform");
1719 /* open the file in the same mode */
1720 if((pf)->_flag & _IOREAD) {
1724 else if((pf)->_flag & _IOWRT) {
1728 else if((pf)->_flag & _IORW) {
1734 /* it appears that the binmode is attached to the
1735 * file descriptor so binmode files will be handled
1738 pfdup = win32_fdopen(fileno, mode);
1740 /* move the file pointer to the same position */
1741 if (!fgetpos(pf, &pos)) {
1742 fsetpos(pfdup, &pos);