fix issues with gdb 8.0
[uclibc-ng.git] / libc / unistd / confstr.c
blob4d4c217e5397cdef357ea5948f7645dc97f77464
1 /* Copyright (C) 1991, 1996, 1997, 2000-2002, 2003, 2004
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stddef.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <string.h>
25 #define CS_PATH "/bin:/usr/bin"
27 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
28 of BUF with the value corresponding to NAME and zero-terminate BUF.
29 Return the number of bytes required to hold NAME's entire value. */
30 size_t confstr (int name, char *buf, size_t len)
32 const char *string;
33 size_t string_len;
35 switch (name)
37 case _CS_PATH:
39 static const char cs_path[] = CS_PATH;
40 string = cs_path;
41 string_len = sizeof (cs_path);
43 break;
44 #ifdef __UCLIBC_HAS_THREADS__
45 case _CS_GNU_LIBPTHREAD_VERSION:
46 # if defined __UCLIBC_HAS_LINUXTHREADS__
47 string = "linuxthreads-0.01";
48 string_len = sizeof("linuxthreads-x.xx");
49 # elif defined __UCLIBC_HAS_THREADS_NATIVE__
50 # define __NPTL_VERSION ("NPTL " \
51 __stringify(__UCLIBC_MAJOR__) "." \
52 __stringify(__UCLIBC_MINOR__) "." \
53 __stringify(__UCLIBC_SUBLEVEL__))
54 string = __NPTL_VERSION;
55 string_len = sizeof(__NPTL_VERSION);
56 # else
57 # error unable to determine thread impl
58 # endif
59 break;
60 #endif
61 default:
62 __set_errno (EINVAL);
63 return 0;
66 if (len > 0 && buf != NULL)
68 if (string_len <= len)
69 memcpy (buf, string, string_len);
70 else
72 memcpy (buf, string, len - 1);
73 buf[len - 1] = '\0';
76 return string_len;