Mail Archives: cygwin/2000/10/27/17:24:24
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 -