confstr.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <stddef.h>
  17. #include <errno.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. libc_hidden_proto(memcpy)
  21. #define CS_PATH "/bin:/usr/bin"
  22. /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
  23. of BUF with the value corresponding to NAME and zero-terminate BUF.
  24. Return the number of bytes required to hold NAME's entire value. */
  25. size_t confstr (int name, char *buf, size_t len)
  26. {
  27. const char *string;
  28. size_t string_len;
  29. switch (name)
  30. {
  31. case _CS_PATH:
  32. {
  33. static const char cs_path[] = CS_PATH;
  34. string = cs_path;
  35. string_len = sizeof (cs_path);
  36. }
  37. break;
  38. default:
  39. __set_errno (EINVAL);
  40. return 0;
  41. }
  42. if (len > 0 && buf != NULL)
  43. {
  44. if (string_len <= len)
  45. memcpy (buf, string, string_len);
  46. else
  47. {
  48. memcpy (buf, string, len - 1);
  49. buf[len - 1] = '\0';
  50. }
  51. }
  52. return string_len;
  53. }