realpath

Returns the absolute path name of a file, with all references resolved.

Library:LibC
Classification:Single UNIX
Service:File and Directory I/O

Syntax

  #include <sys/stat.h> 
   
  char *realpath (
     const char   *file_name,
     char         *resolved_name );
  

Parameters

file_name

(IN) Points to the location and name of the file.

resolved_name

(OUT) Points to a buffer containing the path name of the file, with any ./ or ../ references resolved.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

5

ENOMEM

Insufficient memory to perform the operation.

9

EINVAL

Either the file_name or the resolved_name parameter contains invalid characters.

65

ENAMETOOLONG

The length of the path parameter exceeds the maximum path length, or a component in the path parameter is longer than the maximum length for a component.

105

ENOCONTEXT

The calling thread has no context.

Remarks

The realpath function derives from the path pointed to by the file_name parameter an absolute path name, which does not include any ./ or ../ references. The generated path name is stored as a null-terminated string in the resolved_name parameter. The type of path returned depends upon whether you are using POSIX path semantics. If you are, the resolved_name parameter uses POSIX semantics. If you are using NetWare semantics, the path returned uses NetWare semantics.

If you specify just a filename in the file_name paramter, the resolved_name parameter returns the full path of the file in the current working directory.

If you have compiled your NLM to use POSIX semantics, you can also use the realpath function to convert a NetWare path into a POSIX path. Use the file_name parameter for the NetWare path, and the resolved_name parameter returns the POSIX path, reflecting the information in the etc/pathtab file. For more information about this file, see Section 13.2, POSIX Path Semantics.

If you are using NetWare semantics, the file_name parameter must use NetWare semantics, and the resolved_name parameter always returns NetWare semantics.

See Also