]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/unistd/confstr.c
16b57bee9c72c1d5348b5b8bc4b1351516f4d12b
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / unistd / confstr.c
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     default:
46       __set_errno (EINVAL);
47       return 0;
48     }
49
50   if (len > 0 && buf != NULL)
51     {
52       if (string_len <= len)
53         memcpy (buf, string, string_len);
54       else
55         {
56           memcpy (buf, string, len - 1);
57           buf[len - 1] = '\0';
58         }
59     }
60   return string_len;
61 }