delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/10/27/17:24:24

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-Id: <200010272122.e9RLMnP11586@stay.intouchsys.com>
To: cygwin AT sourceware DOT cygnus DOT com
Subject: sh-utils: need interface to realpath()
Date: Fri, 27 Oct 2000 17:22:48 EDT
From: Stephen Gildea <gildea AT intouchsys DOT com>

I find I need a simple utility in a shell script: something to read
through symlinks and give me the true name of a file.  I don't see
anything in Bash (2.04), sh-utils (2.0), or Cygwin (1.0) that provides
this functionality.

There is a common Unix function realpath() that does what I want, but
it needs to be wrapped in a small utility program.

I'm not sure where to suggest this utility be added.  We needed it in
Cygwin to clean Cygwin pathnames of symlinks before passing them to
native NT programs, so I'm offering this here.

It is also possible the base GNU shell utilities would be a good place
to add such a program.

I'm appending one possible, simple implementation by my co-worker
Marc Neuberger.  It also handles interpreting the Cygwin root--
something else we need to expand before we can pass a pathname to
a native NT process.

 < Stephen


#include <stdio.h>
#include <errno.h>
#include <sys/cygwin.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    char    real[512];
    char    win32[512];
    int     i;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
        return 1;
    }

    
    realpath(argv[1], real);
    cygwin_conv_to_full_win32_path(real, win32);
    for (i= 0; win32[i]; i++) {
        if (win32[i] == '\\') {
            win32[i]= '/';
        }
    }
 
    printf("%s\n", win32);
}

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019