Commit | Line | Data |
---|---|---|
0f4eea8f DL |
1 | |
2 | #include "iperlsys.h" | |
3 | ||
4 | extern CPerlObj *pPerl; | |
5 | ||
6 | #define CALLFUNC0RET(x)\ | |
7 | int ret = x;\ | |
8 | if (ret < 0)\ | |
9 | err = errno;\ | |
10 | return ret; | |
11 | ||
12 | #define PROCESS_AND_RETURN \ | |
13 | if (errno) \ | |
14 | err = errno; \ | |
15 | return r | |
16 | ||
17 | #define CALLFUNCRET(x)\ | |
18 | int ret = x;\ | |
19 | if (ret)\ | |
20 | err = errno;\ | |
21 | return ret; | |
22 | ||
23 | #define CALLFUNCERR(x)\ | |
24 | int ret = x;\ | |
25 | if (errno)\ | |
26 | err = errno;\ | |
27 | return ret; | |
28 | ||
29 | #define LCALLFUNCERR(x)\ | |
30 | long ret = x;\ | |
31 | if (errno)\ | |
32 | err = errno;\ | |
33 | return ret; | |
34 | ||
0f4eea8f DL |
35 | class CPerlDir : public IPerlDir |
36 | { | |
37 | public: | |
38 | CPerlDir() {}; | |
39 | virtual int Makedir(const char *dirname, int mode, int &err) | |
40 | { | |
41 | CALLFUNC0RET(win32_mkdir(dirname, mode)); | |
42 | }; | |
43 | virtual int Chdir(const char *dirname, int &err) | |
44 | { | |
45 | CALLFUNC0RET(win32_chdir(dirname)); | |
46 | }; | |
47 | virtual int Rmdir(const char *dirname, int &err) | |
48 | { | |
49 | CALLFUNC0RET(win32_rmdir(dirname)); | |
50 | }; | |
51 | virtual int Close(DIR *dirp, int &err) | |
52 | { | |
72311751 | 53 | return win32_closedir(dirp); |
0f4eea8f DL |
54 | }; |
55 | virtual DIR *Open(char *filename, int &err) | |
56 | { | |
72311751 | 57 | return win32_opendir(filename); |
0f4eea8f DL |
58 | }; |
59 | virtual struct direct *Read(DIR *dirp, int &err) | |
60 | { | |
72311751 | 61 | return win32_readdir(dirp); |
0f4eea8f DL |
62 | }; |
63 | virtual void Rewind(DIR *dirp, int &err) | |
64 | { | |
72311751 | 65 | win32_rewinddir(dirp); |
0f4eea8f DL |
66 | }; |
67 | virtual void Seek(DIR *dirp, long loc, int &err) | |
68 | { | |
72311751 | 69 | win32_seekdir(dirp, loc); |
0f4eea8f DL |
70 | }; |
71 | virtual long Tell(DIR *dirp, int &err) | |
72 | { | |
72311751 | 73 | return win32_telldir(dirp); |
0f4eea8f DL |
74 | }; |
75 | }; | |
76 | ||
77 | ||
78 | extern char * g_win32_get_privlib(char *pl); | |
79 | extern char * g_win32_get_sitelib(char *pl); | |
80 | ||
81 | class CPerlEnv : public IPerlEnv | |
82 | { | |
83 | public: | |
84 | CPerlEnv() {}; | |
85 | virtual char *Getenv(const char *varname, int &err) | |
86 | { | |
87 | return win32_getenv(varname); | |
88 | }; | |
89 | virtual int Putenv(const char *envstring, int &err) | |
90 | { | |
ac5c734f | 91 | return win32_putenv(envstring); |
0f4eea8f DL |
92 | }; |
93 | virtual char* LibPath(char *pl) | |
94 | { | |
95 | return g_win32_get_privlib(pl); | |
96 | }; | |
97 | virtual char* SiteLibPath(char *pl) | |
98 | { | |
99 | return g_win32_get_sitelib(pl); | |
100 | }; | |
b2af26b1 GS |
101 | virtual int Uname(struct utsname *name, int &err) |
102 | { | |
103 | return win32_uname(name); | |
104 | }; | |
a6c40364 GS |
105 | virtual char *Getenv_len(const char *varname, unsigned long *len, int &err) |
106 | { | |
107 | char *e = win32_getenv(varname); | |
108 | if (e) | |
109 | *len = strlen(e); | |
110 | return e; | |
111 | }; | |
0f4eea8f DL |
112 | }; |
113 | ||
114 | class CPerlSock : public IPerlSock | |
115 | { | |
116 | public: | |
117 | CPerlSock() {}; | |
118 | virtual u_long Htonl(u_long hostlong) | |
119 | { | |
120 | return win32_htonl(hostlong); | |
121 | }; | |
122 | virtual u_short Htons(u_short hostshort) | |
123 | { | |
124 | return win32_htons(hostshort); | |
125 | }; | |
126 | virtual u_long Ntohl(u_long netlong) | |
127 | { | |
128 | return win32_ntohl(netlong); | |
129 | }; | |
130 | virtual u_short Ntohs(u_short netshort) | |
131 | { | |
132 | return win32_ntohs(netshort); | |
133 | } | |
134 | ||
135 | virtual SOCKET Accept(SOCKET s, struct sockaddr* addr, int* addrlen, int &err) | |
136 | { | |
137 | SOCKET r = win32_accept(s, addr, addrlen); | |
138 | PROCESS_AND_RETURN; | |
139 | }; | |
140 | virtual int Bind(SOCKET s, const struct sockaddr* name, int namelen, int &err) | |
141 | { | |
142 | int r = win32_bind(s, name, namelen); | |
143 | PROCESS_AND_RETURN; | |
144 | }; | |
145 | virtual int Connect(SOCKET s, const struct sockaddr* name, int namelen, int &err) | |
146 | { | |
147 | int r = win32_connect(s, name, namelen); | |
148 | PROCESS_AND_RETURN; | |
149 | }; | |
150 | virtual void Endhostent(int &err) | |
151 | { | |
152 | win32_endhostent(); | |
153 | }; | |
154 | virtual void Endnetent(int &err) | |
155 | { | |
156 | win32_endnetent(); | |
157 | }; | |
158 | virtual void Endprotoent(int &err) | |
159 | { | |
160 | win32_endprotoent(); | |
161 | }; | |
162 | virtual void Endservent(int &err) | |
163 | { | |
164 | win32_endservent(); | |
165 | }; | |
166 | virtual struct hostent* Gethostbyaddr(const char* addr, int len, int type, int &err) | |
167 | { | |
168 | struct hostent *r = win32_gethostbyaddr(addr, len, type); | |
169 | PROCESS_AND_RETURN; | |
170 | }; | |
171 | virtual struct hostent* Gethostbyname(const char* name, int &err) | |
172 | { | |
173 | struct hostent *r = win32_gethostbyname(name); | |
174 | PROCESS_AND_RETURN; | |
175 | }; | |
176 | virtual struct hostent* Gethostent(int &err) | |
177 | { | |
178 | croak("gethostent not implemented!\n"); | |
179 | return NULL; | |
180 | }; | |
181 | virtual int Gethostname(char* name, int namelen, int &err) | |
182 | { | |
183 | int r = win32_gethostname(name, namelen); | |
184 | PROCESS_AND_RETURN; | |
185 | }; | |
186 | virtual struct netent *Getnetbyaddr(long net, int type, int &err) | |
187 | { | |
188 | struct netent *r = win32_getnetbyaddr(net, type); | |
189 | PROCESS_AND_RETURN; | |
190 | }; | |
191 | virtual struct netent *Getnetbyname(const char *name, int &err) | |
192 | { | |
193 | struct netent *r = win32_getnetbyname((char*)name); | |
194 | PROCESS_AND_RETURN; | |
195 | }; | |
196 | virtual struct netent *Getnetent(int &err) | |
197 | { | |
198 | struct netent *r = win32_getnetent(); | |
199 | PROCESS_AND_RETURN; | |
200 | }; | |
201 | virtual int Getpeername(SOCKET s, struct sockaddr* name, int* namelen, int &err) | |
202 | { | |
203 | int r = win32_getpeername(s, name, namelen); | |
204 | PROCESS_AND_RETURN; | |
205 | }; | |
206 | virtual struct protoent* Getprotobyname(const char* name, int &err) | |
207 | { | |
208 | struct protoent *r = win32_getprotobyname(name); | |
209 | PROCESS_AND_RETURN; | |
210 | }; | |
211 | virtual struct protoent* Getprotobynumber(int number, int &err) | |
212 | { | |
213 | struct protoent *r = win32_getprotobynumber(number); | |
214 | PROCESS_AND_RETURN; | |
215 | }; | |
216 | virtual struct protoent* Getprotoent(int &err) | |
217 | { | |
218 | struct protoent *r = win32_getprotoent(); | |
219 | PROCESS_AND_RETURN; | |
220 | }; | |
221 | virtual struct servent* Getservbyname(const char* name, const char* proto, int &err) | |
222 | { | |
223 | struct servent *r = win32_getservbyname(name, proto); | |
224 | PROCESS_AND_RETURN; | |
225 | }; | |
226 | virtual struct servent* Getservbyport(int port, const char* proto, int &err) | |
227 | { | |
228 | struct servent *r = win32_getservbyport(port, proto); | |
229 | PROCESS_AND_RETURN; | |
230 | }; | |
231 | virtual struct servent* Getservent(int &err) | |
232 | { | |
233 | struct servent *r = win32_getservent(); | |
234 | PROCESS_AND_RETURN; | |
235 | }; | |
236 | virtual int Getsockname(SOCKET s, struct sockaddr* name, int* namelen, int &err) | |
237 | { | |
238 | int r = win32_getsockname(s, name, namelen); | |
239 | PROCESS_AND_RETURN; | |
240 | }; | |
241 | virtual int Getsockopt(SOCKET s, int level, int optname, char* optval, int* optlen, int &err) | |
242 | { | |
243 | int r = win32_getsockopt(s, level, optname, optval, optlen); | |
244 | PROCESS_AND_RETURN; | |
245 | }; | |
246 | virtual unsigned long InetAddr(const char* cp, int &err) | |
247 | { | |
248 | unsigned long r = win32_inet_addr(cp); | |
249 | PROCESS_AND_RETURN; | |
250 | }; | |
251 | virtual char* InetNtoa(struct in_addr in, int &err) | |
252 | { | |
253 | char *r = win32_inet_ntoa(in); | |
254 | PROCESS_AND_RETURN; | |
255 | }; | |
256 | virtual int Listen(SOCKET s, int backlog, int &err) | |
257 | { | |
258 | int r = win32_listen(s, backlog); | |
259 | PROCESS_AND_RETURN; | |
260 | }; | |
261 | virtual int Recv(SOCKET s, char* buffer, int len, int flags, int &err) | |
262 | { | |
263 | int r = win32_recv(s, buffer, len, flags); | |
264 | PROCESS_AND_RETURN; | |
265 | }; | |
266 | virtual int Recvfrom(SOCKET s, char* buffer, int len, int flags, struct sockaddr* from, int* fromlen, int &err) | |
267 | { | |
268 | int r = win32_recvfrom(s, buffer, len, flags, from, fromlen); | |
269 | PROCESS_AND_RETURN; | |
270 | }; | |
271 | virtual int Select(int nfds, char* readfds, char* writefds, char* exceptfds, const struct timeval* timeout, int &err) | |
272 | { | |
273 | int r = win32_select(nfds, (Perl_fd_set*)readfds, (Perl_fd_set*)writefds, (Perl_fd_set*)exceptfds, timeout); | |
274 | PROCESS_AND_RETURN; | |
275 | }; | |
276 | virtual int Send(SOCKET s, const char* buffer, int len, int flags, int &err) | |
277 | { | |
278 | int r = win32_send(s, buffer, len, flags); | |
279 | PROCESS_AND_RETURN; | |
280 | }; | |
281 | virtual int Sendto(SOCKET s, const char* buffer, int len, int flags, const struct sockaddr* to, int tolen, int &err) | |
282 | { | |
283 | int r = win32_sendto(s, buffer, len, flags, to, tolen); | |
284 | PROCESS_AND_RETURN; | |
285 | }; | |
286 | virtual void Sethostent(int stayopen, int &err) | |
287 | { | |
288 | win32_sethostent(stayopen); | |
289 | }; | |
290 | virtual void Setnetent(int stayopen, int &err) | |
291 | { | |
292 | win32_setnetent(stayopen); | |
293 | }; | |
294 | virtual void Setprotoent(int stayopen, int &err) | |
295 | { | |
296 | win32_setprotoent(stayopen); | |
297 | }; | |
298 | virtual void Setservent(int stayopen, int &err) | |
299 | { | |
300 | win32_setservent(stayopen); | |
301 | }; | |
302 | virtual int Setsockopt(SOCKET s, int level, int optname, const char* optval, int optlen, int &err) | |
303 | { | |
304 | int r = win32_setsockopt(s, level, optname, optval, optlen); | |
305 | PROCESS_AND_RETURN; | |
306 | }; | |
307 | virtual int Shutdown(SOCKET s, int how, int &err) | |
308 | { | |
309 | int r = win32_shutdown(s, how); | |
310 | PROCESS_AND_RETURN; | |
311 | }; | |
312 | virtual SOCKET Socket(int af, int type, int protocol, int &err) | |
313 | { | |
314 | SOCKET r = win32_socket(af, type, protocol); | |
315 | PROCESS_AND_RETURN; | |
316 | }; | |
317 | virtual int Socketpair(int domain, int type, int protocol, int* fds, int &err) | |
318 | { | |
319 | croak("socketpair not implemented!\n"); | |
320 | return 0; | |
321 | }; | |
322 | virtual int Closesocket(SOCKET s, int& err) | |
323 | { | |
324 | int r = win32_closesocket(s); | |
325 | PROCESS_AND_RETURN; | |
326 | }; | |
327 | virtual int Ioctlsocket(SOCKET s, long cmd, u_long *argp, int& err) | |
328 | { | |
329 | int r = win32_ioctlsocket(s, cmd, argp); | |
330 | PROCESS_AND_RETURN; | |
331 | }; | |
332 | }; | |
333 | ||
334 | class CPerlLIO : public IPerlLIO | |
335 | { | |
336 | public: | |
337 | CPerlLIO() {}; | |
338 | virtual int Access(const char *path, int mode, int &err) | |
339 | { | |
340 | CALLFUNCRET(access(path, mode)) | |
341 | }; | |
342 | virtual int Chmod(const char *filename, int pmode, int &err) | |
343 | { | |
344 | CALLFUNCRET(chmod(filename, pmode)) | |
345 | }; | |
346 | virtual int Chown(const char *filename, uid_t owner, gid_t group, int &err) | |
347 | { | |
348 | CALLFUNCERR(chown(filename, owner, group)) | |
349 | }; | |
350 | virtual int Chsize(int handle, long size, int &err) | |
351 | { | |
352 | CALLFUNCRET(chsize(handle, size)) | |
353 | }; | |
354 | virtual int Close(int handle, int &err) | |
355 | { | |
356 | CALLFUNCRET(win32_close(handle)) | |
357 | }; | |
358 | virtual int Dup(int handle, int &err) | |
359 | { | |
360 | CALLFUNCERR(win32_dup(handle)) | |
361 | }; | |
362 | virtual int Dup2(int handle1, int handle2, int &err) | |
363 | { | |
364 | CALLFUNCERR(win32_dup2(handle1, handle2)) | |
365 | }; | |
366 | virtual int Flock(int fd, int oper, int &err) | |
367 | { | |
368 | CALLFUNCERR(win32_flock(fd, oper)) | |
369 | }; | |
370 | virtual int FileStat(int handle, struct stat *buffer, int &err) | |
371 | { | |
372 | CALLFUNCERR(fstat(handle, buffer)) | |
373 | }; | |
374 | virtual int IOCtl(int i, unsigned int u, char *data, int &err) | |
375 | { | |
376 | CALLFUNCERR(win32_ioctlsocket((SOCKET)i, (long)u, (u_long*)data)) | |
377 | }; | |
378 | virtual int Isatty(int fd, int &err) | |
379 | { | |
380 | return isatty(fd); | |
381 | }; | |
382 | virtual long Lseek(int handle, long offset, int origin, int &err) | |
383 | { | |
384 | LCALLFUNCERR(win32_lseek(handle, offset, origin)) | |
385 | }; | |
386 | virtual int Lstat(const char *path, struct stat *buffer, int &err) | |
387 | { | |
388 | return NameStat(path, buffer, err); | |
389 | }; | |
390 | virtual char *Mktemp(char *Template, int &err) | |
391 | { | |
392 | return mktemp(Template); | |
393 | }; | |
394 | virtual int Open(const char *filename, int oflag, int &err) | |
395 | { | |
396 | CALLFUNCERR(win32_open(filename, oflag)) | |
397 | }; | |
398 | virtual int Open(const char *filename, int oflag, int pmode, int &err) | |
399 | { | |
400 | int ret; | |
401 | if(stricmp(filename, "/dev/null") == 0) | |
402 | ret = open("NUL", oflag, pmode); | |
403 | else | |
404 | ret = open(filename, oflag, pmode); | |
405 | ||
406 | if(errno) | |
407 | err = errno; | |
408 | return ret; | |
409 | }; | |
410 | virtual int Read(int handle, void *buffer, unsigned int count, int &err) | |
411 | { | |
412 | CALLFUNCERR(win32_read(handle, buffer, count)) | |
413 | }; | |
414 | virtual int Rename(const char *OldFileName, const char *newname, int &err) | |
415 | { | |
e24c7c18 | 416 | CALLFUNCRET(win32_rename(OldFileName, newname)) |
0f4eea8f DL |
417 | }; |
418 | virtual int Setmode(int handle, int mode, int &err) | |
419 | { | |
420 | CALLFUNCRET(win32_setmode(handle, mode)) | |
421 | }; | |
422 | virtual int NameStat(const char *path, struct stat *buffer, int &err) | |
423 | { | |
424 | return win32_stat(path, buffer); | |
425 | }; | |
426 | virtual char *Tmpnam(char *string, int &err) | |
427 | { | |
428 | return tmpnam(string); | |
429 | }; | |
430 | virtual int Umask(int pmode, int &err) | |
431 | { | |
432 | return umask(pmode); | |
433 | }; | |
434 | virtual int Unlink(const char *filename, int &err) | |
435 | { | |
436 | chmod(filename, S_IREAD | S_IWRITE); | |
437 | CALLFUNCRET(unlink(filename)) | |
438 | }; | |
439 | virtual int Utime(char *filename, struct utimbuf *times, int &err) | |
440 | { | |
441 | CALLFUNCRET(win32_utime(filename, times)) | |
442 | }; | |
443 | virtual int Write(int handle, const void *buffer, unsigned int count, int &err) | |
444 | { | |
445 | CALLFUNCERR(win32_write(handle, buffer, count)) | |
446 | }; | |
447 | }; | |
448 | ||
449 | class CPerlMem : public IPerlMem | |
450 | { | |
451 | public: | |
452 | CPerlMem() {}; | |
453 | virtual void* Malloc(size_t size) | |
454 | { | |
455 | return win32_malloc(size); | |
456 | }; | |
457 | virtual void* Realloc(void* ptr, size_t size) | |
458 | { | |
459 | return win32_realloc(ptr, size); | |
460 | }; | |
461 | virtual void Free(void* ptr) | |
462 | { | |
463 | win32_free(ptr); | |
464 | }; | |
465 | }; | |
466 | ||
467 | #define EXECF_EXEC 1 | |
468 | #define EXECF_SPAWN 2 | |
469 | ||
470 | extern char * g_getlogin(void); | |
471 | extern int do_spawn2(char *cmd, int exectype); | |
472 | extern int g_do_aspawn(void *vreally, void **vmark, void **vsp); | |
473 | ||
474 | class CPerlProc : public IPerlProc | |
475 | { | |
476 | public: | |
477 | CPerlProc() {}; | |
478 | virtual void Abort(void) | |
479 | { | |
480 | win32_abort(); | |
481 | }; | |
ff95b63e DL |
482 | virtual char * Crypt(const char* clear, const char* salt) |
483 | { | |
484 | return win32_crypt(clear, salt); | |
485 | }; | |
0f4eea8f DL |
486 | virtual void Exit(int status) |
487 | { | |
488 | exit(status); | |
489 | }; | |
490 | virtual void _Exit(int status) | |
491 | { | |
492 | _exit(status); | |
493 | }; | |
494 | virtual int Execl(const char *cmdname, const char *arg0, const char *arg1, const char *arg2, const char *arg3) | |
495 | { | |
496 | return execl(cmdname, arg0, arg1, arg2, arg3); | |
497 | }; | |
498 | virtual int Execv(const char *cmdname, const char *const *argv) | |
499 | { | |
500 | return win32_execvp(cmdname, argv); | |
501 | }; | |
502 | virtual int Execvp(const char *cmdname, const char *const *argv) | |
503 | { | |
504 | return win32_execvp(cmdname, argv); | |
505 | }; | |
506 | virtual uid_t Getuid(void) | |
507 | { | |
508 | return getuid(); | |
509 | }; | |
510 | virtual uid_t Geteuid(void) | |
511 | { | |
512 | return geteuid(); | |
513 | }; | |
514 | virtual gid_t Getgid(void) | |
515 | { | |
516 | return getgid(); | |
517 | }; | |
518 | virtual gid_t Getegid(void) | |
519 | { | |
520 | return getegid(); | |
521 | }; | |
522 | virtual char *Getlogin(void) | |
523 | { | |
524 | return g_getlogin(); | |
525 | }; | |
526 | virtual int Kill(int pid, int sig) | |
527 | { | |
528 | return win32_kill(pid, sig); | |
529 | }; | |
530 | virtual int Killpg(int pid, int sig) | |
531 | { | |
532 | croak("killpg not implemented!\n"); | |
533 | return 0; | |
534 | }; | |
535 | virtual int PauseProc(void) | |
536 | { | |
537 | return win32_sleep((32767L << 16) + 32767); | |
538 | }; | |
539 | virtual PerlIO* Popen(const char *command, const char *mode) | |
540 | { | |
541 | win32_fflush(stdout); | |
542 | win32_fflush(stderr); | |
543 | return (PerlIO*)win32_popen(command, mode); | |
544 | }; | |
545 | virtual int Pclose(PerlIO *stream) | |
546 | { | |
547 | return win32_pclose((FILE*)stream); | |
548 | }; | |
549 | virtual int Pipe(int *phandles) | |
550 | { | |
551 | return win32_pipe(phandles, 512, O_BINARY); | |
552 | }; | |
553 | virtual int Setuid(uid_t u) | |
554 | { | |
555 | return setuid(u); | |
556 | }; | |
557 | virtual int Setgid(gid_t g) | |
558 | { | |
559 | return setgid(g); | |
560 | }; | |
561 | virtual int Sleep(unsigned int s) | |
562 | { | |
563 | return win32_sleep(s); | |
564 | }; | |
565 | virtual int Times(struct tms *timebuf) | |
566 | { | |
567 | return win32_times(timebuf); | |
568 | }; | |
569 | virtual int Wait(int *status) | |
570 | { | |
571 | return win32_wait(status); | |
572 | }; | |
573 | virtual int Waitpid(int pid, int *status, int flags) | |
574 | { | |
575 | return win32_waitpid(pid, status, flags); | |
576 | }; | |
577 | virtual Sighandler_t Signal(int sig, Sighandler_t subcode) | |
578 | { | |
579 | return 0; | |
580 | }; | |
581 | virtual void GetSysMsg(char*& sMsg, DWORD& dwLen, DWORD dwErr) | |
582 | { | |
583 | dwLen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
584 | |FORMAT_MESSAGE_IGNORE_INSERTS | |
585 | |FORMAT_MESSAGE_FROM_SYSTEM, NULL, | |
586 | dwErr, 0, (char *)&sMsg, 1, NULL); | |
587 | if (0 < dwLen) { | |
de030af3 | 588 | while (0 < dwLen && isSPACE(sMsg[--dwLen])) |
0f4eea8f DL |
589 | ; |
590 | if ('.' != sMsg[dwLen]) | |
591 | dwLen++; | |
592 | sMsg[dwLen]= '\0'; | |
593 | } | |
594 | if (0 == dwLen) { | |
595 | sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/); | |
db7c17d7 GS |
596 | if (sMsg) |
597 | dwLen = sprintf(sMsg, | |
598 | "Unknown error #0x%lX (lookup 0x%lX)", | |
599 | dwErr, GetLastError()); | |
0f4eea8f DL |
600 | } |
601 | }; | |
602 | virtual void FreeBuf(char* sMsg) | |
603 | { | |
604 | LocalFree(sMsg); | |
605 | }; | |
606 | virtual BOOL DoCmd(char *cmd) | |
607 | { | |
608 | do_spawn2(cmd, EXECF_EXEC); | |
609 | return FALSE; | |
610 | }; | |
611 | virtual int Spawn(char* cmds) | |
612 | { | |
613 | return do_spawn2(cmds, EXECF_SPAWN); | |
614 | }; | |
615 | virtual int Spawnvp(int mode, const char *cmdname, const char *const *argv) | |
616 | { | |
617 | return win32_spawnvp(mode, cmdname, argv); | |
618 | }; | |
619 | virtual int ASpawn(void *vreally, void **vmark, void **vsp) | |
620 | { | |
621 | return g_do_aspawn(vreally, vmark, vsp); | |
622 | }; | |
623 | }; | |
624 | ||
625 | ||
626 | class CPerlStdIO : public IPerlStdIO | |
627 | { | |
628 | public: | |
629 | CPerlStdIO() {}; | |
630 | virtual PerlIO* Stdin(void) | |
631 | { | |
632 | return (PerlIO*)win32_stdin(); | |
633 | }; | |
634 | virtual PerlIO* Stdout(void) | |
635 | { | |
636 | return (PerlIO*)win32_stdout(); | |
637 | }; | |
638 | virtual PerlIO* Stderr(void) | |
639 | { | |
640 | return (PerlIO*)win32_stderr(); | |
641 | }; | |
642 | virtual PerlIO* Open(const char *path, const char *mode, int &err) | |
643 | { | |
644 | PerlIO*pf = (PerlIO*)win32_fopen(path, mode); | |
645 | if(errno) | |
646 | err = errno; | |
647 | return pf; | |
648 | }; | |
649 | virtual int Close(PerlIO* pf, int &err) | |
650 | { | |
651 | CALLFUNCERR(win32_fclose(((FILE*)pf))) | |
652 | }; | |
653 | virtual int Eof(PerlIO* pf, int &err) | |
654 | { | |
655 | CALLFUNCERR(win32_feof((FILE*)pf)) | |
656 | }; | |
657 | virtual int Error(PerlIO* pf, int &err) | |
658 | { | |
659 | CALLFUNCERR(win32_ferror((FILE*)pf)) | |
660 | }; | |
661 | virtual void Clearerr(PerlIO* pf, int &err) | |
662 | { | |
663 | win32_clearerr((FILE*)pf); | |
664 | }; | |
665 | virtual int Getc(PerlIO* pf, int &err) | |
666 | { | |
667 | CALLFUNCERR(win32_getc((FILE*)pf)) | |
668 | }; | |
669 | virtual char* GetBase(PerlIO* pf, int &err) | |
670 | { | |
2bd2b9e0 GS |
671 | #ifdef FILE_base |
672 | FILE *f = (FILE*)pf; | |
673 | return FILE_base(f); | |
674 | #else | |
675 | return Nullch; | |
676 | #endif | |
0f4eea8f DL |
677 | }; |
678 | virtual int GetBufsiz(PerlIO* pf, int &err) | |
679 | { | |
7a5f8e82 | 680 | #ifdef FILE_bufsiz |
2bd2b9e0 GS |
681 | FILE *f = (FILE*)pf; |
682 | return FILE_bufsiz(f); | |
683 | #else | |
684 | return (-1); | |
685 | #endif | |
0f4eea8f DL |
686 | }; |
687 | virtual int GetCnt(PerlIO* pf, int &err) | |
688 | { | |
2bd2b9e0 GS |
689 | #ifdef USE_STDIO_PTR |
690 | FILE *f = (FILE*)pf; | |
691 | return FILE_cnt(f); | |
692 | #else | |
693 | return (-1); | |
694 | #endif | |
0f4eea8f DL |
695 | }; |
696 | virtual char* GetPtr(PerlIO* pf, int &err) | |
697 | { | |
2bd2b9e0 GS |
698 | #ifdef USE_STDIO_PTR |
699 | FILE *f = (FILE*)pf; | |
700 | return FILE_ptr(f); | |
701 | #else | |
702 | return Nullch; | |
703 | #endif | |
0f4eea8f DL |
704 | }; |
705 | virtual char* Gets(PerlIO* pf, char* s, int n, int& err) | |
706 | { | |
707 | char* ret = win32_fgets(s, n, (FILE*)pf); | |
708 | if(errno) | |
709 | err = errno; | |
710 | return ret; | |
711 | }; | |
712 | virtual int Putc(PerlIO* pf, int c, int &err) | |
713 | { | |
714 | CALLFUNCERR(win32_fputc(c, (FILE*)pf)) | |
715 | }; | |
716 | virtual int Puts(PerlIO* pf, const char *s, int &err) | |
717 | { | |
718 | CALLFUNCERR(win32_fputs(s, (FILE*)pf)) | |
719 | }; | |
720 | virtual int Flush(PerlIO* pf, int &err) | |
721 | { | |
722 | CALLFUNCERR(win32_fflush((FILE*)pf)) | |
723 | }; | |
724 | virtual int Ungetc(PerlIO* pf,int c, int &err) | |
725 | { | |
726 | CALLFUNCERR(win32_ungetc(c, (FILE*)pf)) | |
727 | }; | |
728 | virtual int Fileno(PerlIO* pf, int &err) | |
729 | { | |
730 | CALLFUNCERR(win32_fileno((FILE*)pf)) | |
731 | }; | |
732 | virtual PerlIO* Fdopen(int fd, const char *mode, int &err) | |
733 | { | |
734 | PerlIO* pf = (PerlIO*)win32_fdopen(fd, mode); | |
735 | if(errno) | |
736 | err = errno; | |
737 | return pf; | |
738 | }; | |
739 | virtual PerlIO* Reopen(const char*path, const char*mode, PerlIO* pf, int &err) | |
740 | { | |
741 | PerlIO* newPf = (PerlIO*)win32_freopen(path, mode, (FILE*)pf); | |
742 | if(errno) | |
743 | err = errno; | |
744 | return newPf; | |
745 | }; | |
746 | virtual SSize_t Read(PerlIO* pf, void *buffer, Size_t size, int &err) | |
747 | { | |
748 | SSize_t i = win32_fread(buffer, 1, size, (FILE*)pf); | |
749 | if(errno) | |
750 | err = errno; | |
751 | return i; | |
752 | }; | |
753 | virtual SSize_t Write(PerlIO* pf, const void *buffer, Size_t size, int &err) | |
754 | { | |
755 | SSize_t i = win32_fwrite(buffer, 1, size, (FILE*)pf); | |
756 | if(errno) | |
757 | err = errno; | |
758 | return i; | |
759 | }; | |
760 | virtual void SetBuf(PerlIO* pf, char* buffer, int &err) | |
761 | { | |
762 | win32_setbuf((FILE*)pf, buffer); | |
763 | }; | |
764 | virtual int SetVBuf(PerlIO* pf, char* buffer, int type, Size_t size, int &err) | |
765 | { | |
766 | int i = win32_setvbuf((FILE*)pf, buffer, type, size); | |
767 | if(errno) | |
768 | err = errno; | |
769 | return i; | |
770 | }; | |
771 | virtual void SetCnt(PerlIO* pf, int n, int &err) | |
772 | { | |
2bd2b9e0 GS |
773 | #ifdef STDIO_CNT_LVALUE |
774 | FILE *f = (FILE*)pf; | |
775 | FILE_cnt(f) = n; | |
776 | #endif | |
0f4eea8f DL |
777 | }; |
778 | virtual void SetPtrCnt(PerlIO* pf, char * ptr, int n, int& err) | |
779 | { | |
2bd2b9e0 GS |
780 | #ifdef STDIO_PTR_LVALUE |
781 | FILE *f = (FILE*)pf; | |
782 | FILE_ptr(f) = ptr; | |
783 | FILE_cnt(f) = n; | |
784 | #endif | |
0f4eea8f DL |
785 | }; |
786 | virtual void Setlinebuf(PerlIO* pf, int &err) | |
787 | { | |
788 | win32_setvbuf((FILE*)pf, NULL, _IOLBF, 0); | |
789 | }; | |
790 | virtual int Printf(PerlIO* pf, int &err, const char *format,...) | |
791 | { | |
792 | va_list(arglist); | |
793 | va_start(arglist, format); | |
794 | int i = win32_vfprintf((FILE*)pf, format, arglist); | |
795 | if(errno) | |
796 | err = errno; | |
797 | return i; | |
798 | }; | |
799 | virtual int Vprintf(PerlIO* pf, int &err, const char *format, va_list arglist) | |
800 | { | |
801 | int i = win32_vfprintf((FILE*)pf, format, arglist); | |
802 | if(errno) | |
803 | err = errno; | |
804 | return i; | |
805 | }; | |
806 | virtual long Tell(PerlIO* pf, int &err) | |
807 | { | |
808 | long l = win32_ftell((FILE*)pf); | |
809 | if(errno) | |
810 | err = errno; | |
811 | return l; | |
812 | }; | |
813 | virtual int Seek(PerlIO* pf, off_t offset, int origin, int &err) | |
814 | { | |
815 | int i = win32_fseek((FILE*)pf, offset, origin); | |
816 | if(errno) | |
817 | err = errno; | |
818 | return i; | |
819 | }; | |
820 | virtual void Rewind(PerlIO* pf, int &err) | |
821 | { | |
822 | win32_rewind((FILE*)pf); | |
823 | }; | |
824 | virtual PerlIO* Tmpfile(int &err) | |
825 | { | |
826 | PerlIO* pf = (PerlIO*)win32_tmpfile(); | |
827 | if(errno) | |
828 | err = errno; | |
829 | return pf; | |
830 | }; | |
831 | virtual int Getpos(PerlIO* pf, Fpos_t *p, int &err) | |
832 | { | |
833 | int i = win32_fgetpos((FILE*)pf, p); | |
834 | if(errno) | |
835 | err = errno; | |
836 | return i; | |
837 | }; | |
838 | virtual int Setpos(PerlIO* pf, const Fpos_t *p, int &err) | |
839 | { | |
840 | int i = win32_fsetpos((FILE*)pf, p); | |
841 | if(errno) | |
842 | err = errno; | |
843 | return i; | |
844 | }; | |
845 | virtual void Init(int &err) | |
846 | { | |
847 | }; | |
848 | virtual void InitOSExtras(void* p) | |
849 | { | |
850 | Perl_init_os_extras(); | |
851 | }; | |
852 | virtual int OpenOSfhandle(long osfhandle, int flags) | |
853 | { | |
854 | return win32_open_osfhandle(osfhandle, flags); | |
855 | } | |
856 | virtual int GetOSfhandle(int filenum) | |
857 | { | |
858 | return win32_get_osfhandle(filenum); | |
859 | } | |
860 | }; | |
861 | ||
862 | class CPerlHost | |
863 | { | |
864 | public: | |
865 | CPerlHost() { pPerl = NULL; }; | |
866 | inline BOOL PerlCreate(void) | |
867 | { | |
868 | try | |
869 | { | |
870 | pPerl = perl_alloc(&perlMem, &perlEnv, &perlStdIO, &perlLIO, | |
871 | &perlDir, &perlSock, &perlProc); | |
872 | if(pPerl != NULL) | |
873 | { | |
874 | try | |
875 | { | |
22c35a8c | 876 | perl_construct(); |
0f4eea8f DL |
877 | } |
878 | catch(...) | |
879 | { | |
880 | win32_fprintf(stderr, "%s\n", | |
881 | "Error: Unable to construct data structures"); | |
22c35a8c | 882 | perl_free(); |
0f4eea8f DL |
883 | pPerl = NULL; |
884 | } | |
885 | } | |
886 | } | |
887 | catch(...) | |
888 | { | |
889 | win32_fprintf(stderr, "%s\n", "Error: Unable to allocate memory"); | |
890 | pPerl = NULL; | |
891 | } | |
892 | return (pPerl != NULL); | |
893 | }; | |
894 | inline int PerlParse(void (*xs_init)(CPerlObj*), int argc, char** argv, char** env) | |
895 | { | |
896 | int retVal; | |
897 | try | |
898 | { | |
22c35a8c | 899 | retVal = perl_parse(xs_init, argc, argv, env); |
0f4eea8f DL |
900 | } |
901 | catch(int x) | |
902 | { | |
903 | // this is where exit() should arrive | |
904 | retVal = x; | |
905 | } | |
906 | catch(...) | |
907 | { | |
908 | win32_fprintf(stderr, "Error: Parse exception\n"); | |
909 | retVal = -1; | |
910 | } | |
911 | *win32_errno() = 0; | |
912 | return retVal; | |
913 | }; | |
914 | inline int PerlRun(void) | |
915 | { | |
916 | int retVal; | |
917 | try | |
918 | { | |
22c35a8c | 919 | retVal = perl_run(); |
0f4eea8f DL |
920 | } |
921 | catch(int x) | |
922 | { | |
923 | // this is where exit() should arrive | |
924 | retVal = x; | |
925 | } | |
926 | catch(...) | |
927 | { | |
928 | win32_fprintf(stderr, "Error: Runtime exception\n"); | |
929 | retVal = -1; | |
930 | } | |
931 | return retVal; | |
932 | }; | |
933 | inline void PerlDestroy(void) | |
934 | { | |
935 | try | |
936 | { | |
22c35a8c GS |
937 | perl_destruct(); |
938 | perl_free(); | |
0f4eea8f DL |
939 | } |
940 | catch(...) | |
941 | { | |
942 | } | |
943 | }; | |
944 | ||
945 | protected: | |
946 | CPerlDir perlDir; | |
947 | CPerlEnv perlEnv; | |
948 | CPerlLIO perlLIO; | |
949 | CPerlMem perlMem; | |
950 | CPerlProc perlProc; | |
951 | CPerlSock perlSock; | |
952 | CPerlStdIO perlStdIO; | |
953 | }; |