_fullpath

Description

Makes an absolute path name from a relative path name.

#include <stdlib.h>

char *_fullpath( char *buffer, const char *pathname, size_t maxlen );

buffer Full path-name buffer  
pathname Relative path name  
maxlen Length of the buffer pointed to by buffer  

Remarks

The _fullpath routine converts the partial path stored in pathname to a fully qualified path that is stored in buffer. Unlike _makepath, the _fullpath routine can be used with .\ and ..\ in the path.

If the length of the fully qualified path is greater than the value of maxlen, then NULL is returned; otherwise, the address of buffer is returned.

If the buffer is NULL, _fullpath will allocate a buffer of _MAX_PATH size using malloc and the maxlen argument is ignored. It is the caller's responsibility to deallocate this buffer (using free) as appropriate.

If the pathname argument specifies a disk drive, the current directory of this drive is combined with the path. If the drive is not valid, _fullpath returns NULL.

Return Value

The _fullpath function returns a pointer to the buffer containing the absolute path (buffer). If there is an error, _fullpath returns NULL.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_getcwd, _getdcwd, _makepath, _splitpath

Example

/* FULLPATH.C: This program demonstrates how _fullpath creates a full

* path from a partial path.

*/

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <direct.h>

char full[_MAX_PATH], part[_MAX_PATH];

void main( void )

{

while( 1 )

{

printf( "Enter partial path or ENTER to quit: " );

gets( part );

if( part[0] == 0 )

break;

if( _fullpath( full, part, _MAX_PATH ) != NULL )

printf( "Full path is: %s\n", full );

else

printf( "Invalid path\n" );

}

}

Output

Enter partial path or ENTER to quit: ..

Full path is: C:\

Enter partial path or ENTER to quit: ..\include

Full path is: C:\include

Enter partial path or ENTER to quit: p:

Full path is: P:\

Enter partial path or ENTER to quit: fullpath.c

Full path is: C:\LIBREF\fullpath.c

Enter partial path or ENTER to quit: