summaryrefslogtreecommitdiff
path: root/src/unistd/confstr.c
blob: 0cf003195c1855108aee2184ea0bef1a7ac920ad (plain)
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
#include "sys/types.h"
#include <unistd.h>
#include "errno.h"
#include "string.h"
#include "nonstd/assert.h"

size_t confstr(int name, char *buf, size_t len)
{
	char *value = NULL;

	if (len > 0) {
		ASSERT_NONNULL(buf);
	}

	switch (name) {
	#include "_confstr.h"
	default:
		value = NULL;
		break;
	}

	if (value == NULL) {
		errno = EINVAL;
		return 0;
	}

	if (len > 0) {
		strncpy(buf, value, len);
	}

	return strlen(value);
}

/*
POSIX(2)
*/