7 #undef USE_DYNAMIC_LOADING
12 #include <sys/cygwin.h>
17 * pp_system() implemented via spawn()
18 * - more efficient and useful when embedding Perl in non-Cygwin apps
19 * - code mostly borrowed from djgpp.c
22 do_spawnvp (const char *path, const char * const *argv)
25 Sigsave_t ihand,qhand;
26 int childpid, result, status;
28 rsignal_save(SIGINT, (Sighandler_t) SIG_IGN, &ihand);
29 rsignal_save(SIGQUIT, (Sighandler_t) SIG_IGN, &qhand);
30 childpid = spawnvp(_P_NOWAIT,path,argv);
34 Perl_warner(aTHX_ packWARN(WARN_EXEC),"Can't spawn \"%s\": %s",
35 path,Strerror (errno));
38 result = wait4pid(childpid, &status, 0);
39 } while (result == -1 && errno == EINTR);
43 (void)rsignal_restore(SIGINT, &ihand);
44 (void)rsignal_restore(SIGQUIT, &qhand);
49 do_aspawn (SV *really, void **mark, void **sp)
53 char **a,*tmps,**argv;
58 a=argv=(char**) alloca ((sp-mark+3)*sizeof (char*));
62 *a++ = SvPVx((SV *)*mark, n_a);
67 if (argv[0][0] != '/' && argv[0][0] != '\\'
68 && !(argv[0][0] && argv[0][1] == ':'
69 && (argv[0][2] == '/' || argv[0][2] != '\\'))
70 ) /* will swawnvp use PATH? */
71 TAINT_ENV(); /* testing IFS here is overkill, probably */
73 if (really && *(tmps = SvPV(really, n_a)))
74 rc=do_spawnvp (tmps,(const char * const *)argv);
76 rc=do_spawnvp (argv[0],(const char *const *)argv);
85 char **a,*s,*metachars = "$&*(){}[]'\";\\?>|<~`\n";
86 const char *command[4];
88 while (*cmd && isSPACE(*cmd))
91 if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7]))
94 /* save an extra exec if possible */
95 /* see if there are shell metacharacters in it */
96 if (strstr (cmd,"..."))
98 if (*cmd=='.' && isSPACE (cmd[1]))
100 if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4]))
102 for (s=cmd; *s && isALPHA (*s); s++) ; /* catch VAR=val gizmo */
107 if (strchr (metachars,*s))
109 if (*s=='\n' && s[1]=='\0')
120 return do_spawnvp("sh",command);
123 Newx (PL_Argv,(s-cmd)/2+2,char*);
124 PL_Cmd=savepvn (cmd,s-cmd);
126 for (s=PL_Cmd; *s;) {
127 while (*s && isSPACE (*s)) s++;
130 while (*s && !isSPACE (*s)) s++;
138 return do_spawnvp(PL_Argv[0],(const char * const *)PL_Argv);
141 /* see also Cwd.pm */
148 Perl_croak(aTHX_ "Usage: Cwd::cwd()");
149 if((cwd = getcwd(NULL, -1))) {
150 ST(0) = sv_2mortal(newSVpv(cwd, 0));
152 #ifndef INCOMPLETE_TAINTS
160 XS(XS_Cygwin_pid_to_winpid)
167 Perl_croak(aTHX_ "Usage: Cygwin::pid_to_winpid(pid)");
169 pid = (pid_t)SvIV(ST(0));
171 if ((RETVAL = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid)) > 0) {
172 XSprePUSH; PUSHi((IV)RETVAL);
178 XS(XS_Cygwin_winpid_to_pid)
185 Perl_croak(aTHX_ "Usage: Cygwin::winpid_to_pid(pid)");
187 pid = (pid_t)SvIV(ST(0));
189 if ((RETVAL = cygwin32_winpid_to_pid(pid)) > 0) {
190 XSprePUSH; PUSHi((IV)RETVAL);
196 XS(XS_Cygwin_win_to_posix_path)
199 int absolute_flag = 0;
202 char *pathname, *buf;
204 if (items < 1 || items > 2)
205 Perl_croak(aTHX_ "Usage: Cygwin::win_to_posix_path(pathname, [absolute])");
207 pathname = SvPV(ST(0), len);
209 absolute_flag = SvTRUE(ST(1));
212 Perl_croak(aTHX_ "can't convert empty path");
213 buf = (char *) safemalloc (len + 260 + 1001);
216 err = cygwin_conv_to_full_posix_path(pathname, buf);
218 err = cygwin_conv_to_posix_path(pathname, buf);
220 ST(0) = sv_2mortal(newSVpv(buf, 0));
229 XS(XS_Cygwin_posix_to_win_path)
232 int absolute_flag = 0;
235 char *pathname, *buf;
237 if (items < 1 || items > 2)
238 Perl_croak(aTHX_ "Usage: Cygwin::posix_to_win_path(pathname, [absolute])");
240 pathname = SvPV(ST(0), len);
242 absolute_flag = SvTRUE(ST(1));
245 Perl_croak(aTHX_ "can't convert empty path");
246 buf = (char *) safemalloc(len + 260 + 1001);
249 err = cygwin_conv_to_full_win32_path(pathname, buf);
251 err = cygwin_conv_to_win32_path(pathname, buf);
253 ST(0) = sv_2mortal(newSVpv(buf, 0));
262 XS(XS_Cygwin_is_binmount)
268 Perl_croak(aTHX_ "Usage: Cygwin::is_binmount(pathname)");
270 pathname = SvPV_nolen(ST(0));
272 ST(0) = boolSV(cygwin_internal(CW_GET_BINMODE, pathname));
276 XS(XS_Cygwin_is_textmount)
282 Perl_croak(aTHX_ "Usage: Cygwin::is_textmount(pathname)");
284 pathname = SvPV_nolen(ST(0));
286 ST(0) = boolSV(!cygwin_internal(CW_GET_BINMODE, pathname));
294 char *file = __FILE__;
297 newXS("Cwd::cwd", Cygwin_cwd, file);
298 newXSproto("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file, "$");
299 newXSproto("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file, "$");
300 newXSproto("Cygwin::win_to_posix_path", XS_Cygwin_win_to_posix_path, file, "$;$");
301 newXSproto("Cygwin::posix_to_win_path", XS_Cygwin_posix_to_win_path, file, "$;$");
302 newXSproto("Cygwin::is_binmount", XS_Cygwin_is_binmount, file, "$");
303 newXSproto("Cygwin::is_textmount", XS_Cygwin_is_textmount, file, "$");
305 /* Initialize Win32CORE if it has been statically linked. */
306 handle = dlopen(NULL, RTLD_LAZY);
308 void (*pfn_init)(pTHX);
309 pfn_init = (void (*)(pTHX))dlsym(handle, "init_Win32CORE");