Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / name / name.c
bloba115a20e182edeb8c77f2b2ef473f1d0ad77d634
1 /* $NetBSD: name.c,v 1.1 2003/02/26 22:05:03 thorpej Exp $ */
3 #include <assert.h>
4 #include <err.h>
5 #include <errno.h>
6 #include <pthread.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
12 void *threadfunc(void *arg);
14 #define NAME_TOO_LONG "12345678901234567890123456789012" /* 32 chars */
15 #define NAME_JUST_RIGHT "1234567890123456789012345678901" /* 31 chars */
17 #define CONST_NAME "xyzzy"
18 char non_const_name[] = CONST_NAME;
20 int
21 main(int argc, char *argv[])
23 pthread_t thr, self = pthread_self();
24 pthread_attr_t attr;
25 char retname[32];
26 int ret;
28 pthread_attr_init(&attr);
29 assert(0 == pthread_attr_getname_np(&attr, retname, sizeof(retname),
30 NULL));
31 assert(retname[0] == '\0');
32 assert(EINVAL == pthread_attr_setname_np(&attr, NAME_TOO_LONG, NULL));
33 assert(0 == pthread_attr_setname_np(&attr, "%s", NAME_JUST_RIGHT));
35 strcpy(retname, "foo");
36 assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
37 assert(retname[0] == '\0');
39 ret = pthread_create(&thr, &attr, threadfunc, NULL);
40 if (ret != 0)
41 err(1, "pthread_create");
43 ret = pthread_join(thr, NULL);
44 if (ret != 0)
45 err(1, "pthread_join");
47 assert(ESRCH == pthread_getname_np(thr, retname, sizeof(retname)));
49 return 0;
52 void *
53 threadfunc(void *arg)
55 pthread_t self = pthread_self();
56 char retname[32];
58 assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
59 assert(0 == strcmp(retname, NAME_JUST_RIGHT));
61 assert(0 == pthread_setname_np(self, non_const_name, NULL));
62 memset(non_const_name, 0, sizeof(non_const_name));
63 assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
64 assert(0 == strcmp(retname, CONST_NAME));
66 return NULL;