leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

agetcwd.c
Go to the documentation of this file.
1#include "leafnode.h"
2#include <unistd.h>
3
4/* (C) Copyright 2004 by Matthias Andree */
5
6/** allocates a buffer (stores result into *buf and *size)
7 * and fetches the current working directory.
8 * *buf must be a malloc()d buffer or NULL on first call.
9 * returns success, *buf is free()d when FALSE is returned */
10int agetcwd(char **buf, size_t *size) {
11 while(1) {
12 if (*buf) {
13 if (getcwd(*buf, *size - 1))
14 return TRUE;
15 free(*buf);
16 *buf = NULL;
17 if (errno != ERANGE) {
18 return FALSE;
19 }
20 *size <<= 1;
21 } else {
22 *size = PATH_MAX;
23 }
24 *buf = critmalloc(*size, "agetcwd");
25 (*buf)[*size-1] = 0; /* NUL terminate always */
26 }
27}
28
29
int agetcwd(char **buf, size_t *size)
Definition: agetcwd.c:10
char * critmalloc(size_t size, const char *message)
Definition: critmem.c:61
#define TRUE
Definition: leafnode.h:29
#define FALSE
Definition: leafnode.h:32
#define PATH_MAX
Definition: leafnode.h:43