Back to index

python3.2  3.2.2
Defines | Functions
getcwd.c File Reference
#include <stdio.h>
#include <errno.h>

Go to the source code of this file.

Defines

#define PWD_CMD   "/bin/pwd"

Functions

char * getcwd (char *buf, int size)

Define Documentation

#define PWD_CMD   "/bin/pwd"

Definition at line 54 of file getcwd.c.


Function Documentation

char* getcwd ( char *  buf,
int  size 
)

Definition at line 58 of file getcwd.c.

{
    FILE *fp;
    char *p;
    int sts;
    if (size <= 0) {
        errno = EINVAL;
        return NULL;
    }
    if ((fp = popen(PWD_CMD, "r")) == NULL)
        return NULL;
    if (fgets(buf, size, fp) == NULL || (sts = pclose(fp)) != 0) {
        errno = EACCES; /* Most likely error */
        return NULL;
    }
    for (p = buf; *p != '\n'; p++) {
        if (*p == '\0') {
            errno = ERANGE;
            return NULL;
        }
    }
    *p = '\0';
    return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function: