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_gettimeofday(struct timeval *tp, void *not_used)
502 return xcegettimeofday(tp,not_used);
506 win32_uname(struct utsname *name)
509 STRLEN nodemax = sizeof(name->nodename)-1;
510 OSVERSIONINFOA osver;
512 memset(&osver, 0, sizeof(OSVERSIONINFOA));
513 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
514 if (XCEGetVersionExA(&osver)) {
516 switch (osver.dwPlatformId) {
517 case VER_PLATFORM_WIN32_CE:
518 strcpy(name->sysname, "Windows CE");
520 case VER_PLATFORM_WIN32_WINDOWS:
521 strcpy(name->sysname, "Windows");
523 case VER_PLATFORM_WIN32_NT:
524 strcpy(name->sysname, "Windows NT");
526 case VER_PLATFORM_WIN32s:
527 strcpy(name->sysname, "Win32s");
530 strcpy(name->sysname, "Win32 Unknown");
535 sprintf(name->release, "%d.%d",
536 osver.dwMajorVersion, osver.dwMinorVersion);
539 sprintf(name->version, "Build %d",
540 osver.dwPlatformId == VER_PLATFORM_WIN32_NT
541 ? osver.dwBuildNumber : (osver.dwBuildNumber & 0xffff));
542 if (osver.szCSDVersion[0]) {
543 char *buf = name->version + strlen(name->version);
544 sprintf(buf, " (%s)", osver.szCSDVersion);
548 *name->sysname = '\0';
549 *name->version = '\0';
550 *name->release = '\0';
554 hep = win32_gethostbyname("localhost");
556 STRLEN len = strlen(hep->h_name);
557 if (len <= nodemax) {
558 strcpy(name->nodename, hep->h_name);
561 strncpy(name->nodename, hep->h_name, nodemax);
562 name->nodename[nodemax] = '\0';
567 if (!XCEGetComputerNameA(name->nodename, &sz))
568 *name->nodename = '\0';
571 /* machine (architecture) */
575 GetSystemInfo(&info);
577 switch (info.wProcessorArchitecture) {
578 case PROCESSOR_ARCHITECTURE_INTEL:
580 case PROCESSOR_ARCHITECTURE_MIPS:
581 arch = "mips"; break;
582 case PROCESSOR_ARCHITECTURE_ALPHA:
583 arch = "alpha"; break;
584 case PROCESSOR_ARCHITECTURE_PPC:
586 case PROCESSOR_ARCHITECTURE_ARM:
588 case PROCESSOR_HITACHI_SH3:
590 case PROCESSOR_SHx_SH3:
594 arch = "unknown"; break;
596 strcpy(name->machine, arch);
601 static UINT timerid = 0;
603 static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
606 KillTimer(NULL,timerid);
611 DllExport unsigned int
612 win32_alarm(unsigned int sec)
615 * the 'obvious' implentation is SetTimer() with a callback
616 * which does whatever receiving SIGALRM would do
617 * we cannot use SIGALRM even via raise() as it is not
618 * one of the supported codes in <signal.h>
620 * Snag is unless something is looking at the message queue
621 * nothing happens :-(
626 timerid = SetTimer(NULL,timerid,sec*1000,(TIMERPROC)TimerProc);
628 Perl_croak_nocontext("Cannot set timer");
634 KillTimer(NULL,timerid);
641 #ifdef HAVE_DES_FCRYPT
642 extern char * des_fcrypt(const char *txt, const char *salt, char *cbuf);
646 win32_crypt(const char *txt, const char *salt)
649 #ifdef HAVE_DES_FCRYPT
651 return des_fcrypt(txt, salt, w32_crypt_buffer);
653 Perl_croak(aTHX_ "The crypt() function is unimplemented due to excessive paranoia.");
658 /* C doesn't like repeat struct definitions */
660 #if defined(USE_FIXED_OSFHANDLE) || defined(PERL_MSVCRT_READFIX)
663 #define _CRTIMP __declspec(dllimport)
667 * Control structure for lowio file handles
670 long osfhnd; /* underlying OS file HANDLE */
671 char osfile; /* attributes of file (e.g., open in text mode?) */
672 char pipech; /* one char buffer for handles opened on pipes */
674 CRITICAL_SECTION lock;
679 * Array of arrays of control structures for lowio files.
681 EXTERN_C _CRTIMP ioinfo* __pioinfo[];
684 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
685 * array of ioinfo structs.
690 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
692 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
695 * Access macros for getting at an ioinfo struct and its fields from a
698 #define _pioinfo(i) (__pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
699 #define _osfhnd(i) (_pioinfo(i)->osfhnd)
700 #define _osfile(i) (_pioinfo(i)->osfile)
701 #define _pipech(i) (_pioinfo(i)->pipech)
706 * redirected io subsystem for all XS modules
716 /* the rest are the remapped stdio routines */
736 win32_ferror(FILE *fp)
749 * Since the errors returned by the socket error function
750 * WSAGetLastError() are not known by the library routine strerror
751 * we have to roll our own.
755 win32_strerror(int e)
757 return xcestrerror(e);
761 win32_str_os_error(void *sv, DWORD dwErr)
765 sv_setpvn((SV*)sv, "Error", 5);
770 win32_fprintf(FILE *fp, const char *format, ...)
773 va_start(marker, format); /* Initialize variable arguments. */
775 return (vfprintf(fp, format, marker));
779 win32_printf(const char *format, ...)
782 va_start(marker, format); /* Initialize variable arguments. */
784 return (vprintf(format, marker));
788 win32_vfprintf(FILE *fp, const char *format, va_list args)
790 return (vfprintf(fp, format, args));
794 win32_vprintf(const char *format, va_list args)
796 return (vprintf(format, args));
800 win32_fread(void *buf, size_t size, size_t count, FILE *fp)
802 return fread(buf, size, count, fp);
806 win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
808 return fwrite(buf, size, count, fp);
812 win32_fopen(const char *filename, const char *mode)
814 return xcefopen(filename, mode);
818 win32_fdopen(int handle, const char *mode)
820 return palm_fdopen(handle, mode);
824 win32_freopen(const char *path, const char *mode, FILE *stream)
826 return xcefreopen(path, mode, stream);
830 win32_fclose(FILE *pf)
832 return xcefclose(pf);
836 win32_fputs(const char *s,FILE *pf)
842 win32_fputc(int c,FILE *pf)
848 win32_ungetc(int c,FILE *pf)
860 win32_fileno(FILE *pf)
862 return palm_fileno(pf);
866 win32_clearerr(FILE *pf)
873 win32_fflush(FILE *pf)
879 win32_ftell(FILE *pf)
885 win32_fseek(FILE *pf,long offset,int origin)
887 return fseek(pf, offset, origin);
890 /* fpos_t seems to be int64 on hpc pro! Really stupid. */
891 /* But maybe someday there will be such large disks in a hpc... */
893 win32_fgetpos(FILE *pf, fpos_t *p)
895 return fgetpos(pf, p);
899 win32_fsetpos(FILE *pf, const fpos_t *p)
901 return fsetpos(pf, p);
905 win32_rewind(FILE *pf)
907 fseek(pf, 0, SEEK_SET);
914 Perl_croak(aTHX_ PL_no_func, "tmpfile");
928 win32_fstat(int fd, struct stat *sbufptr)
930 return xcefstat(fd, sbufptr);
934 win32_link(const char *oldname, const char *newname)
936 Perl_croak(aTHX_ PL_no_func, "link");
942 win32_rename(const char *oname, const char *newname)
944 return xcerename(oname, newname);
948 win32_setmode(int fd, int mode)
950 /* currently 'celib' seem to have this function in src, but not
951 * exported. When it will be, we'll uncomment following line.
953 /* return xcesetmode(fd, mode); */
958 win32_lseek(int fd, long offset, int origin)
960 return xcelseek(fd, offset, origin);
966 return xcelseek(fd, 0, SEEK_CUR);
970 win32_open(const char *path, int flag, ...)
976 pmode = va_arg(ap, int);
979 return xceopen(path, flag, pmode);
991 Perl_croak(aTHX_ PL_no_func, "eof");
998 //vv Perl_croak(aTHX_ PL_no_func, "dup");
999 return xcedup(fd); // from celib/ceio.c; requires some more work on it.
1003 win32_dup2(int fd1,int fd2)
1005 //Perl_croak(aTHX_ PL_no_func, "dup2");
1006 return xcedup2(fd1,fd2);
1010 win32_read(int fd, void *buf, unsigned int cnt)
1012 return xceread(fd, buf, cnt);
1016 win32_write(int fd, const void *buf, unsigned int cnt)
1018 return xcewrite(fd, (void *) buf, cnt);
1022 win32_mkdir(const char *dir, int mode)
1024 return xcemkdir(dir);
1028 win32_rmdir(const char *dir)
1030 return xcermdir(dir);
1034 win32_chdir(const char *dir)
1036 return xcechdir(dir);
1040 win32_access(const char *path, int mode)
1042 return xceaccess(path, mode);
1046 win32_chmod(const char *path, int mode)
1048 return xcechmod(path, mode);
1052 win32_perror(const char *str)
1058 win32_setbuf(FILE *pf, char *buf)
1060 Perl_croak(aTHX_ PL_no_func, "setbuf");
1064 win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
1066 return setvbuf(pf, buf, type, size);
1070 win32_flushall(void)
1076 win32_fcloseall(void)
1082 win32_fgets(char *s, int n, FILE *pf)
1084 return fgets(s, n, pf);
1094 win32_fgetc(FILE *pf)
1100 win32_putc(int c, FILE *pf)
1106 win32_puts(const char *s)
1118 win32_putchar(int c)
1125 #ifndef USE_PERL_SBRK
1127 static char *committed = NULL;
1128 static char *base = NULL;
1129 static char *reserved = NULL;
1130 static char *brk = NULL;
1131 static DWORD pagesize = 0;
1132 static DWORD allocsize = 0;
1140 GetSystemInfo(&info);
1141 /* Pretend page size is larger so we don't perpetually
1142 * call the OS to commit just one page ...
1144 pagesize = info.dwPageSize << 3;
1145 allocsize = info.dwAllocationGranularity;
1147 /* This scheme fails eventually if request for contiguous
1148 * block is denied so reserve big blocks - this is only
1149 * address space not memory ...
1151 if (brk+need >= reserved)
1153 DWORD size = 64*1024*1024;
1155 if (committed && reserved && committed < reserved)
1157 /* Commit last of previous chunk cannot span allocations */
1158 addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
1160 committed = reserved;
1162 /* Reserve some (more) space
1163 * Note this is a little sneaky, 1st call passes NULL as reserved
1164 * so lets system choose where we start, subsequent calls pass
1165 * the old end address so ask for a contiguous block
1167 addr = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
1170 reserved = addr+size;
1185 if (brk > committed)
1187 DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
1188 char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
1203 win32_malloc(size_t size)
1205 return malloc(size);
1209 win32_calloc(size_t numitems, size_t size)
1211 return calloc(numitems,size);
1215 win32_realloc(void *block, size_t size)
1217 return realloc(block,size);
1221 win32_free(void *block)
1227 win32_execv(const char *cmdname, const char *const *argv)
1229 Perl_croak(aTHX_ PL_no_func, "execv");
1234 win32_execvp(const char *cmdname, const char *const *argv)
1236 Perl_croak(aTHX_ PL_no_func, "execvp");
1241 win32_dynaload(const char* filename)
1246 hModule = XCELoadLibraryA(filename);
1251 /* this is needed by Cwd.pm... */
1258 SV *sv = sv_newmortal();
1260 xcegetcwd(buf, sizeof(buf));
1262 sv_setpv(sv, xcestrdup(buf));
1266 #ifndef INCOMPLETE_TAINTS
1267 SvTAINTED_on(ST(0));
1278 Perl_croak(aTHX_ "usage: Win32::SetCwd($cwd)");
1280 if (!xcechdir(SvPV_nolen(ST(0))))
1287 XS(w32_GetTickCount)
1290 DWORD msec = GetTickCount();
1298 XS(w32_GetOSVersion)
1301 OSVERSIONINFOA osver;
1303 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
1304 if (!XCEGetVersionExA(&osver)) {
1307 XPUSHs(newSVpvn(osver.szCSDVersion, strlen(osver.szCSDVersion)));
1308 XPUSHs(newSViv(osver.dwMajorVersion));
1309 XPUSHs(newSViv(osver.dwMinorVersion));
1310 XPUSHs(newSViv(osver.dwBuildNumber));
1312 XPUSHs(newSViv(osver.dwPlatformId));
1321 XSRETURN_IV(IsWinNT());
1329 XSRETURN_IV(IsWin95());
1337 XSRETURN_IV(IsWinCE());
1347 if(SystemParametersInfoW(SPI_GETOEMINFO, sizeof(wbuf), wbuf, FALSE))
1348 WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, sizeof(buf), 0, 0);
1350 sprintf(buf, "SystemParametersInfo failed: %d", GetLastError());
1361 Perl_croak(aTHX_ "usage: Win32::Sleep($milliseconds)");
1372 Perl_croak(aTHX_ "usage: Win32::CopyFile($from, $to, $overwrite)");
1375 char szSourceFile[MAX_PATH+1];
1376 strcpy(szSourceFile, PerlDir_mapA(SvPV_nolen(ST(0))));
1377 bResult = XCECopyFileA(szSourceFile, SvPV_nolen(ST(1)),
1394 unsigned int flags = MB_OK;
1396 txt = SvPV_nolen(ST(0));
1398 if (items < 1 || items > 2)
1399 Perl_croak(aTHX_ "usage: Win32::MessageBox($txt, [$flags])");
1402 flags = SvIV(ST(1));
1404 res = XCEMessageBoxA(NULL, txt, "Perl", flags);
1410 XS(w32_GetPowerStatus)
1414 SYSTEM_POWER_STATUS_EX sps;
1416 if(GetSystemPowerStatusEx(&sps, TRUE) == FALSE)
1421 XPUSHs(newSViv(sps.ACLineStatus));
1422 XPUSHs(newSViv(sps.BatteryFlag));
1423 XPUSHs(newSViv(sps.BatteryLifePercent));
1424 XPUSHs(newSViv(sps.BatteryLifeTime));
1425 XPUSHs(newSViv(sps.BatteryFullLifeTime));
1426 XPUSHs(newSViv(sps.BackupBatteryFlag));
1427 XPUSHs(newSViv(sps.BackupBatteryLifePercent));
1428 XPUSHs(newSViv(sps.BackupBatteryLifeTime));
1429 XPUSHs(newSViv(sps.BackupBatteryFullLifeTime));
1441 SHELLEXECUTEINFO si;
1443 wchar_t wfile[MAX_PATH];
1447 Perl_croak(aTHX_ "usage: Win32::ShellEx($file, $verb)");
1449 file = SvPV_nolen(ST(0));
1450 verb = SvPV_nolen(ST(1));
1452 memset(&si, 0, sizeof(si));
1453 si.cbSize = sizeof(si);
1454 si.fMask = SEE_MASK_FLAG_NO_UI;
1456 MultiByteToWideChar(CP_ACP, 0, verb, -1,
1457 wverb, sizeof(wverb)/2);
1458 si.lpVerb = (TCHAR *)wverb;
1460 MultiByteToWideChar(CP_ACP, 0, file, -1,
1461 wfile, sizeof(wfile)/2);
1462 si.lpFile = (TCHAR *)wfile;
1464 if(ShellExecuteEx(&si) == FALSE)
1473 Perl_init_os_extras(void)
1476 char *file = __FILE__;
1479 w32_perlshell_tokens = Nullch;
1480 w32_perlshell_items = -1;
1481 w32_fdpid = newAV(); /* XX needs to be in Perl_win32_init()? */
1482 New(1313, w32_children, 1, child_tab);
1483 w32_num_children = 0;
1485 newXS("Win32::GetCwd", w32_GetCwd, file);
1486 newXS("Win32::SetCwd", w32_SetCwd, file);
1487 newXS("Win32::GetTickCount", w32_GetTickCount, file);
1488 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
1490 newXS("Win32::ShellEx", w32_ShellEx, file);
1492 newXS("Win32::IsWinNT", w32_IsWinNT, file);
1493 newXS("Win32::IsWin95", w32_IsWin95, file);
1494 newXS("Win32::IsWinCE", w32_IsWinCE, file);
1495 newXS("Win32::CopyFile", w32_CopyFile, file);
1496 newXS("Win32::Sleep", w32_Sleep, file);
1497 newXS("Win32::MessageBox", w32_MessageBox, file);
1498 newXS("Win32::GetPowerStatus", w32_GetPowerStatus, file);
1499 newXS("Win32::GetOemInfo", w32_GetOemInfo, file);
1508 fgets(buf, sizeof(buf), stdin);
1512 Perl_win32_init(int *argcp, char ***argvp)
1517 if((p = xcegetenv("PERLDEBUG")) && (p[0] == 'y' || p[0] == 'Y'))
1525 win32_flock(int fd, int oper)
1527 Perl_croak(aTHX_ PL_no_func, "flock");
1532 win32_waitpid(int pid, int *status, int flags)
1534 Perl_croak(aTHX_ PL_no_func, "waitpid");
1539 win32_wait(int *status)
1541 Perl_croak(aTHX_ PL_no_func, "wait");
1548 return xcesystem(cmd);
1552 do_aspawn(void *vreally, void **vmark, void **vsp)
1554 Perl_croak(aTHX_ PL_no_func, "aspawn");
1559 wce_reopen_stdout(char *fname)
1561 if(xcefreopen(fname, "w", stdout) == NULL)
1572 printf("Hit RETURN");
1574 fgets(buf, sizeof(buf), stdin);
1578 /* //////////////////////////////////////////////////////////////////// */
1581 win32_argv2utf8(int argc, char** argv)
1587 Perl_sys_intern_init(pTHX)
1589 w32_perlshell_tokens = Nullch;
1590 w32_perlshell_vec = (char**)NULL;
1591 w32_perlshell_items = 0;
1592 w32_fdpid = newAV();
1593 New(1313, w32_children, 1, child_tab);
1594 w32_num_children = 0;
1595 # ifdef USE_ITHREADS
1597 New(1313, w32_pseudo_children, 1, child_tab);
1598 w32_num_pseudo_children = 0;
1602 w32_init_socktype = 0;
1607 Perl_sys_intern_clear(pTHX)
1609 Safefree(w32_perlshell_tokens);
1610 Safefree(w32_perlshell_vec);
1611 /* NOTE: w32_fdpid is freed by sv_clean_all() */
1612 Safefree(w32_children);
1613 # ifdef USE_ITHREADS
1614 Safefree(w32_pseudo_children);
1618 /* //////////////////////////////////////////////////////////////////// */
1623 getcwd(char *buf, size_t size)
1625 return xcegetcwd(buf, size);
1635 win32_open_osfhandle(intptr_t osfhandle, int flags)
1638 char fileflags=0; /* _osfile flags */
1640 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_open_osfhandle)", "error", 0);
1641 Perl_croak_nocontext("win32_open_osfhandle() TBD on this platform");
1646 win32_get_osfhandle(intptr_t osfhandle, int flags)
1649 char fileflags=0; /* _osfile flags */
1651 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_get_osfhandle)", "error", 0);
1652 Perl_croak_nocontext("win32_get_osfhandle() TBD on this platform");
1657 * a popen() clone that respects PERL5SHELL
1659 * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
1663 win32_popen(const char *command, const char *mode)
1665 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT in wince/wince.c(win32_popen)", "error", 0);
1666 Perl_croak_nocontext("win32_popen() TBD on this platform");
1674 win32_pclose(PerlIO *pf)
1676 #ifdef USE_RTL_POPEN
1680 int childpid, status;
1684 sv = *av_fetch(w32_fdpid, PerlIO_fileno(pf), TRUE);
1687 childpid = SvIVX(sv);
1704 if (win32_waitpid(childpid, &status, 0) == -1)
1709 #endif /* USE_RTL_POPEN */
1713 win32_fdupopen(FILE *pf)
1718 int fileno = win32_dup(win32_fileno(pf));
1720 XCEMessageBoxA(NULL, "NEED TO IMPLEMENT a place in .../wince/wince.c(win32_fdupopen)", "Perl(developer)", 0);
1721 Perl_croak_nocontext("win32_fdupopen() TBD on this platform");
1724 /* open the file in the same mode */
1725 if((pf)->_flag & _IOREAD) {
1729 else if((pf)->_flag & _IOWRT) {
1733 else if((pf)->_flag & _IORW) {
1739 /* it appears that the binmode is attached to the
1740 * file descriptor so binmode files will be handled
1743 pfdup = win32_fdopen(fileno, mode);
1745 /* move the file pointer to the same position */
1746 if (!fgetpos(pf, &pos)) {
1747 fsetpos(pfdup, &pos);