confstr.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 __UCLIBC_HAS_LINUXTHREADS__
  39. string = "linuxthreads-0.01";
  40. string_len = sizeof("linuxthreads-x.xx");
  41. # elif defined __UCLIBC_HAS_THREADS_NATIVE__
  42. # define __NPTL_VERSION ("NPTL " \
  43. __stringify(__UCLIBC_MAJOR__) "." \
  44. __stringify(__UCLIBC_MINOR__) "." \
  45. __stringify(__UCLIBC_SUBLEVEL__))
  46. string = __NPTL_VERSION;
  47. string_len = sizeof(__NPTL_VERSION);
  48. # else
  49. # error unable to determine thread impl
  50. # endif
  51. break;
  52. #endif
  53. default:
  54. __set_errno (EINVAL);
  55. return 0;
  56. }
  57. if (len > 0 && buf != NULL)
  58. {
  59. if (string_len <= len)
  60. memcpy (buf, string, string_len);
  61. else
  62. {
  63. memcpy (buf, string, len - 1);
  64. buf[len - 1] = '\0';
  65. }
  66. }
  67. return string_len;
  68. }