summaryrefslogtreecommitdiff
path: root/cygwin
diff options
context:
space:
mode:
authorReini Urban <rurban@x-ray.at>2007-07-07 17:00:54 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-07-09 08:20:32 +0000
commit15414d2b8179f5759172a843e63bd4f4857b021d (patch)
tree365b9feafa15f6262963724e96a2afb7991140a8 /cygwin
parentd1e86c407abee5529d4bd5338b54adfb901e3d73 (diff)
downloadperl-15414d2b8179f5759172a843e63bd4f4857b021d.tar.gz
cygwin path conversions, take 4
From: "Reini Urban" <rurban@x-ray.at> Message-ID: <6910a60707070600xa8638eak3c3f20b20ccc093a@mail.gmail.com> p4raw-id: //depot/perl@31568
Diffstat (limited to 'cygwin')
-rw-r--r--cygwin/cygwin.c101
1 files changed, 99 insertions, 2 deletions
diff --git a/cygwin/cygwin.c b/cygwin/cygwin.c
index 2f6e2248b8..57f3b6a37c 100644
--- a/cygwin/cygwin.c
+++ b/cygwin/cygwin.c
@@ -193,6 +193,99 @@ XS(XS_Cygwin_winpid_to_pid)
XSRETURN_UNDEF;
}
+XS(XS_Cygwin_win_to_posix_path)
+{
+ dXSARGS;
+ int absolute_flag = 0;
+ STRLEN len;
+ int err;
+ char *pathname, *buf;
+
+ if (items < 1 || items > 2)
+ Perl_croak(aTHX_ "Usage: Cygwin::win_to_posix_path(pathname, [absolute])");
+
+ pathname = SvPV(ST(0), len);
+ if (items == 2)
+ absolute_flag = SvTRUE(ST(1));
+
+ if (!len)
+ Perl_croak(aTHX_ "can't convert empty path");
+ buf = (char *) safemalloc (len + 260 + 1001);
+
+ if (absolute_flag)
+ err = cygwin_conv_to_full_posix_path(pathname, buf);
+ else
+ err = cygwin_conv_to_posix_path(pathname, buf);
+ if (!err) {
+ ST(0) = sv_2mortal(newSVpv(buf, 0));
+ safefree(buf);
+ XSRETURN(1);
+ } else {
+ safefree(buf);
+ XSRETURN_UNDEF;
+ }
+}
+
+XS(XS_Cygwin_posix_to_win_path)
+{
+ dXSARGS;
+ int absolute_flag = 0;
+ STRLEN len;
+ int err;
+ char *pathname, *buf;
+
+ if (items < 1 || items > 2)
+ Perl_croak(aTHX_ "Usage: Cygwin::posix_to_win_path(pathname, [absolute])");
+
+ pathname = SvPV(ST(0), len);
+ if (items == 2)
+ absolute_flag = SvTRUE(ST(1));
+
+ if (!len)
+ Perl_croak(aTHX_ "can't convert empty path");
+ buf = (char *) safemalloc(len + 260 + 1001);
+
+ if (absolute_flag)
+ err = cygwin_conv_to_full_win32_path(pathname, buf);
+ else
+ err = cygwin_conv_to_win32_path(pathname, buf);
+ if (!err) {
+ ST(0) = sv_2mortal(newSVpv(buf, 0));
+ safefree(buf);
+ XSRETURN(1);
+ } else {
+ safefree(buf);
+ XSRETURN_UNDEF;
+ }
+}
+
+XS(XS_Cygwin_is_binmount)
+{
+ dXSARGS;
+ char *pathname;
+
+ if (items != 1)
+ Perl_croak(aTHX_ "Usage: Cygwin::is_binmount(pathname)");
+
+ pathname = SvPV_nolen(ST(0));
+
+ ST(0) = boolSV(cygwin_internal(CW_GET_BINMODE, pathname));
+ XSRETURN(1);
+}
+
+XS(XS_Cygwin_is_textmount)
+{
+ dXSARGS;
+ char *pathname;
+
+ if (items != 1)
+ Perl_croak(aTHX_ "Usage: Cygwin::is_textmount(pathname)");
+
+ pathname = SvPV_nolen(ST(0));
+
+ ST(0) = boolSV(!cygwin_internal(CW_GET_BINMODE, pathname));
+ XSRETURN(1);
+}
void
init_os_extras(void)
@@ -202,8 +295,12 @@ init_os_extras(void)
void *handle;
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);
+ newXSproto("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file, "$");
+ newXSproto("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file, "$");
+ newXSproto("Cygwin::win_to_posix_path", XS_Cygwin_win_to_posix_path, file, "$;$");
+ newXSproto("Cygwin::posix_to_win_path", XS_Cygwin_posix_to_win_path, file, "$;$");
+ newXSproto("Cygwin::is_binmount", XS_Cygwin_is_binmount, file, "$");
+ newXSproto("Cygwin::is_textmount", XS_Cygwin_is_textmount, file, "$");
/* Initialize Win32CORE if it has been statically linked. */
handle = dlopen(NULL, RTLD_LAZY);