This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
change to quiet cygwin's perlld
[perl5.git] / cygwin / cygwin.c
index db1c426..ceb2e81 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <unistd.h>
 #include <process.h>
+#include <sys/cygwin.h>
 
 /*
  * pp_system() implemented via spawn()
@@ -18,7 +19,7 @@
 static int
 do_spawnvp (const char *path, const char * const *argv)
 {
-    dTHXo;
+    dTHX;
     Sigsave_t ihand,qhand;
     int childpid, result, status;
 
@@ -27,11 +28,9 @@ do_spawnvp (const char *path, const char * const *argv)
     childpid = spawnvp(_P_NOWAIT,path,argv);
     if (childpid < 0) {
        status = -1;
-       if(ckWARN(WARN_EXEC)) {
-           dTHR;
-           Perl_warner(aTHX_ WARN_EXEC,"Can't spawn \"%s\": %s",
+       if(ckWARN(WARN_EXEC))
+           Perl_warner(aTHX_ packWARN(WARN_EXEC),"Can't spawn \"%s\": %s",
                    path,Strerror (errno));
-       }
     } else {
        do {
            result = wait4pid(childpid, &status, 0);
@@ -47,7 +46,7 @@ do_spawnvp (const char *path, const char * const *argv)
 int
 do_aspawn (SV *really, void **mark, void **sp)
 {
-    dTHXo;
+    dTHX;
     int  rc;
     char **a,*tmps,**argv; 
     STRLEN n_a; 
@@ -80,7 +79,7 @@ do_aspawn (SV *really, void **mark, void **sp)
 int
 do_spawn (char *cmd)
 {
-    dTHXo;
+    dTHX;
     char **a,*s,*metachars = "$&*(){}[]'\";\\?>|<~`\n";
     const char *command[4];
 
@@ -146,14 +145,50 @@ XS(Cygwin_cwd)
 
     if(items != 0)
        Perl_croak(aTHX_ "Usage: Cwd::cwd()");
-    if((cwd = getcwd(NULL, 0))) {
+    if((cwd = getcwd(NULL, -1))) {
        ST(0) = sv_2mortal(newSVpv(cwd, 0));
        safesysfree(cwd);
+#ifndef INCOMPLETE_TAINTS
+       SvTAINTED_on(ST(0));
+#endif
        XSRETURN(1);
     }
     XSRETURN_UNDEF;
 }
 
+static
+XS(XS_Cygwin_pid_to_winpid)
+{
+    dXSARGS;
+    if (items != 1)
+        Perl_croak(aTHX_ "Usage: Cygwin::pid_to_winpid(pid)");
+    pid_t pid = (pid_t)SvIV(ST(0));
+    pid_t RETVAL;
+    dXSTARG;
+    if ((RETVAL = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid)) > 0) {
+       XSprePUSH; PUSHi((IV)RETVAL);
+        XSRETURN(1);
+    }
+    XSRETURN_UNDEF;
+}
+
+static
+XS(XS_Cygwin_winpid_to_pid)
+{
+    dXSARGS;
+    if (items != 1)
+        Perl_croak(aTHX_ "Usage: Cygwin::winpid_to_pid(pid)");
+    pid_t pid = (pid_t)SvIV(ST(0));
+    pid_t RETVAL;
+    dXSTARG;
+    if ((RETVAL = cygwin32_winpid_to_pid(pid)) > 0) {
+        XSprePUSH; PUSHi((IV)RETVAL);
+        XSRETURN(1);
+    }
+    XSRETURN_UNDEF;
+}
+
+
 void
 init_os_extras(void)
 {
@@ -161,4 +196,6 @@ init_os_extras(void)
     dTHX;
 
     newXS("Cwd::cwd", Cygwin_cwd, file);
+    newXS("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file);
+    newXS("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file);
 }