aboutsummaryrefslogtreecommitdiffstats
path: root/getcwd.c
blob: 38c7bcfa511c89c21fd5a476daf2744042bf5f6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


char *
libsimple_getcwd(void)
{
	char *cwd = NULL, *new;
	size_t cwd_size = 0;

	for (;;) {
		new = realloc(cwd, cwd_size += 512);
		if (!new)
			goto error;
		cwd = new;
		if (getcwd(cwd, cwd_size))
			break;
		if (errno != ERANGE)
			goto error;
	}

	return cwd;

error:
	free(cwd);
	return NULL;
}


#else
#include "test.h"

int
main(void) /* TODO test */
{
	return 0;
}

#endif