realpath -- returns the real file name


cc ...-lc

#include <stdlib.h>

char *realpath (const char *file_name, char *resolved_name);


realpath(S) resolves all links, symbolic links, and references to ``.'' and ``..'' in file_name and stores the path in resolved_name. It can handle both relative and absolute path names: resolved_name must be big enough (MAXPATHLEN) to contain the fully resolved path name.

realpath( ) operates on null-terminated strings.

You should have execute permission on all the directories in the given and the resolved path.

If an error occurs, realpath( ) may fail to return to the current directory.

Return values

If there is no error, realpath( ) returns a pointer to the resolved_name. Otherwise it returns a null pointer and places the name of the offending file in resolved_name. The global variable errno is set to indicate the error.


If any of the following conditions occur, this function returns -1 and sets errno to the corresponding value:

The system denied you read or search permission for some part of file_name.

One of the arguments file_name or resolved_name is a null pointer.

The function encountered an I/O error while reading from the file system.

The function found too many symbolic links while resolving the path.

Either file_name or a component of the path name is longer than PATH_MAX bytes.

Either a component of file_name does not exist or file_name points to an empty string.

Part of the pathname prefix is not a directory.
The following conditions might cause the function to fail:

Resolving a symbolic link in the pathname produced an intermediate result that is longer than PATH_MAX bytes.

There is not enough memory.

See also


Standards conformance

realpath(S) is conformant with

X/Open CAE Specification, System Interfaces and Headers, Issue 4, Version 2.

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003