www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/16/18:21:47

Date: Sun, 16 May 1999 21:55:20 +0200
From: Frank Heckenbach <frank AT tim DOT gerwinski DOT de>
Message-Id: <1C551283.19990516215520.FOO-2C58.frank@goedel.fjf.gnu.de>
X-Mailer: smtphack 0.3.4 by Jan Andres
To: eliz AT is DOT elta DOT co DOT il, djgpp-workers AT delorie DOT com
Subject: Re: realpath()
Reply-To: djgpp-workers AT delorie DOT com

> > :        Otherwise   it  returns  a  NULL  pointer  and  places  in
> > :        resolved_path the absolute pathname of the path  component
> > :        which  could not be resolved.
> 
> This is not very specific, and in fact I could interpret this in several 
> ways.  Could you please throw together a short test program and see what 
> it does with non-existent file names?

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/param.h>

int main ()
{
  char resolved_path [MAXPATHLEN];
  char *rp;
  printf ("Trying /bin/../usr/bin/foo/bar/baz\n");
  rp = realpath ("/bin/../usr/bin/foo/bar/baz", resolved_path);
  printf ("realpath returns: %s\n", rp ? rp : "NULL");
  printf ("resolved_path contains: %s\n\n", resolved_path);
  printf ("Trying /usr/../bin\n");
  rp = realpath ("/usr/../bin", resolved_path);
  printf ("realpath returns: %s\n", rp ? rp : "NULL");
  printf ("resolved_path contains: %s\n\n", resolved_path);
  return 0;
}

Under Linux (2.2.7, libc 5.4.46) it says:

Trying /bin/../usr/bin/foo/bar/baz
realpath returns: NULL
resolved_path contains: /usr/bin/foo

Trying /usr/../bin
realpath returns: /bin
resolved_path contains: /bin

(/usr/bin/foo, of course, does not exist on my system.)

Frank

-- 
Frank Heckenbach, frank AT fjf DOT gnu DOT de
http://fjf.gnu.de/
PGP and GPG keys: http://fjf.gnu.de/plan

- Raw text -


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