chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / posix / confstr.c
1 /* Copyright (C) 1991,1996,1997,2000-2004,2009 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #include <stddef.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <confstr.h>
24 #include "../version.h"
25
26 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
27    of BUF with the value corresponding to NAME and zero-terminate BUF.
28    Return the number of bytes required to hold NAME's entire value.  */
29 size_t
30 confstr (name, buf, len)
31      int name;
32      char *buf;
33      size_t len;
34 {
35   const char *string = "";
36   size_t string_len = 1;
37
38   switch (name)
39     {
40     case _CS_PATH:
41       {
42         static const char cs_path[] = CS_PATH;
43         string = cs_path;
44         string_len = sizeof (cs_path);
45       }
46       break;
47
48       /* eglibc: We share code in confstr.inc with cross-getconf.c.  */
49 #include "confstr.inc"
50       /* eglibc: end.  */
51
52     case _CS_XBS5_ILP32_OFF32_CFLAGS:
53     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
54     case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
55 #ifdef __ILP32_OFF32_CFLAGS
56 # if _POSIX_V7_ILP32_OFF32 == -1
57 #  error "__ILP32_OFF32_CFLAGS should not be defined"
58 # elif !defined _POSIX_V7_ILP32_OFF32
59       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
60         break;
61 # endif
62       string = __ILP32_OFF32_CFLAGS;
63       string_len = sizeof (__ILP32_OFF32_CFLAGS);
64 #endif
65       break;
66
67     case _CS_XBS5_ILP32_OFFBIG_CFLAGS:
68     case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
69     case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
70 #ifdef __ILP32_OFFBIG_CFLAGS
71 # if _POSIX_V7_ILP32_OFFBIG == -1
72 #  error "__ILP32_OFFBIG_CFLAGS should not be defined"
73 # elif !defined _POSIX_V7_ILP32_OFFBIG
74       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
75         break;
76 # endif
77       string = __ILP32_OFFBIG_CFLAGS;
78       string_len = sizeof (__ILP32_OFFBIG_CFLAGS);
79 #endif
80       break;
81
82     case _CS_XBS5_LP64_OFF64_CFLAGS:
83     case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
84     case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
85 #ifdef __LP64_OFF64_CFLAGS
86 # if _POSIX_V7_LP64_OFF64 == -1
87 #  error "__LP64_OFF64_CFLAGS should not be defined"
88 # elif !defined _POSIX_V7_LP64_OFF64
89       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
90         break;
91 # endif
92       string = __LP64_OFF64_CFLAGS;
93       string_len = sizeof (__LP64_OFF64_CFLAGS);
94 #endif
95       break;
96
97     case _CS_XBS5_ILP32_OFF32_LDFLAGS:
98     case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
99     case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
100 #ifdef __ILP32_OFF32_LDFLAGS
101 # if _POSIX_V7_ILP32_OFF32 == -1
102 #  error "__ILP32_OFF32_LDFLAGS should not be defined"
103 # elif !defined _POSIX_V7_ILP32_OFF32
104       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
105         break;
106 # endif
107       string = __ILP32_OFF32_LDFLAGS;
108       string_len = sizeof (__ILP32_OFF32_LDFLAGS);
109 #endif
110       break;
111
112     case _CS_XBS5_ILP32_OFFBIG_LDFLAGS:
113     case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
114     case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
115 #ifdef __ILP32_OFFBIG_LDFLAGS
116 # if _POSIX_V7_ILP32_OFFBIG == -1
117 #  error "__ILP32_OFFBIG_LDFLAGS should not be defined"
118 # elif !defined _POSIX_V7_ILP32_OFFBIG
119       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
120         break;
121 # endif
122       string = __ILP32_OFFBIG_LDFLAGS;
123       string_len = sizeof (__ILP32_OFFBIG_LDFLAGS);
124 #endif
125       break;
126
127     case _CS_XBS5_LP64_OFF64_LDFLAGS:
128     case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
129     case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
130 #ifdef __LP64_OFF64_LDFLAGS
131 # if _POSIX_V7_LP64_OFF64 == -1
132 #  error "__LP64_OFF64_LDFLAGS should not be defined"
133 # elif !defined _POSIX_V7_LP64_OFF64
134       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
135         break;
136 # endif
137       string = __LP64_OFF64_LDFLAGS;
138       string_len = sizeof (__LP64_OFF64_LDFLAGS);
139 #endif
140       break;
141
142     case _CS_LFS_CFLAGS:
143     case _CS_LFS_LINTFLAGS:
144 #if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
145 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
146       /* Signal that we want the new ABI.  */
147       string = __LFS_CFLAGS;
148       string_len = sizeof (__LFS_CFLAGS);
149 #endif
150       break;
151
152     case _CS_LFS_LDFLAGS:
153     case _CS_LFS_LIBS:
154       /* No special libraries or linker flags needed.  */
155       break;
156
157     case _CS_LFS64_CFLAGS:
158     case _CS_LFS64_LINTFLAGS:
159 #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE"
160       string = __LFS64_CFLAGS;
161       string_len = sizeof (__LFS64_CFLAGS);
162       break;
163
164     case _CS_LFS64_LDFLAGS:
165     case _CS_LFS64_LIBS:
166       /* No special libraries or linker flags needed.  */
167       break;
168
169     case _CS_XBS5_ILP32_OFF32_LIBS:
170     case _CS_XBS5_ILP32_OFF32_LINTFLAGS:
171     case _CS_XBS5_ILP32_OFFBIG_LIBS:
172     case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS:
173     case _CS_XBS5_LP64_OFF64_LIBS:
174     case _CS_XBS5_LP64_OFF64_LINTFLAGS:
175     case _CS_XBS5_LPBIG_OFFBIG_CFLAGS:
176     case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS:
177     case _CS_XBS5_LPBIG_OFFBIG_LIBS:
178     case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS:
179
180     case _CS_POSIX_V6_ILP32_OFF32_LIBS:
181     case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS:
182     case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
183     case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS:
184     case _CS_POSIX_V6_LP64_OFF64_LIBS:
185     case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS:
186     case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
187     case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
188     case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
189     case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS:
190
191     case _CS_POSIX_V7_ILP32_OFF32_LIBS:
192     case _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS:
193     case _CS_POSIX_V7_ILP32_OFFBIG_LIBS:
194     case _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS:
195     case _CS_POSIX_V7_LP64_OFF64_LIBS:
196     case _CS_POSIX_V7_LP64_OFF64_LINTFLAGS:
197     case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS:
198     case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS:
199     case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS:
200     case _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS:
201       /* GNU libc does not require special actions to use LFS functions.  */
202       break;
203
204     case _CS_GNU_LIBC_VERSION:
205       string = "glibc " VERSION;
206       string_len = sizeof ("glibc " VERSION);
207       break;
208
209     case _CS_GNU_LIBPTHREAD_VERSION:
210 #ifdef LIBPTHREAD_VERSION
211       string = LIBPTHREAD_VERSION;
212       string_len = sizeof LIBPTHREAD_VERSION;
213       break;
214 #else
215       /* No thread library.  */
216       __set_errno (EINVAL);
217       return 0;
218 #endif
219
220     default:
221       __set_errno (EINVAL);
222       return 0;
223     }
224
225   if (len > 0 && buf != NULL)
226     {
227       if (string_len <= len)
228         memcpy (buf, string, string_len);
229       else
230         {
231           memcpy (buf, string, len - 1);
232           buf[len - 1] = '\0';
233         }
234     }
235   return string_len;
236 }
237 libc_hidden_def (confstr)