getcwd()                 Get Path Name of Current Working Directory
 
 #include   <direct.h>                   Required for declarations only
 
 char       *getcwd(pathbuf,n);
 char       *pathbuf;                    Storage location of path name
 int        n;                           Maximum length of path name
 
    getcwd() gets the full path name of the current working directory and
    stores it at 'pathbuf'.  The path name (including terminating NULL
    character) cannot be any longer than the integer specified by 'n'.
 
    Returns:    A pointer to 'pathbuf' if successful, or NULL if there is
                insufficient memory to allocate 'n' bytes, or the path
                name is too long. A NULL return value causes 'errno' to
                be set to:
 
                ENOMEM:  Insufficient memory; malloc() couldn't allocate
                         'n' bytes (see below); or
 
                ERANGE:  Path name longer than 'n' characters.
 
      Notes:    If the 'pathbuf' argument is NULL, the function will
                automatically allocate a buffer of size 'n', using
                malloc(). The buffer can be freed by using the return
                value of getcwd() (which is a pointer to the buffer) as
                the argument to free().
 
  -------------------------------- Example ---------------------------------
 
    The following statement stores the name of the current working
    directory in 'pbuff':
 
           #include <direct.h>         /* getcwd declared */
           #include <stdlib.h>         /* perror declared */
           #include <stdio.h>          /* NULL defined   */
 
           char pbuff[30];
 
           main()
           {
               if (getcwd(pbuff,64) == NULL)
                   perror("unable to get path name");
               else
                   printf("%s",pbuff);
           }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster