Back to index

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