summaryrefslogtreecommitdiff
path: root/libgcompat/netdb.c
blob: ae7713ac08c79932e646e26c2945c429ea251c0e (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <errno.h>  /* ENOENT */
#include <netdb.h>  /* getproto* */
#include <stddef.h> /* NULL, size_t */
#include <string.h> /* memcpy */

/**
 * Retrieve information from the network protocol database by protocol name,
 * reentrantly.
 *
 * LSB 5.0: LSB-Core-generic/baselib-getprotobyname-r.html
 */
int getprotobyname_r(const char *name, struct protoent *result_buf, char *buf,
                     size_t buflen, struct protoent **result)
{
	struct protoent *prototmp = getprotobyname(name);

	/* musl does not reuse static storage, so no race is possible. */
	if (prototmp == NULL) {
		*result = NULL;
		return ENOENT;
	}
	*result = memcpy(result_buf, prototmp, sizeof(*result_buf));

	return 0;
}

/**
 * Retrieve information from the network protocol database by protocol number,
 * reentrantly.
 *
 * LSB 5.0: LSB-Core-generic/baselib-getprotobynumber-r.html
 */
int getprotobynumber_r(int proto, struct protoent *result_buf, char *buf,
                       size_t buflen, struct protoent **result)
{
	struct protoent *prototmp = getprotobynumber(proto);

	/* musl does not reuse static storage, so no race is possible. */
	if (prototmp == NULL) {
		*result = NULL;
		return ENOENT;
	}
	*result = memcpy(result_buf, prototmp, sizeof(*result_buf));

	return 0;
}

/**
 * Read the next entry of the protocol database, reentrantly.
 *
 * LSB 5.0: LSB-Core-generic/baselib-getprotoent-r.html
 */
int getprotoent_r(struct protoent *result_buf, char *buf, size_t buflen,
                  struct protoent **result)
{
	struct protoent *prototmp = getprotoent();

	/* musl does not reuse static storage, so no race is possible. */
	if (prototmp == NULL) {
		*result = NULL;
		return ENOENT;
	}
	*result = memcpy(result_buf, prototmp, sizeof(*result_buf));

	return 0;
}

/**
 * Read the next entry of the network services database, reentrantly.
 *
 * LSB 5.0: LSB-Core-generic/baselib-getservent-r.html
 */
int getservent_r(struct servent *result_buf, char *buf, size_t buflen,
                 struct servent **result)
{
	/* musl does not implement getservent(). */
	*result = NULL;
	return ENOENT;
}