Mail Archives: djgpp-workers/1999/05/06/10:15:58
Bonjour
>
> On Wed, 5 May 1999, Frank Heckenbach wrote:
>
> > do you plan to support the realpath() function?
>
> Nobody asked for it until now (personally, I didn't even know such a
> function existed on Unix platforms).
>
> It should be easy to add a simple wrapper around _fixpath. Volunteers
> are welcome ;-)
>
> > AFAICS, the _fixpath() function is functionally
> > mostly equivalent, but the underscore suggests that it's not meant
> > for use from normal programs!?
>
> The underscore simply means that the name is not in any standard. A
> library is allowed to use such names without caring about name-space
> conflicts.
realpath() is not part of Posix.1, but it is in the Unix98 std :
On Un*x, one could use :
bash> cat resolv.c
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
int main (int argc, char ** argv)
{
char buffer [PATH_MAX];
char * path ;
if (argc == 2)
p = argv[1];
else
p = ".";
if (realpath(p, buffer) == 0)
perror("realpath");
else
printf("%s ==> %s\n", p, buffer);
return 0;
}
bash> make resolv
gcc resolv.c -o resolv
bash> resolv ../PlayGround/resolv.c
../PlayGround/resolv.c ==> /home/alain/PlayGround.c
bash> uname -rs
SunOS 5.6
------
Such functions are usually not very portable, for example on QNX wich
is is a distributed system, the node number is also part of the path.
So if you want to access a file on node 390:
//390/etc/passwd
//390/dev/ser1
But I must admit seeing it on almost all Un*x variants.
------------------------- for ref -------------------
realpath - resolve a pathname
SYNOPSIS
#include <stdlib.h>
char *realpath(const char *file_name, char *resolved_name);
DESCRIPTION
The realpath() function derives, from the pathname pointed to by file_name,
an absolute pathname that names the same file, whose resolution does not
involve ".", "..", or symbolic links. The generated pathname is stored, up
to a maximum of {PATH_MAX} bytes, in the buffer pointed to by resolved_name.
RETURN VALUE
On successful completion, realpath() returns a pointer to the resolved name.
Otherwise, realpath() returns a null pointer and sets errno to indicate the
error, and the contents of the buffer pointed to by resolved_name are
undefined.
ERRORS
The realpath() function will fail if:
[EACCES] Read or search permission was denied for a component of file_name.
[EINVAL] Either the file_name or resolved_name argument is a null pointer.
[EIO] An error occurred while reading from the file system.
[ELOOP] Too many symbolic links were encountered in resolving path.
[ENAMETOOLONG] The file_name argument is longer than {PATH_MAX} or a pathname
component is longer than {NAME_MAX}.
[ENOENT] A component of file_name does not name an existing file or file_name
points to an empty string.
[ENOTDIR] A component of the path prefix is not a directory.
The realpath() function may fail if:
[ENAMETOOLONG] Pathname resolution of a symbolic link produced an
intermediate result whose length exceeds {PATH_MAX}.
[ENOMEM] Insufficient storage space is available.
EXAMPLES
None.
APPLICATION USAGE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
getcwd(), sysconf(), <stdlib.h>.
--
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!
- Raw text -