www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/13/23:26:18

From: Alain Magloire <alainm AT rcsm DOT ece DOT mcgill DOT ca>
Message-Id: <199905140324.XAA04586@mccoy2.ECE.McGill.CA>
Subject: Re: realpath()
To: eliz AT is DOT elta DOT co DOT il (Eli Zaretskii)
Date: Thu, 13 May 1999 23:24:50 -0400 (EDT)
Cc: djgpp-workers AT delorie DOT com
In-Reply-To: <Pine.SUN.3.91.990512192251.28259D-100000@is> from "Eli Zaretskii" at May 12, 99 07:23:46 pm
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Bonjour

> 
> On Wed, 12 May 1999, Alain Magloire wrote:
> 
> > I'm not sure about __file_exist, since, according to reference
> > on www.delorie.com/djgpp/doc/libc it does not seem to set the errno
> > appropriately.
> 
> It does.  Every library function in DJGPP that calls the OS sets errno as 
> an integral part of the OS call.

In that case here is a revised submission, below.

-- 
alain

----------------------------------------------------------
#include <stdlib.h>
+ char * realpath (const char *, char *);
--realpath.c--------------------------------------------------------
#include <stdlib.h>
#include <limits.h>
#include <sys/stat.h>
#include <errno.h>

char * realpath (const char * file_name, char * resolved_name)
{
  struct stat stbuf;

  if (file_name == NULL || resolved_name == NULL)
  {
     errno = EINVAL;
     return NULL;
  }

  if (*file_name == '\0')
  {
     errno = ENOENT;
     return NULL;
  }

  if (! __file_exists(file_name))
     return NULL;

  _fixpath (file_name, resolved_name);
  return resolved_name;
}
--realpath.txh--------------------------------------------------------
@node realpath, file system
@subheading Syntax

@example
#include <stdlib.h>

char * realpath(const char *in_path, char *out_path);
@end example

@subheading Description

This function checks for the existence of the file @var{in_path} and
stores the canonicalize result in the buffer pointed to by @var{out_path}.

The @var{out_path} is fixed according to the same then @xref{_fixpath}.

Since the returned path name can be longer than the original one, the
caller should ensure there is enough space in the buffer pointed to by
@var{out_path}.  Using ANSI-standard constant @code{FILENAME_MAX}
(defined on @file{stdio.h}) or Posix-standard constant @code{PATH_MAX}
(defined on @file{limits.h}) is recommended.

@subheading Return Value

On success, @code{realpath} returns a pointer to the resolved name. Otherwise,
null is return and the errno is set.

[EACCESS] Read or search permission denied.
[EINVAL]  Either @var{in_path} or @var{out_path} is a null pointer.
[ENOENT]  @var{in_path} is empty string or file does not exist.

@subheading Portability

@portability !ansi, !posix, unix98

@subheading Example

@example
char oldpath[100], newpath[PATH_MAX];
scanf(oldpath);
if (realpath(oldpath, newpath) != NULL);
  printf("that really is %s\n", newpath);
@end example

- Raw text -


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