Skip to content

Commit 7871fb4

Browse files
committed
add test
Created using spr 1.3.4
1 parent 2aafa62 commit 7871fb4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %clangxx -O0 %s -o %t && %run %t
2+
3+
// REQUIRES: glibc
4+
5+
#include <arpa/inet.h>
6+
#include <assert.h>
7+
#include <netdb.h>
8+
9+
int main(void) {
10+
struct servent result_buf;
11+
struct servent *result;
12+
char buf[1024];
13+
assert(getservent_r(&result_buf, buf, sizeof(buf), &result) == 0);
14+
assert(result != nullptr);
15+
16+
// If these fail, check /etc/services if "ssh" exists. I picked this because
17+
// it should exist everywhere, if it doesn't, I am sorry. Disable the test
18+
// then please.
19+
assert(getservbyname_r("ssh", nullptr, &result_buf, buf, sizeof(buf),
20+
&result) == 0);
21+
assert(result != nullptr);
22+
assert(getservbyport_r(htons(22), nullptr, &result_buf, buf, sizeof(buf),
23+
&result) == 0);
24+
assert(result != nullptr);
25+
26+
assert(getservbyname_r("invalidhadfuiasdhi", nullptr, &result_buf, buf,
27+
sizeof(buf), &result) == 0);
28+
assert(result == nullptr);
29+
}

0 commit comments

Comments
 (0)