1 /* $NetBSD: name.c,v 1.1 2003/02/26 22:05:03 thorpej Exp $ */
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
;
21 main(int argc
, char *argv
[])
23 pthread_t thr
, self
= pthread_self();
28 pthread_attr_init(&attr
);
29 assert(0 == pthread_attr_getname_np(&attr
, retname
, sizeof(retname
),
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
);
41 err(1, "pthread_create");
43 ret
= pthread_join(thr
, NULL
);
45 err(1, "pthread_join");
47 assert(ESRCH
== pthread_getname_np(thr
, retname
, sizeof(retname
)));
55 pthread_t self
= pthread_self();
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
));