Back to index

glibc  2.9
pathconf.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1995,1996,1998,2000,2001,2003
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 <errno.h>
00021 #include <stddef.h>
00022 #include <unistd.h>
00023 #include <limits.h>
00024 #include <fcntl.h>
00025 #include <sys/stat.h>
00026 #include <sys/statfs.h>
00027 #include <sys/statvfs.h>
00028 
00029 
00030 /* Get file-specific information about PATH.  */
00031 long int
00032 __pathconf (const char *path, int name)
00033 {
00034   if (path[0] == '\0')
00035     {
00036       __set_errno (ENOENT);
00037       return -1;
00038     }
00039 
00040   switch (name)
00041     {
00042     default:
00043       __set_errno (EINVAL);
00044       return -1;
00045 
00046     case _PC_LINK_MAX:
00047 #ifdef LINK_MAX
00048       return LINK_MAX;
00049 #else
00050       return -1;
00051 #endif
00052 
00053     case _PC_MAX_CANON:
00054 #ifdef MAX_CANON
00055       return MAX_CANON;
00056 #else
00057       return -1;
00058 #endif
00059 
00060     case _PC_MAX_INPUT:
00061 #ifdef MAX_INPUT
00062       return MAX_INPUT;
00063 #else
00064       return -1;
00065 #endif
00066 
00067     case _PC_NAME_MAX:
00068 #ifdef NAME_MAX
00069       {
00070        struct statfs buf;
00071        int save_errno = errno;
00072 
00073        if (__statfs (path, &buf) < 0)
00074          {
00075            if (errno == ENOSYS)
00076              {
00077               errno = save_errno;
00078               return NAME_MAX;
00079              }
00080            return -1;
00081          }
00082        else
00083          {
00084 #ifdef _STATFS_F_NAMELEN
00085            return buf.f_namelen;
00086 #else
00087 # ifdef _STATFS_F_NAME_MAX
00088            return buf.f_name_max;
00089 # else
00090            return NAME_MAX;
00091 # endif
00092 #endif
00093          }
00094       }
00095 #else
00096       return -1;
00097 #endif
00098 
00099     case _PC_PATH_MAX:
00100 #ifdef PATH_MAX
00101       return PATH_MAX;
00102 #else
00103       return -1;
00104 #endif
00105 
00106     case _PC_PIPE_BUF:
00107 #ifdef PIPE_BUF
00108       return PIPE_BUF;
00109 #else
00110       return -1;
00111 #endif
00112 
00113     case _PC_CHOWN_RESTRICTED:
00114 #ifdef _POSIX_CHOWN_RESTRICTED
00115       return _POSIX_CHOWN_RESTRICTED;
00116 #else
00117       return -1;
00118 #endif
00119 
00120     case _PC_NO_TRUNC:
00121 #ifdef _POSIX_NO_TRUNC
00122       return _POSIX_NO_TRUNC;
00123 #else
00124       return -1;
00125 #endif
00126 
00127     case _PC_VDISABLE:
00128 #ifdef _POSIX_VDISABLE
00129       return _POSIX_VDISABLE;
00130 #else
00131       return -1;
00132 #endif
00133 
00134     case _PC_SYNC_IO:
00135 #ifdef _POSIX_SYNC_IO
00136       return _POSIX_SYNC_IO;
00137 #else
00138       return -1;
00139 #endif
00140 
00141     case _PC_ASYNC_IO:
00142 #ifdef _POSIX_ASYNC_IO
00143       {
00144        /* AIO is only allowed on regular files and block devices.  */
00145        struct stat64 st;
00146 
00147        if (__xstat64 (_STAT_VER, path, &st) < 0
00148            || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
00149          return -1;
00150        else
00151          return 1;
00152       }
00153 #else
00154       return -1;
00155 #endif
00156 
00157     case _PC_PRIO_IO:
00158 #ifdef _POSIX_PRIO_IO
00159       return _POSIX_PRIO_IO;
00160 #else
00161       return -1;
00162 #endif
00163 
00164     case _PC_SOCK_MAXBUF:
00165 #ifdef SOCK_MAXBUF
00166       return SOCK_MAXBUF;
00167 #else
00168       return -1;
00169 #endif
00170 
00171     case _PC_FILESIZEBITS:
00172 #ifdef FILESIZEBITS
00173       return FILESIZEBITS;
00174 #else
00175       /* We let platforms with larger file sizes overwrite this value.  */
00176       return 32;
00177 #endif
00178 
00179     case _PC_REC_INCR_XFER_SIZE:
00180       /* XXX It is not entirely clear what the limit is supposed to do.
00181         What is incremented?  */
00182       return -1;
00183 
00184     case _PC_REC_MAX_XFER_SIZE:
00185       /* XXX It is not entirely clear what the limit is supposed to do.
00186         In general there is no top limit of the number of bytes which
00187         case be transported at once.  */
00188       return -1;
00189 
00190     case _PC_REC_MIN_XFER_SIZE:
00191       {
00192        /* XXX It is not entirely clear what the limit is supposed to do.
00193           I assume this is the block size of the filesystem.  */
00194        struct statvfs64 sv;
00195 
00196        if (__statvfs64 (path, &sv) < 0)
00197          return -1;
00198        return sv.f_bsize;
00199       }
00200 
00201     case _PC_REC_XFER_ALIGN:
00202       {
00203        /* XXX It is not entirely clear what the limit is supposed to do.
00204           I assume that the number should reflect the minimal block
00205           alignment.  */
00206        struct statvfs64 sv;
00207 
00208        if (__statvfs64 (path, &sv) < 0)
00209          return -1;
00210        return sv.f_frsize;
00211       }
00212 
00213     case _PC_ALLOC_SIZE_MIN:
00214       {
00215        /* XXX It is not entirely clear what the limit is supposed to do.
00216           I assume that the number should reflect the minimal block
00217           alignment.  */
00218        struct statvfs64 sv;
00219 
00220        if (__statvfs64 (path, &sv) < 0)
00221          return -1;
00222        return sv.f_frsize;
00223       }
00224 
00225     case _PC_SYMLINK_MAX:
00226       /* In general there are no limits.  If a system has one it should
00227         overwrite this case.  */
00228       return -1;
00229 
00230     case _PC_2_SYMLINKS:
00231       /* Unix systems generally have symlinks.  */
00232       return 1;
00233     }
00234 }
00235 
00236 #undef __pathconf
00237 weak_alias (__pathconf, pathconf)