| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

get_curdir

#include "sfldir.h"
char *
get_curdir (void)

Synopsis

Returns a buffer containing the current working directory. This buffer is allocated using the mem_alloc() function and should be freed using mem_free() when no longer needed. Returns NULL if there was insufficient memory to allocate the buffer, or if the system does not provide the current working directory information. Under Windows, replaces backslash characters by the UNIX-like slash. Under OpenVMS, returns directory name in POSIX format. Note that the directory name always ends in a slash (e.g. 'C:/' or 'C:/subdir/').

Source Code - (sfldir.c)

{
    char
        *curdir;                        /*  String we get from the OS        */

    curdir = mem_alloc (PATH_MAX + 1);

#if (defined (__UNIX__) || defined (__OS2__))
    getcwd (curdir, PATH_MAX);

#elif (defined (__VMS__))
    getcwd (curdir, PATH_MAX, 0);

#elif (defined (WIN32))
    GetCurrentDirectory (PATH_MAX, curdir);
    strconvch (curdir, '\\', '/');

#elif (defined (MSDOS_FILESYSTEM))
    getcwd (curdir, PATH_MAX);
    strconvch (curdir, '\\', '/');

#else
    strclr (curdir);
#endif

    /*  The directory must always end in a slash                             */
    if (strlast (curdir) != '/')
        strcat (curdir, "/");

    return (curdir);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation