Mail Archives: djgpp-workers/1999/05/13/23:26:18
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 -