confstr.c 2.3 KB

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