This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: converting between UNC and NT files names?


On Thu, 11 Dec 1997, Kevin Hughes wrote:

> Is there any easy way of converting between the unc used by the gnu tools for file names and the standard
> NT file names? I would like to call native NT tools directly from shell scripts but all the file names I have
> in variables etc. are in UNC format and the tools only understand the standard names.
> 

The attached piece of code may help you get started. Simply run it with
the posix filename(s) on the command line and it'll spit out both relative
and absolute win32 pathnames.

   % posix2win32path . //server/src
   . --> c:\tmp (.)
   //server/src --> \\server\src (\\server\src)

Regards, 
Mumit -- khan@xraylith.wisc.edu
http://www.xraylith.wisc.edu/~khan/

#include <iostream.h>
#include <stdlib.h>
#include <limits.h>		// PATH_MAX should be here, but instead
#include <sys/param.h>		//    it seems to be here.

//
// from path.h in cygwin32 distribution.
//
extern "C" {
void cygwin32_conv_to_win32_path (const char *src_path, char *win32_path);
void cygwin32_conv_to_full_win32_path (const char *src_path, char *win32_path);
}

int main (int argc, char* argv[]) {
    char win32_full_path [PATH_MAX];
    char win32_path [PATH_MAX];
    for (unsigned int i = 1; i < argc; ++i) {
	const char* posix_path = argv[i];
        cygwin32_conv_to_full_win32_path (posix_path, win32_full_path);
        cygwin32_conv_to_win32_path (posix_path, win32_path);
	cerr << posix_path << " --> " << win32_full_path 
	    << " (" << win32_path << ")" << endl;
    }
    exit (0);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]