lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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. |
| 4 | |
| 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. |
| 9 | |
| 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. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, write to the Free |
| 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 18 | 02111-1307 USA. */ |
| 19 | |
| 20 | #include <stddef.h> |
| 21 | #include <errno.h> |
| 22 | #include <unistd.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | |
| 26 | #define CS_PATH "/bin:/usr/bin" |
| 27 | |
| 28 | /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes |
| 29 | of BUF with the value corresponding to NAME and zero-terminate BUF. |
| 30 | Return the number of bytes required to hold NAME's entire value. */ |
| 31 | size_t confstr (int name, char *buf, size_t len) |
| 32 | { |
| 33 | const char *string; |
| 34 | size_t string_len; |
| 35 | |
| 36 | switch (name) |
| 37 | { |
| 38 | case _CS_PATH: |
| 39 | { |
| 40 | static const char cs_path[] = CS_PATH; |
| 41 | string = cs_path; |
| 42 | string_len = sizeof (cs_path); |
| 43 | } |
| 44 | break; |
| 45 | #ifdef __UCLIBC_HAS_THREADS__ |
| 46 | case _CS_GNU_LIBPTHREAD_VERSION: |
| 47 | # if defined __LINUXTHREADS_OLD__ |
| 48 | string = "linuxthreads-0.01"; |
| 49 | string_len = sizeof("linuxthreads-x.xx"); |
| 50 | # elif defined __LINUXTHREADS_NEW__ |
| 51 | string = "linuxthreads-0.10"; |
| 52 | string_len = sizeof("linuxthreads-x.xx"); |
| 53 | # elif defined __UCLIBC_HAS_THREADS_NATIVE__ |
| 54 | # define __NPTL_VERSION ("NPTL " \ |
| 55 | __stringify(__UCLIBC_MAJOR__) "." \ |
| 56 | __stringify(__UCLIBC_MINOR__) "." \ |
| 57 | __stringify(__UCLIBC_SUBLEVEL__)) |
| 58 | string = __NPTL_VERSION; |
| 59 | string_len = sizeof(__NPTL_VERSION); |
| 60 | # else |
| 61 | # error unable to determine thread impl |
| 62 | # endif |
| 63 | break; |
| 64 | #endif |
| 65 | default: |
| 66 | __set_errno (EINVAL); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | if (len > 0 && buf != NULL) |
| 71 | { |
| 72 | if (string_len <= len) |
| 73 | memcpy (buf, string, string_len); |
| 74 | else |
| 75 | { |
| 76 | memcpy (buf, string, len - 1); |
| 77 | buf[len - 1] = '\0'; |
| 78 | } |
| 79 | } |
| 80 | return string_len; |
| 81 | } |