2 * "The Road goes ever on and on, down from the door where it began."
15 #ifdef PERL_IMPLICIT_SYS
21 /* Register any extra external extensions */
22 char *staticlinkmodules[] = {
27 EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv);
32 char *file = __FILE__;
34 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
37 #ifdef PERL_IMPLICIT_SYS
40 PerlMemMalloc(struct IPerlMem *I, size_t size)
42 return win32_malloc(size);
45 PerlMemRealloc(struct IPerlMem *I, void* ptr, size_t size)
47 return win32_realloc(ptr, size);
50 PerlMemFree(struct IPerlMem *I, void* ptr)
55 struct IPerlMem perlMem =
64 extern char * g_win32_get_privlib(char *pl);
65 extern char * g_win32_get_sitelib(char *pl);
69 PerlEnvGetenv(struct IPerlEnv *I, const char *varname)
71 return win32_getenv(varname);
74 PerlEnvPutenv(struct IPerlEnv *I, const char *envstring)
76 return win32_putenv(envstring);
80 PerlEnvGetenv_len(struct IPerlEnv *I, const char* varname, unsigned long* len)
82 char *e = win32_getenv(varname);
89 PerlEnvUname(struct IPerlEnv *I, struct utsname *name)
91 return win32_uname(name);
95 PerlEnvClearenv(struct IPerlEnv *I)
98 char *envv = GetEnvironmentStrings();
102 char *end = strchr(cur,'=');
103 if (end && end != cur) {
105 my_setenv(cur,Nullch);
107 cur = end + strlen(end+1)+2;
109 else if ((len = strlen(cur)))
112 FreeEnvironmentStrings(envv);
116 PerlEnvGetChildEnv(struct IPerlEnv *I)
122 PerlEnvFreeChildEnv(struct IPerlEnv *I, void* env)
127 PerlEnvGetChildDir(struct IPerlEnv *I)
133 PerlEnvFreeChildDir(struct IPerlEnv *I, char* dir)
138 PerlEnvOsId(struct IPerlEnv *I)
140 return win32_os_id();
144 PerlEnvLibPath(struct IPerlEnv *I, char *pl)
146 return g_win32_get_privlib(pl);
150 PerlEnvSiteLibPath(struct IPerlEnv *I, char *pl)
152 return g_win32_get_sitelib(pl);
155 struct IPerlEnv perlEnv =
174 PerlStdIOStdin(struct IPerlStdIO *I)
176 return (PerlIO*)win32_stdin();
180 PerlStdIOStdout(struct IPerlStdIO *I)
182 return (PerlIO*)win32_stdout();
186 PerlStdIOStderr(struct IPerlStdIO *I)
188 return (PerlIO*)win32_stderr();
192 PerlStdIOOpen(struct IPerlStdIO *I, const char *path, const char *mode)
194 return (PerlIO*)win32_fopen(path, mode);
198 PerlStdIOClose(struct IPerlStdIO *I, PerlIO* pf)
200 return win32_fclose(((FILE*)pf));
204 PerlStdIOEof(struct IPerlStdIO *I, PerlIO* pf)
206 return win32_feof((FILE*)pf);
210 PerlStdIOError(struct IPerlStdIO *I, PerlIO* pf)
212 return win32_ferror((FILE*)pf);
216 PerlStdIOClearerr(struct IPerlStdIO *I, PerlIO* pf)
218 win32_clearerr((FILE*)pf);
222 PerlStdIOGetc(struct IPerlStdIO *I, PerlIO* pf)
224 return win32_getc((FILE*)pf);
228 PerlStdIOGetBase(struct IPerlStdIO *I, PerlIO* pf)
239 PerlStdIOGetBufsiz(struct IPerlStdIO *I, PerlIO* pf)
243 return FILE_bufsiz(f);
250 PerlStdIOGetCnt(struct IPerlStdIO *I, PerlIO* pf)
261 PerlStdIOGetPtr(struct IPerlStdIO *I, PerlIO* pf)
272 PerlStdIOGets(struct IPerlStdIO *I, PerlIO* pf, char* s, int n)
274 return win32_fgets(s, n, (FILE*)pf);
278 PerlStdIOPutc(struct IPerlStdIO *I, PerlIO* pf, int c)
280 return win32_fputc(c, (FILE*)pf);
284 PerlStdIOPuts(struct IPerlStdIO *I, PerlIO* pf, const char *s)
286 return win32_fputs(s, (FILE*)pf);
290 PerlStdIOFlush(struct IPerlStdIO *I, PerlIO* pf)
292 return win32_fflush((FILE*)pf);
296 PerlStdIOUngetc(struct IPerlStdIO *I, PerlIO* pf,int c)
298 return win32_ungetc(c, (FILE*)pf);
302 PerlStdIOFileno(struct IPerlStdIO *I, PerlIO* pf)
304 return win32_fileno((FILE*)pf);
308 PerlStdIOFdopen(struct IPerlStdIO *I, int fd, const char *mode)
310 return (PerlIO*)win32_fdopen(fd, mode);
314 PerlStdIOReopen(struct IPerlStdIO *I, const char*path, const char*mode, PerlIO* pf)
316 return (PerlIO*)win32_freopen(path, mode, (FILE*)pf);
320 PerlStdIORead(struct IPerlStdIO *I, PerlIO* pf, void *buffer, Size_t size)
322 return win32_fread(buffer, 1, size, (FILE*)pf);
326 PerlStdIOWrite(struct IPerlStdIO *I, PerlIO* pf, const void *buffer, Size_t size)
328 return win32_fwrite(buffer, 1, size, (FILE*)pf);
332 PerlStdIOSetBuf(struct IPerlStdIO *I, PerlIO* pf, char* buffer)
334 win32_setbuf((FILE*)pf, buffer);
338 PerlStdIOSetVBuf(struct IPerlStdIO *I, PerlIO* pf, char* buffer, int type, Size_t size)
340 return win32_setvbuf((FILE*)pf, buffer, type, size);
344 PerlStdIOSetCnt(struct IPerlStdIO *I, PerlIO* pf, int n)
346 #ifdef STDIO_CNT_LVALUE
353 PerlStdIOSetPtrCnt(struct IPerlStdIO *I, PerlIO* pf, char * ptr, int n)
355 #ifdef STDIO_PTR_LVALUE
363 PerlStdIOSetlinebuf(struct IPerlStdIO *I, PerlIO* pf)
365 win32_setvbuf((FILE*)pf, NULL, _IOLBF, 0);
369 PerlStdIOPrintf(struct IPerlStdIO *I, PerlIO* pf, const char *format,...)
372 va_start(arglist, format);
373 return win32_vfprintf((FILE*)pf, format, arglist);
377 PerlStdIOVprintf(struct IPerlStdIO *I, PerlIO* pf, const char *format, va_list arglist)
379 return win32_vfprintf((FILE*)pf, format, arglist);
383 PerlStdIOTell(struct IPerlStdIO *I, PerlIO* pf)
385 return win32_ftell((FILE*)pf);
389 PerlStdIOSeek(struct IPerlStdIO *I, PerlIO* pf, off_t offset, int origin)
391 return win32_fseek((FILE*)pf, offset, origin);
395 PerlStdIORewind(struct IPerlStdIO *I, PerlIO* pf)
397 win32_rewind((FILE*)pf);
401 PerlStdIOTmpfile(struct IPerlStdIO *I)
403 return (PerlIO*)win32_tmpfile();
407 PerlStdIOGetpos(struct IPerlStdIO *I, PerlIO* pf, Fpos_t *p)
409 return win32_fgetpos((FILE*)pf, p);
413 PerlStdIOSetpos(struct IPerlStdIO *I, PerlIO* pf, const Fpos_t *p)
415 return win32_fsetpos((FILE*)pf, p);
418 PerlStdIOInit(struct IPerlStdIO *I)
423 PerlStdIOInitOSExtras(struct IPerlStdIO *I)
425 Perl_init_os_extras();
429 PerlStdIOOpenOSfhandle(struct IPerlStdIO *I, long osfhandle, int flags)
431 return win32_open_osfhandle(osfhandle, flags);
435 PerlStdIOGetOSfhandle(struct IPerlStdIO *I, int filenum)
437 return win32_get_osfhandle(filenum);
441 struct IPerlStdIO perlStdIO =
480 PerlStdIOInitOSExtras,
486 PerlLIOAccess(struct IPerlLIO *I, const char *path, int mode)
488 return access(path, mode);
492 PerlLIOChmod(struct IPerlLIO *I, const char *filename, int pmode)
494 return chmod(filename, pmode);
498 PerlLIOChown(struct IPerlLIO *I, const char *filename, uid_t owner, gid_t group)
500 return chown(filename, owner, group);
504 PerlLIOChsize(struct IPerlLIO *I, int handle, long size)
506 return chsize(handle, size);
510 PerlLIOClose(struct IPerlLIO *I, int handle)
512 return win32_close(handle);
516 PerlLIODup(struct IPerlLIO *I, int handle)
518 return win32_dup(handle);
522 PerlLIODup2(struct IPerlLIO *I, int handle1, int handle2)
524 return win32_dup2(handle1, handle2);
528 PerlLIOFlock(struct IPerlLIO *I, int fd, int oper)
530 return win32_flock(fd, oper);
534 PerlLIOFileStat(struct IPerlLIO *I, int handle, struct stat *buffer)
536 return fstat(handle, buffer);
540 PerlLIOIOCtl(struct IPerlLIO *I, int i, unsigned int u, char *data)
542 return win32_ioctlsocket((SOCKET)i, (long)u, (u_long*)data);
546 PerlLIOIsatty(struct IPerlLIO *I, int fd)
552 PerlLIOLink(struct IPerlLIO*, const char*oldname, const char *newname)
554 return win32_link(oldname, newname);
558 PerlLIOLseek(struct IPerlLIO *I, int handle, long offset, int origin)
560 return win32_lseek(handle, offset, origin);
564 PerlLIOLstat(struct IPerlLIO* p, const char *path, struct stat *buffer)
566 return win32_stat(path, buffer);
570 PerlLIOMktemp(struct IPerlLIO *I, char *Template)
572 return mktemp(Template);
576 PerlLIOOpen(struct IPerlLIO *I, const char *filename, int oflag)
578 return win32_open(filename, oflag);
582 PerlLIOOpen3(struct IPerlLIO *I, const char *filename, int oflag, int pmode)
585 if(stricmp(filename, "/dev/null") == 0)
586 ret = open("NUL", oflag, pmode);
588 ret = open(filename, oflag, pmode);
594 PerlLIORead(struct IPerlLIO *I, int handle, void *buffer, unsigned int count)
596 return win32_read(handle, buffer, count);
600 PerlLIORename(struct IPerlLIO *I, const char *OldFileName, const char *newname)
602 return win32_rename(OldFileName, newname);
606 PerlLIOSetmode(struct IPerlLIO *I, int handle, int mode)
608 return win32_setmode(handle, mode);
612 PerlLIONameStat(struct IPerlLIO *I, const char *path, struct stat *buffer)
614 return win32_stat(path, buffer);
618 PerlLIOTmpnam(struct IPerlLIO *I, char *string)
620 return tmpnam(string);
624 PerlLIOUmask(struct IPerlLIO *I, int pmode)
630 PerlLIOUnlink(struct IPerlLIO *I, const char *filename)
632 chmod(filename, S_IREAD | S_IWRITE);
633 return unlink(filename);
637 PerlLIOUtime(struct IPerlLIO *I, char *filename, struct utimbuf *times)
639 return win32_utime(filename, times);
643 PerlLIOWrite(struct IPerlLIO *I, int handle, const void *buffer, unsigned int count)
645 return win32_write(handle, buffer, count);
648 struct IPerlLIO perlLIO =
680 PerlDirMakedir(struct IPerlDir *I, const char *dirname, int mode)
682 return win32_mkdir(dirname, mode);
686 PerlDirChdir(struct IPerlDir *I, const char *dirname)
688 return win32_chdir(dirname);
692 PerlDirRmdir(struct IPerlDir *I, const char *dirname)
694 return win32_rmdir(dirname);
698 PerlDirClose(struct IPerlDir *I, DIR *dirp)
700 return win32_closedir(dirp);
704 PerlDirOpen(struct IPerlDir *I, char *filename)
706 return win32_opendir(filename);
710 PerlDirRead(struct IPerlDir *I, DIR *dirp)
712 return win32_readdir(dirp);
716 PerlDirRewind(struct IPerlDir *I, DIR *dirp)
718 win32_rewinddir(dirp);
722 PerlDirSeek(struct IPerlDir *I, DIR *dirp, long loc)
724 win32_seekdir(dirp, loc);
728 PerlDirTell(struct IPerlDir *I, DIR *dirp)
730 return win32_telldir(dirp);
733 struct IPerlDir perlDir =
749 PerlSockHtonl(struct IPerlSock *I, u_long hostlong)
751 return win32_htonl(hostlong);
755 PerlSockHtons(struct IPerlSock *I, u_short hostshort)
757 return win32_htons(hostshort);
761 PerlSockNtohl(struct IPerlSock *I, u_long netlong)
763 return win32_ntohl(netlong);
767 PerlSockNtohs(struct IPerlSock *I, u_short netshort)
769 return win32_ntohs(netshort);
772 SOCKET PerlSockAccept(struct IPerlSock *I, SOCKET s, struct sockaddr* addr, int* addrlen)
774 return win32_accept(s, addr, addrlen);
778 PerlSockBind(struct IPerlSock *I, SOCKET s, const struct sockaddr* name, int namelen)
780 return win32_bind(s, name, namelen);
784 PerlSockConnect(struct IPerlSock *I, SOCKET s, const struct sockaddr* name, int namelen)
786 return win32_connect(s, name, namelen);
790 PerlSockEndhostent(struct IPerlSock *I)
796 PerlSockEndnetent(struct IPerlSock *I)
802 PerlSockEndprotoent(struct IPerlSock *I)
808 PerlSockEndservent(struct IPerlSock *I)
814 PerlSockGethostbyaddr(struct IPerlSock *I, const char* addr, int len, int type)
816 return win32_gethostbyaddr(addr, len, type);
820 PerlSockGethostbyname(struct IPerlSock *I, const char* name)
822 return win32_gethostbyname(name);
826 PerlSockGethostent(struct IPerlSock *I)
829 Perl_croak(aTHX_ "gethostent not implemented!\n");
834 PerlSockGethostname(struct IPerlSock *I, char* name, int namelen)
836 return win32_gethostname(name, namelen);
840 PerlSockGetnetbyaddr(struct IPerlSock *I, long net, int type)
842 return win32_getnetbyaddr(net, type);
846 PerlSockGetnetbyname(struct IPerlSock *I, const char *name)
848 return win32_getnetbyname((char*)name);
852 PerlSockGetnetent(struct IPerlSock *I)
854 return win32_getnetent();
857 int PerlSockGetpeername(struct IPerlSock *I, SOCKET s, struct sockaddr* name, int* namelen)
859 return win32_getpeername(s, name, namelen);
863 PerlSockGetprotobyname(struct IPerlSock *I, const char* name)
865 return win32_getprotobyname(name);
869 PerlSockGetprotobynumber(struct IPerlSock *I, int number)
871 return win32_getprotobynumber(number);
875 PerlSockGetprotoent(struct IPerlSock *I)
877 return win32_getprotoent();
881 PerlSockGetservbyname(struct IPerlSock *I, const char* name, const char* proto)
883 return win32_getservbyname(name, proto);
887 PerlSockGetservbyport(struct IPerlSock *I, int port, const char* proto)
889 return win32_getservbyport(port, proto);
893 PerlSockGetservent(struct IPerlSock *I)
895 return win32_getservent();
899 PerlSockGetsockname(struct IPerlSock *I, SOCKET s, struct sockaddr* name, int* namelen)
901 return win32_getsockname(s, name, namelen);
905 PerlSockGetsockopt(struct IPerlSock *I, SOCKET s, int level, int optname, char* optval, int* optlen)
907 return win32_getsockopt(s, level, optname, optval, optlen);
911 PerlSockInetAddr(struct IPerlSock *I, const char* cp)
913 return win32_inet_addr(cp);
917 PerlSockInetNtoa(struct IPerlSock *I, struct in_addr in)
919 return win32_inet_ntoa(in);
923 PerlSockListen(struct IPerlSock *I, SOCKET s, int backlog)
925 return win32_listen(s, backlog);
929 PerlSockRecv(struct IPerlSock *I, SOCKET s, char* buffer, int len, int flags)
931 return win32_recv(s, buffer, len, flags);
935 PerlSockRecvfrom(struct IPerlSock *I, SOCKET s, char* buffer, int len, int flags, struct sockaddr* from, int* fromlen)
937 return win32_recvfrom(s, buffer, len, flags, from, fromlen);
941 PerlSockSelect(struct IPerlSock *I, int nfds, char* readfds, char* writefds, char* exceptfds, const struct timeval* timeout)
943 return win32_select(nfds, (Perl_fd_set*)readfds, (Perl_fd_set*)writefds, (Perl_fd_set*)exceptfds, timeout);
947 PerlSockSend(struct IPerlSock *I, SOCKET s, const char* buffer, int len, int flags)
949 return win32_send(s, buffer, len, flags);
953 PerlSockSendto(struct IPerlSock *I, SOCKET s, const char* buffer, int len, int flags, const struct sockaddr* to, int tolen)
955 return win32_sendto(s, buffer, len, flags, to, tolen);
959 PerlSockSethostent(struct IPerlSock *I, int stayopen)
961 win32_sethostent(stayopen);
965 PerlSockSetnetent(struct IPerlSock *I, int stayopen)
967 win32_setnetent(stayopen);
971 PerlSockSetprotoent(struct IPerlSock *I, int stayopen)
973 win32_setprotoent(stayopen);
977 PerlSockSetservent(struct IPerlSock *I, int stayopen)
979 win32_setservent(stayopen);
983 PerlSockSetsockopt(struct IPerlSock *I, SOCKET s, int level, int optname, const char* optval, int optlen)
985 return win32_setsockopt(s, level, optname, optval, optlen);
989 PerlSockShutdown(struct IPerlSock *I, SOCKET s, int how)
991 return win32_shutdown(s, how);
995 PerlSockSocket(struct IPerlSock *I, int af, int type, int protocol)
997 return win32_socket(af, type, protocol);
1001 PerlSockSocketpair(struct IPerlSock *I, int domain, int type, int protocol, int* fds)
1004 Perl_croak(aTHX_ "socketpair not implemented!\n");
1009 PerlSockClosesocket(struct IPerlSock *I, SOCKET s)
1011 return win32_closesocket(s);
1015 PerlSockIoctlsocket(struct IPerlSock *I, SOCKET s, long cmd, u_long *argp)
1017 return win32_ioctlsocket(s, cmd, argp);
1020 struct IPerlSock perlSock =
1031 PerlSockEndprotoent,
1033 PerlSockGethostname,
1034 PerlSockGetpeername,
1035 PerlSockGethostbyaddr,
1036 PerlSockGethostbyname,
1038 PerlSockGetnetbyaddr,
1039 PerlSockGetnetbyname,
1041 PerlSockGetprotobyname,
1042 PerlSockGetprotobynumber,
1043 PerlSockGetprotoent,
1044 PerlSockGetservbyname,
1045 PerlSockGetservbyport,
1047 PerlSockGetsockname,
1059 PerlSockSetprotoent,
1065 PerlSockClosesocket,
1071 #define EXECF_EXEC 1
1072 #define EXECF_SPAWN 2
1074 extern char * g_getlogin(void);
1075 extern int do_spawn2(char *cmd, int exectype);
1077 extern int g_do_aspawn(void *vreally, void **vmark, void **vsp);
1078 #define do_aspawn g_do_aspawn
1080 EXTERN_C PerlInterpreter* perl_alloc_using(struct IPerlMem* pMem,
1081 struct IPerlEnv* pEnv, struct IPerlStdIO* pStdIO,
1082 struct IPerlLIO* pLIO, struct IPerlDir* pDir,
1083 struct IPerlSock* pSock, struct IPerlProc* pProc);
1086 PerlProcAbort(struct IPerlProc *I)
1092 PerlProcCrypt(struct IPerlProc *I, const char* clear, const char* salt)
1094 return win32_crypt(clear, salt);
1098 PerlProcExit(struct IPerlProc *I, int status)
1104 PerlProc_Exit(struct IPerlProc *I, int status)
1110 PerlProcExecl(struct IPerlProc *I, const char *cmdname, const char *arg0, const char *arg1, const char *arg2, const char *arg3)
1112 return execl(cmdname, arg0, arg1, arg2, arg3);
1116 PerlProcExecv(struct IPerlProc *I, const char *cmdname, const char *const *argv)
1118 return win32_execvp(cmdname, argv);
1122 PerlProcExecvp(struct IPerlProc *I, const char *cmdname, const char *const *argv)
1124 return win32_execvp(cmdname, argv);
1128 PerlProcGetuid(struct IPerlProc *I)
1134 PerlProcGeteuid(struct IPerlProc *I)
1140 PerlProcGetgid(struct IPerlProc *I)
1146 PerlProcGetegid(struct IPerlProc *I)
1152 PerlProcGetlogin(struct IPerlProc *I)
1154 return g_getlogin();
1158 PerlProcKill(struct IPerlProc *I, int pid, int sig)
1160 return win32_kill(pid, sig);
1164 PerlProcKillpg(struct IPerlProc *I, int pid, int sig)
1167 Perl_croak(aTHX_ "killpg not implemented!\n");
1172 PerlProcPauseProc(struct IPerlProc *I)
1174 return win32_sleep((32767L << 16) + 32767);
1178 PerlProcPopen(struct IPerlProc *I, const char *command, const char *mode)
1181 PERL_FLUSHALL_FOR_CHILD;
1182 return (PerlIO*)win32_popen(command, mode);
1186 PerlProcPclose(struct IPerlProc *I, PerlIO *stream)
1188 return win32_pclose((FILE*)stream);
1192 PerlProcPipe(struct IPerlProc *I, int *phandles)
1194 return win32_pipe(phandles, 512, O_BINARY);
1198 PerlProcSetuid(struct IPerlProc *I, uid_t u)
1204 PerlProcSetgid(struct IPerlProc *I, gid_t g)
1210 PerlProcSleep(struct IPerlProc *I, unsigned int s)
1212 return win32_sleep(s);
1216 PerlProcTimes(struct IPerlProc *I, struct tms *timebuf)
1218 return win32_times(timebuf);
1222 PerlProcWait(struct IPerlProc *I, int *status)
1224 return win32_wait(status);
1228 PerlProcWaitpid(struct IPerlProc *I, int pid, int *status, int flags)
1230 return win32_waitpid(pid, status, flags);
1234 PerlProcSignal(struct IPerlProc *I, int sig, Sighandler_t subcode)
1240 PerlProcDynaLoader(struct IPerlProc *I, const char* filename)
1242 return win32_dynaload(filename);
1246 PerlProcGetOSError(struct IPerlProc *I, SV* sv, DWORD dwErr)
1248 win32_str_os_error(sv, dwErr);
1252 PerlProcDoCmd(struct IPerlProc *I, char *cmd)
1254 do_spawn2(cmd, EXECF_EXEC);
1259 PerlProcSpawn(struct IPerlProc *I, char* cmds)
1261 return do_spawn2(cmds, EXECF_SPAWN);
1265 PerlProcSpawnvp(struct IPerlProc *I, int mode, const char *cmdname, const char *const *argv)
1267 return win32_spawnvp(mode, cmdname, argv);
1271 PerlProcASpawn(struct IPerlProc *I, void *vreally, void **vmark, void **vsp)
1273 return do_aspawn(vreally, vmark, vsp);
1276 struct IPerlProc perlProc =
1311 /*#include "perlhost.h" */
1315 perl_get_host_info(struct IPerlMemInfo* perlMemInfo,
1316 struct IPerlEnvInfo* perlEnvInfo,
1317 struct IPerlStdIOInfo* perlStdIOInfo,
1318 struct IPerlLIOInfo* perlLIOInfo,
1319 struct IPerlDirInfo* perlDirInfo,
1320 struct IPerlSockInfo* perlSockInfo,
1321 struct IPerlProcInfo* perlProcInfo)
1324 Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
1325 perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
1328 Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
1329 perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
1332 Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
1333 perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
1336 Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
1337 perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
1340 Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
1341 perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
1344 Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
1345 perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
1348 Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
1349 perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
1355 EXTERN_C PerlInterpreter* perl_alloc_using(struct IPerlMem* pMem,
1356 struct IPerlEnv* pEnv, struct IPerlStdIO* pStdIO,
1357 struct IPerlLIO* pLIO, struct IPerlDir* pDir,
1358 struct IPerlSock* pSock, struct IPerlProc* pProc)
1360 CPerlObj* pPerl = NULL;
1363 pPerl = Perl_alloc(pMem, pEnv, pStdIO, pLIO, pDir, pSock, pProc);
1367 win32_fprintf(stderr, "%s\n", "Error: Unable to allocate memory");
1372 SetPerlInterpreter(pPerl);
1373 return (PerlInterpreter*)pPerl;
1375 SetPerlInterpreter(NULL);
1380 #undef perl_construct
1381 #undef perl_destruct
1385 EXTERN_C PerlInterpreter* perl_alloc(void)
1387 CPerlObj* pPerl = NULL;
1390 pPerl = Perl_alloc(&perlMem, &perlEnv, &perlStdIO, &perlLIO,
1391 &perlDir, &perlSock, &perlProc);
1395 win32_fprintf(stderr, "%s\n", "Error: Unable to allocate memory");
1400 SetPerlInterpreter(pPerl);
1401 return (PerlInterpreter*)pPerl;
1403 SetPerlInterpreter(NULL);
1407 EXTERN_C void perl_construct(PerlInterpreter* sv_interp)
1409 CPerlObj* pPerl = (CPerlObj*)sv_interp;
1412 pPerl->perl_construct();
1416 win32_fprintf(stderr, "%s\n",
1417 "Error: Unable to construct data structures");
1419 SetPerlInterpreter(NULL);
1423 EXTERN_C void perl_destruct(PerlInterpreter* sv_interp)
1425 CPerlObj* pPerl = (CPerlObj*)sv_interp;
1428 pPerl->perl_destruct();
1435 EXTERN_C void perl_free(PerlInterpreter* sv_interp)
1437 CPerlObj* pPerl = (CPerlObj*)sv_interp;
1445 SetPerlInterpreter(NULL);
1448 EXTERN_C int perl_run(PerlInterpreter* sv_interp)
1450 CPerlObj* pPerl = (CPerlObj*)sv_interp;
1454 retVal = pPerl->perl_run();
1459 // this is where exit() should arrive
1465 win32_fprintf(stderr, "Error: Runtime exception\n");
1471 EXTERN_C int perl_parse(PerlInterpreter* sv_interp, void (*xsinit)(CPerlObj*), int argc, char** argv, char** env)
1474 CPerlObj* pPerl = (CPerlObj*)sv_interp;
1477 retVal = pPerl->perl_parse(xsinit, argc, argv, env);
1482 // this is where exit() should arrive
1488 win32_fprintf(stderr, "Error: Parse exception\n");
1495 #undef PL_perl_destruct_level
1496 #define PL_perl_destruct_level int dummy
1498 #else /* !PERL_OBJECT */
1500 EXTERN_C PerlInterpreter*
1503 return perl_alloc_using(&perlMem, &perlEnv, &perlStdIO, &perlLIO,
1504 &perlDir, &perlSock, &perlProc);
1507 #endif /* PERL_OBJECT */
1509 #endif /* PERL_IMPLICIT_SYS */
1511 extern HANDLE w32_perldll_handle;
1512 static DWORD g_TlsAllocIndex;
1514 EXTERN_C DllExport bool
1515 SetPerlInterpreter(void *interp)
1517 return TlsSetValue(g_TlsAllocIndex, interp);
1520 EXTERN_C DllExport void*
1521 GetPerlInterpreter(void)
1523 return TlsGetValue(g_TlsAllocIndex);
1526 EXTERN_C DllExport int
1527 RunPerl(int argc, char **argv, char **env)
1530 PerlInterpreter *my_perl;
1531 struct perl_thread *thr;
1533 #ifndef __BORLANDC__
1534 /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
1535 * want to free() argv after main() returns. As luck would have it,
1536 * Borland's CRT does the right thing to argv[0] already. */
1537 char szModuleName[MAX_PATH];
1540 GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
1541 (void)win32_longpath(szModuleName);
1542 argv[0] = szModuleName;
1545 #ifdef PERL_GLOBAL_STRUCT
1546 #define PERLVAR(var,type) /**/
1547 #define PERLVARA(var,type) /**/
1548 #define PERLVARI(var,type,init) PL_Vars.var = init;
1549 #define PERLVARIC(var,type,init) PL_Vars.var = init;
1550 #include "perlvars.h"
1557 PERL_SYS_INIT(&argc,&argv);
1559 if (!(my_perl = perl_alloc()))
1561 perl_construct( my_perl );
1562 PL_perl_destruct_level = 0;
1564 exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
1566 #ifdef USE_ITHREADS /* XXXXXX testing */
1567 extern PerlInterpreter * perl_clone(pTHXx_ IV flags);
1569 PerlInterpreter *new_perl = perl_clone(my_perl, 0);
1570 Perl_push_scope(new_perl); /* ENTER; (hack in lieu of perl_destruct()) */
1571 exitstatus = perl_run( new_perl );
1572 perl_destruct(new_perl); perl_free(new_perl);
1573 SetPerlInterpreter(my_perl);
1575 exitstatus = perl_run( my_perl );
1579 perl_destruct( my_perl );
1580 perl_free( my_perl );
1584 return (exitstatus);
1588 DllMain(HANDLE hModule, /* DLL module handle */
1589 DWORD fdwReason, /* reason called */
1590 LPVOID lpvReserved) /* reserved */
1592 switch (fdwReason) {
1593 /* The DLL is attaching to a process due to process
1594 * initialization or a call to LoadLibrary.
1596 case DLL_PROCESS_ATTACH:
1597 /* #define DEFAULT_BINMODE */
1598 #ifdef DEFAULT_BINMODE
1599 setmode( fileno( stdin ), O_BINARY );
1600 setmode( fileno( stdout ), O_BINARY );
1601 setmode( fileno( stderr ), O_BINARY );
1604 g_TlsAllocIndex = TlsAlloc();
1605 DisableThreadLibraryCalls(hModule);
1606 w32_perldll_handle = hModule;
1609 /* The DLL is detaching from a process due to
1610 * process termination or call to FreeLibrary.
1612 case DLL_PROCESS_DETACH:
1613 TlsFree(g_TlsAllocIndex);
1616 /* The attached process creates a new thread. */
1617 case DLL_THREAD_ATTACH:
1620 /* The thread of the attached process terminates. */
1621 case DLL_THREAD_DETACH: