aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/linux/pthread_setname_np.c
blob: 95c95c9922a80699b01d51ec3fcf224cf03c96b5 (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
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <assert.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>

int main() {
	int ret = pthread_setname_np(pthread_self(), "mlibc-test-123");
	assert(!ret);

	char buf[16];
	ret = pthread_getname_np(pthread_self(), buf, 16);
	assert(!ret);
	assert(!strcmp("mlibc-test-123", buf));

	ret = pthread_setname_np(pthread_self(), "mlibc-test-123-too-long");
	assert(ret == ERANGE);

	ret = pthread_getname_np(pthread_self(), buf, 1);
	assert(ret == ERANGE);

	ret = pthread_getname_np(pthread_self(), buf, 15);
	assert(ret == ERANGE);

	ret = pthread_getname_np(pthread_self(), buf, 16);
	assert(!ret);
	assert(!strcmp("mlibc-test-123", buf));

	return 0;
}