]> sourceware.org Git - glibc.git/blob - posix/confstr.c
Update.
[glibc.git] / posix / confstr.c
1 /* Copyright (C) 1991,96,97,2000-2003, 2004 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 case _CS_V6_WIDTH_RESTRICTED_ENVS:
49 /* We have to return a newline-separated list of named of
50 programming environements in which the widths of blksize_t,
51 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
52 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
53 wint_t types are no greater than the width of type long.
54
55 Currently this means all environment which the system allows. */
56 {
57 static const char restenvs[] =
58 #if _POSIX_V6_ILP32_OFF32 > 0
59 "_POSIX_V6_ILP32_OFF32"
60 #endif
61 #if _POSIX_V6_ILP32_OFFBIG > 0
62 # if _POSIX_V6_ILP32_OFF32 > 0
63 "\n"
64 # endif
65 "_POSIX_V6_ILP32_OFFBIG"
66 #endif
67 #if _POSIX_V6_LP64_OFF64 > 0
68 # if _POSIX_V6_ILP32_OFF32 > 0 || _POSIX_V6_ILP32_OFFBIG > 0
69 "\n"
70 # endif
71 "_POSIX_V6_LP64_OFF64"
72 #endif
73 #if _POSIX_V6_LPBIG_OFFBIG > 0
74 # if _POSIX_V6_ILP32_OFF32 > 0 || _POSIX_V6_ILP32_OFFBIG > 0 \
75 || _POSIX_V6_LP64_OFF64 > 0
76 "\n"
77 # endif
78 "_POSIX_V6_LPBIG_OFFBIG"
79 #endif
80 ;
81 string = restenvs;
82 string_len = sizeof (restenvs);
83 }
84 break;
85
86 case _CS_XBS5_ILP32_OFFBIG_CFLAGS:
87 case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
88 case _CS_LFS_CFLAGS:
89 case _CS_LFS_LINTFLAGS:
90 #if _XBS5_LP64_OFF64 == -1 && _XBS5_LPBIG_OFFBIG == -1 && _XBS5_ILP32_OFFBIG == 1
91 /* Signal that we want the new ABI. */
92 {
93 static const char file_offset[]
94 = "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64";
95 string = file_offset;
96 string_len = sizeof (file_offset);
97 }
98 break;
99 #endif
100 /* FALLTHROUGH */
101
102 case _CS_LFS_LDFLAGS:
103 case _CS_LFS_LIBS:
104 /* No special libraries or linker flags needed. */
105 break;
106
107 case _CS_LFS64_CFLAGS:
108 case _CS_LFS64_LINTFLAGS:
109 if (sizeof (off_t) != sizeof (off64_t))
110 {
111 static const char lf64_source[] = "-D_LARGEFILE64_SOURCE";
112 string = lf64_source;
113 string_len = sizeof (lf64_source);
114 }
115 break;
116
117 case _CS_LFS64_LDFLAGS:
118 case _CS_LFS64_LIBS:
119 /* No special libraries or linker flags needed. */
120 break;
121
122 case _CS_XBS5_ILP32_OFF32_CFLAGS:
123 case _CS_XBS5_ILP32_OFF32_LDFLAGS:
124 case _CS_XBS5_ILP32_OFF32_LIBS:
125 case _CS_XBS5_ILP32_OFF32_LINTFLAGS:
126 case _CS_XBS5_ILP32_OFFBIG_LDFLAGS:
127 case _CS_XBS5_ILP32_OFFBIG_LIBS:
128 case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS:
129 case _CS_XBS5_LP64_OFF64_CFLAGS:
130 case _CS_XBS5_LP64_OFF64_LDFLAGS:
131 case _CS_XBS5_LP64_OFF64_LIBS:
132 case _CS_XBS5_LP64_OFF64_LINTFLAGS:
133 case _CS_XBS5_LPBIG_OFFBIG_CFLAGS:
134 case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS:
135 case _CS_XBS5_LPBIG_OFFBIG_LIBS:
136 case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS:
137
138 case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
139 case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
140 case _CS_POSIX_V6_ILP32_OFF32_LIBS:
141 case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS:
142 case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
143 case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
144 case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS:
145 case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
146 case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
147 case _CS_POSIX_V6_LP64_OFF64_LIBS:
148 case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS:
149 case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
150 case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
151 case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
152 case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS:
153 /* GNU libc does not require special actions to use LFS functions. */
154 break;
155
156 case _CS_GNU_LIBC_VERSION:
157 string = "glibc " VERSION;
158 string_len = sizeof ("glibc " VERSION);
159 break;
160
161 case _CS_GNU_LIBPTHREAD_VERSION:
162 #ifdef LIBPTHREAD_VERSION
163 string = LIBPTHREAD_VERSION;
164 string_len = sizeof LIBPTHREAD_VERSION;
165 break;
166 #else
167 /* No thread library. */
168 __set_errno (EINVAL);
169 return 0;
170 #endif
171
172 default:
173 __set_errno (EINVAL);
174 return 0;
175 }
176
177 if (len > 0 && buf != NULL)
178 {
179 if (string_len <= len)
180 memcpy (buf, string, string_len);
181 else
182 {
183 memcpy (buf, string, len - 1);
184 buf[len - 1] = '\0';
185 }
186 }
187 return string_len;
188 }
189 libc_hidden_def (confstr)
This page took 0.044501 seconds and 5 git commands to generate.