Back to index

glibc  2.9
confstr.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1996, 1997, 2000-2002, 2003, 2004
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stddef.h>
00021 #include <errno.h>
00022 #include <unistd.h>
00023 #include <string.h>
00024 #include <confstr.h>
00025 #include "../version.h"
00026 
00027 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
00028    of BUF with the value corresponding to NAME and zero-terminate BUF.
00029    Return the number of bytes required to hold NAME's entire value.  */
00030 size_t
00031 confstr (name, buf, len)
00032      int name;
00033      char *buf;
00034      size_t len;
00035 {
00036   const char *string = "";
00037   size_t string_len = 1;
00038 
00039   switch (name)
00040     {
00041     case _CS_PATH:
00042       {
00043        static const char cs_path[] = CS_PATH;
00044        string = cs_path;
00045        string_len = sizeof (cs_path);
00046       }
00047       break;
00048 
00049     case _CS_V6_WIDTH_RESTRICTED_ENVS:
00050       /* We have to return a newline-separated list of named of
00051         programming environements in which the widths of blksize_t,
00052         cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
00053         ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
00054         wint_t types are no greater than the width of type long.
00055 
00056         Currently this means all environment which the system allows.  */
00057       {
00058        char restenvs[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
00059 
00060        string_len = 0;
00061 #ifndef _POSIX_V6_ILP32_OFF32
00062         if (__sysconf (_SC_V6_ILP32_OFF32) > 0)
00063 #endif
00064 #if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
00065           {
00066             memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFF32",
00067                     sizeof "POSIX_V6_ILP32_OFF32" - 1);
00068             string_len += sizeof "POSIX_V6_ILP32_OFF32" - 1;
00069           }
00070 #endif
00071 #ifndef _POSIX_V6_ILP32_OFFBIG
00072         if (__sysconf (_SC_V6_ILP32_OFFBIG) > 0)
00073 #endif
00074 #if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
00075           {
00076             if (string_len)
00077               restenvs[string_len++] = '\n';
00078             memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFFBIG",
00079                     sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
00080             string_len += sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
00081           }
00082 #endif
00083 #ifndef _POSIX_V6_LP64_OFF64
00084         if (__sysconf (_SC_V6_LP64_OFF64) > 0)
00085 #endif
00086 #if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
00087           {
00088             if (string_len)
00089               restenvs[string_len++] = '\n';
00090             memcpy (restenvs + string_len, "POSIX_V6_LP64_OFF64",
00091                     sizeof "POSIX_V6_LP64_OFF64" - 1);
00092             string_len += sizeof "POSIX_V6_LP64_OFF64" - 1;
00093           }
00094 #endif
00095 #ifndef _POSIX_V6_LPBIG_OFFBIG
00096         if (__sysconf (_SC_V6_LPBIG_OFFBIG) > 0)
00097 #endif
00098 #if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
00099           {
00100             if (string_len)
00101               restenvs[string_len++] = '\n';
00102             memcpy (restenvs + string_len, "POSIX_V6_LPBIG_OFFBIG",
00103                     sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
00104             string_len += sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
00105           }
00106 #endif
00107         restenvs[string_len++] = '\0';
00108        string = restenvs;
00109       }
00110       break;
00111 
00112     case _CS_XBS5_ILP32_OFF32_CFLAGS:
00113     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
00114 #ifdef __ILP32_OFF32_CFLAGS
00115 # if _POSIX_V6_ILP32_OFF32 == -1
00116 #  error "__ILP32_OFF32_CFLAGS should not be defined"
00117 # elif !defined _POSIX_V6_ILP32_OFF32
00118       if (__sysconf (_SC_V6_ILP32_OFF32) < 0)
00119         break;
00120 # endif
00121       string = __ILP32_OFF32_CFLAGS;
00122       string_len = sizeof (__ILP32_OFF32_CFLAGS);
00123 #endif
00124       break;
00125 
00126     case _CS_XBS5_ILP32_OFFBIG_CFLAGS:
00127     case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
00128 #ifdef __ILP32_OFFBIG_CFLAGS
00129 # if _POSIX_V6_ILP32_OFFBIG == -1
00130 #  error "__ILP32_OFFBIG_CFLAGS should not be defined"
00131 # elif !defined _POSIX_V6_ILP32_OFFBIG
00132       if (__sysconf (_SC_V6_ILP32_OFFBIG) < 0)
00133         break;
00134 # endif
00135       string = __ILP32_OFFBIG_CFLAGS;
00136       string_len = sizeof (__ILP32_OFFBIG_CFLAGS);
00137 #endif
00138       break;
00139 
00140     case _CS_XBS5_LP64_OFF64_CFLAGS:
00141     case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
00142 #ifdef __LP64_OFF64_CFLAGS
00143 # if _POSIX_V6_LP64_OFF64 == -1
00144 #  error "__LP64_OFF64_CFLAGS should not be defined"
00145 # elif !defined _POSIX_V6_LP64_OFF64
00146       if (__sysconf (_SC_V6_LP64_OFF64) < 0)
00147         break;
00148 # endif
00149       string = __LP64_OFF64_CFLAGS;
00150       string_len = sizeof (__LP64_OFF64_CFLAGS);
00151 #endif
00152       break;
00153 
00154     case _CS_XBS5_ILP32_OFF32_LDFLAGS:
00155     case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
00156 #ifdef __ILP32_OFF32_LDFLAGS
00157 # if _POSIX_V6_ILP32_OFF32 == -1
00158 #  error "__ILP32_OFF32_LDFLAGS should not be defined"
00159 # elif !defined _POSIX_V6_ILP32_OFF32
00160       if (__sysconf (_SC_V6_ILP32_OFF32) < 0)
00161         break;
00162 # endif
00163       string = __ILP32_OFF32_LDFLAGS;
00164       string_len = sizeof (__ILP32_OFF32_LDFLAGS);
00165 #endif
00166       break;
00167 
00168     case _CS_XBS5_ILP32_OFFBIG_LDFLAGS:
00169     case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
00170 #ifdef __ILP32_OFFBIG_LDFLAGS
00171 # if _POSIX_V6_ILP32_OFFBIG == -1
00172 #  error "__ILP32_OFFBIG_LDFLAGS should not be defined"
00173 # elif !defined _POSIX_V6_ILP32_OFFBIG
00174       if (__sysconf (_SC_V6_ILP32_OFFBIG) < 0)
00175         break;
00176 # endif
00177       string = __ILP32_OFFBIG_LDFLAGS;
00178       string_len = sizeof (__ILP32_OFFBIG_LDFLAGS);
00179 #endif
00180       break;
00181 
00182     case _CS_XBS5_LP64_OFF64_LDFLAGS:
00183     case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
00184 #ifdef __LP64_OFF64_LDFLAGS
00185 # if _POSIX_V6_LP64_OFF64 == -1
00186 #  error "__LP64_OFF64_LDFLAGS should not be defined"
00187 # elif !defined _POSIX_V6_LP64_OFF64
00188       if (__sysconf (_SC_V6_LP64_OFF64) < 0)
00189         break;
00190 # endif
00191       string = __LP64_OFF64_LDFLAGS;
00192       string_len = sizeof (__LP64_OFF64_LDFLAGS);
00193 #endif
00194       break;
00195 
00196     case _CS_LFS_CFLAGS:
00197     case _CS_LFS_LINTFLAGS:
00198 #if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
00199 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
00200       /* Signal that we want the new ABI.  */
00201       string = __LFS_CFLAGS;
00202       string_len = sizeof (__LFS_CFLAGS);
00203 #endif
00204       break;
00205 
00206     case _CS_LFS_LDFLAGS:
00207     case _CS_LFS_LIBS:
00208       /* No special libraries or linker flags needed.  */
00209       break;
00210 
00211     case _CS_LFS64_CFLAGS:
00212     case _CS_LFS64_LINTFLAGS:
00213 #define __LFS64_CFLAGS "-D_LARGEFILE64_SOURCE"
00214       string = __LFS64_CFLAGS;
00215       string_len = sizeof (__LFS64_CFLAGS);
00216       break;
00217 
00218     case _CS_LFS64_LDFLAGS:
00219     case _CS_LFS64_LIBS:
00220       /* No special libraries or linker flags needed.  */
00221       break;
00222 
00223     case _CS_XBS5_ILP32_OFF32_LIBS:
00224     case _CS_XBS5_ILP32_OFF32_LINTFLAGS:
00225     case _CS_XBS5_ILP32_OFFBIG_LIBS:
00226     case _CS_XBS5_ILP32_OFFBIG_LINTFLAGS:
00227     case _CS_XBS5_LP64_OFF64_LIBS:
00228     case _CS_XBS5_LP64_OFF64_LINTFLAGS:
00229     case _CS_XBS5_LPBIG_OFFBIG_CFLAGS:
00230     case _CS_XBS5_LPBIG_OFFBIG_LDFLAGS:
00231     case _CS_XBS5_LPBIG_OFFBIG_LIBS:
00232     case _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS:
00233 
00234     case _CS_POSIX_V6_ILP32_OFF32_LIBS:
00235     case _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS:
00236     case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
00237     case _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS:
00238     case _CS_POSIX_V6_LP64_OFF64_LIBS:
00239     case _CS_POSIX_V6_LP64_OFF64_LINTFLAGS:
00240     case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
00241     case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
00242     case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
00243     case _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS:
00244       /* GNU libc does not require special actions to use LFS functions.  */
00245       break;
00246 
00247     case _CS_GNU_LIBC_VERSION:
00248       string = "glibc " VERSION;
00249       string_len = sizeof ("glibc " VERSION);
00250       break;
00251 
00252     case _CS_GNU_LIBPTHREAD_VERSION:
00253 #ifdef LIBPTHREAD_VERSION
00254       string = LIBPTHREAD_VERSION;
00255       string_len = sizeof LIBPTHREAD_VERSION;
00256       break;
00257 #else
00258       /* No thread library.  */
00259       __set_errno (EINVAL);
00260       return 0;
00261 #endif
00262 
00263     default:
00264       __set_errno (EINVAL);
00265       return 0;
00266     }
00267 
00268   if (len > 0 && buf != NULL)
00269     {
00270       if (string_len <= len)
00271        memcpy (buf, string, string_len);
00272       else
00273        {
00274          memcpy (buf, string, len - 1);
00275          buf[len - 1] = '\0';
00276        }
00277     }
00278   return string_len;
00279 }
00280 libc_hidden_def (confstr)