blob: 29d5a106d7a75bedc7ce77abe8bc5e06da4a0919 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
char *
libfonts_gethome__(struct libfonts_context *ctx)
{
uid_t uid = (ctx && ctx->use_context_uid) ? ctx->uid : getuid();
size_t size = 512;
char *buf = NULL, *new;
char *ret = NULL;
struct passwd pw, *pwp;
int err;
goto beginning;
do {
if (size > SIZE_MAX / 2)
goto enomem;
size *= 2;
beginning:
new = realloc(buf, size);
if (!new) {
enomem:
free(buf);
errno = ENOMEM;
return NULL;
}
buf = new;
} while ((err = getpwuid_r(uid, &pw, buf, size, &pwp)) == ERANGE);
if (err) {
free(buf);
return NULL;
}
if (pwp && pwp->pw_dir)
ret = strdup(pwp->pw_dir);
free(buf);
return ret;
}
#else
int
main(void)
{
return 0; /* XXX add test */
}
#endif
|