Help-Site Computer Manuals
  Algorithms & Data Structures   Programming Languages   Revision Control
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

Perl extension to get various conversions of path specifications in the Cygwin port of Perl.

Filesys::CygwinPaths - Perl extension to get various conversions of path specifications in the Cygwin port of Perl.


Filesys::CygwinPaths - Perl extension to get various conversions of path specifications in the Cygwin port of Perl.



    use Filesys::CygwinPaths;


        my $HOME = $ENV{'HOME'};

    my @pics_to_ogle = glob("$HOME/mypics/*.jpg");

        foreach my $pic (@pics_to_ogle) {


                vetted_path($pic), '/bf /pos=(0,0) /one', "/title=$pic")

         or die "No fun today!";


        system('C:/Applications/IrfanView/iview32', '/killmesoftly');


    use Filesys::CygwinPaths ':all';

        my $windows_groks_this = fullwin32path("$ENV{HOME}");

        my $posix_style = fullposixpath($ENV{'USERPROFILE'});

        if(posixpath($windows_groks_this) ne $posix_style)


           print "You don't keep your bash HOME in your NT Profile dir, huh?\n";



Filesys::CygwinPaths is a Cygwin-specific module created to ease the author's occasional pique over the little quirks that come up with using Perl on Cygwin, the free POSIX emulation psuedoplatform for Microsoft Windows(tm). The subroutines it exports allow various kinds of path conversions to be made in a fairly concise, simple, procedural manner. At the present time the module does not have an OO interface but one might be added in the future. The module can be used according to two diffent approaches, which are outlined below.

Note: Hopefully it is obvious that the module can be neither built nor used on any platform besides Perl for Cygwin, and there would be no reason to want to do so.

Usage Styles

Two slightly different ways of using Filesys::CygwinPaths are available. The first, and recommended, way is to tell Perl once and for all (for the duration of your script) what mode you need to use in conversing with, say external non-Cygwin applications. To do this, say something like:

        use Filesys::CygwinPaths;

         PATHS_mode( 'cyg_mixed' );

         my $own_name = vetted_path($0);

         print "I am $own_name, how are you today?\n";

And that will set the mode to cyg_mixed for the duration of the script or until you change it to something else.

The 3 recognized settings for $PATHSMODE are:

       cyg_mixed (like: C:/foobar/sugarplum/fairy.txt)         cyg_win32 (like: C:\foobar\sugarplum\fairy.txt)         cyg_posix (like: /cygdrive/c/sugarplum/fairy.txt

Alternatively you might prefer the more specific and elaborate full set of subroutines to be made available to you by name (:all). These can be called to get the specific translation mode you desire. Listed below. However, at present, using vetted_path is the only means by which to get ``mixed'' mode paths.

make any translations necessary to transform the path argument according to the setting of the global (Filesysy::CygwinPaths) variable $PATHSMODE. If this variable is not already set when vetted_path() is called, it will set to the default of cyg_mixed and complain a little at you. Set the script-wide mode you desire for vetted_path() to use by
(a) setting PATHSMODE directly in your script

   $PATHSMODE = 'cyg_posix';  # not "my" (!!)
(b) calling the subroutine PATHS_mode with the desired value. See below.

This function provides the ``mixed mode'' paths that aren't directly provided by any functions in the Cygwin API. That is its main raison d'tre.

set or query the current mode under which vetted_path will return a path spec.

return the POSIX-style path spec (filename) for the given argument. If the argument is a relative path, returns a relative path.

return the Win32 (Microsoft Windows standard) style path spec for the given argument. If the argument is a relative path, returns a relative path.

return the fully-qualified (absolute) path spec (filename) for the given argument, in POSIX-style.

return the fully-qualified path spec in Windows style.


 >= 0.04 -- see CHANGES file in distrubution archive.

  0.03 Added private subroutine to provide the HOME directory if the

       arg began with "~<something>". Added ucfirst() call to

       fullwin32path(), to force uniformity of results (all drive

       letters UpperCase). Changed all instances of using the term

       "protocol" in subs and variables to "mode".  ;-)

  0.02 First upload to CPAN (unregistered).

  0.01 First build.

Notes on the XS programming (C interface)


  • Another way to do the call to the xs interface would have been, maybe:
     sub conv_to_win32_path {
       my $in= shift(@_);
       my $out= "\0" x PATH_MAX();
       cygwin_conv_to_win 32_path($in,$out);
       return $out;


We shall see.

The return values (int C type) of the Cygwin functions are being discarded. The author confesses his crime. This may change in a future update, but for now, is how it is.


the File::Spec manpage, the File::Spec::Unix manpage, the File::Basename manpage, the File::PathConvert manpage, Env.


Tye McQueen for his XSeedingly generous help with the C interface work for this module. ;-)

Kazuko Andersen for her patience and for bringing food so I could finish working on this module ;-).


Soren (Michael) Andersen (CPAN id SOMIAN), <>.


This program is Copyright 2002 by Soren Andersen. This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

If you do not have a copy of the GNU General Public License write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.