Commit 6d13380e authored by A. Wilcox's avatar A. Wilcox

Merge branch 'patch-5' into 'master'

pthread: Fix pthread_getname_np

Remove the trailing newline, and ensure the string
returned is always null-terminated.
Signed-off-by: Samuel Holland's avatarSamuel Holland <samuel@sholland.org>

See merge request !5
parents 70add834 40e85cf9
......@@ -38,15 +38,17 @@ weak_alias(__register_atfork, register_atfork);
int pthread_getname_np(pthread_t thread, char *name, size_t len)
{
int fd = open("/proc/thread-self/comm", O_RDONLY | O_CLOEXEC);
char dummy;
ssize_t n;
if (fd < 0)
return errno;
if (read(fd, name, len) < 0)
n = read(fd, name, len);
if (n < 0)
return errno;
/* If there's more to read, the buffer was too small. */
if (read(fd, &dummy, 1) > 0)
/* If the trailing newline was not read, the buffer was too small. */
if (n == 0 || name[n - 1] != '\n')
return ERANGE;
name[n - 1] = '\0';
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment