xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 1991-2016 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, see |
| 16 | <http://www.gnu.org/licenses/>. */ |
| 17 | |
| 18 | #include <errno.h> |
| 19 | #include <stddef.h> |
| 20 | #include <unistd.h> |
| 21 | #include <limits.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/statfs.h> |
| 25 | #include <sys/statvfs.h> |
| 26 | |
| 27 | |
| 28 | /* Get file-specific information about PATH. */ |
| 29 | long int |
| 30 | __pathconf (const char *path, int name) |
| 31 | { |
| 32 | if (path[0] == '\0') |
| 33 | { |
| 34 | __set_errno (ENOENT); |
| 35 | return -1; |
| 36 | } |
| 37 | |
| 38 | switch (name) |
| 39 | { |
| 40 | default: |
| 41 | __set_errno (EINVAL); |
| 42 | return -1; |
| 43 | |
| 44 | case _PC_LINK_MAX: |
| 45 | #ifdef LINK_MAX |
| 46 | return LINK_MAX; |
| 47 | #else |
| 48 | return -1; |
| 49 | #endif |
| 50 | |
| 51 | case _PC_MAX_CANON: |
| 52 | #ifdef MAX_CANON |
| 53 | return MAX_CANON; |
| 54 | #else |
| 55 | return -1; |
| 56 | #endif |
| 57 | |
| 58 | case _PC_MAX_INPUT: |
| 59 | #ifdef MAX_INPUT |
| 60 | return MAX_INPUT; |
| 61 | #else |
| 62 | return -1; |
| 63 | #endif |
| 64 | |
| 65 | case _PC_NAME_MAX: |
| 66 | #ifdef NAME_MAX |
| 67 | { |
| 68 | struct statvfs64 sv; |
| 69 | int save_errno = errno; |
| 70 | |
| 71 | if (__statvfs64 (path, &sv) < 0) |
| 72 | { |
| 73 | if (errno == ENOSYS) |
| 74 | { |
| 75 | errno = save_errno; |
| 76 | return NAME_MAX; |
| 77 | } |
| 78 | return -1; |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | return sv.f_namemax; |
| 83 | } |
| 84 | } |
| 85 | #else |
| 86 | return -1; |
| 87 | #endif |
| 88 | |
| 89 | case _PC_PATH_MAX: |
| 90 | #ifdef PATH_MAX |
| 91 | return PATH_MAX; |
| 92 | #else |
| 93 | return -1; |
| 94 | #endif |
| 95 | |
| 96 | case _PC_PIPE_BUF: |
| 97 | #ifdef PIPE_BUF |
| 98 | return PIPE_BUF; |
| 99 | #else |
| 100 | return -1; |
| 101 | #endif |
| 102 | |
| 103 | case _PC_CHOWN_RESTRICTED: |
| 104 | #ifdef _POSIX_CHOWN_RESTRICTED |
| 105 | return _POSIX_CHOWN_RESTRICTED; |
| 106 | #else |
| 107 | return -1; |
| 108 | #endif |
| 109 | |
| 110 | case _PC_NO_TRUNC: |
| 111 | #ifdef _POSIX_NO_TRUNC |
| 112 | return _POSIX_NO_TRUNC; |
| 113 | #else |
| 114 | return -1; |
| 115 | #endif |
| 116 | |
| 117 | case _PC_VDISABLE: |
| 118 | #ifdef _POSIX_VDISABLE |
| 119 | return _POSIX_VDISABLE; |
| 120 | #else |
| 121 | return -1; |
| 122 | #endif |
| 123 | |
| 124 | case _PC_SYNC_IO: |
| 125 | #ifdef _POSIX_SYNC_IO |
| 126 | return _POSIX_SYNC_IO; |
| 127 | #else |
| 128 | return -1; |
| 129 | #endif |
| 130 | |
| 131 | case _PC_ASYNC_IO: |
| 132 | #ifdef _POSIX_ASYNC_IO |
| 133 | { |
| 134 | /* AIO is only allowed on regular files and block devices. */ |
| 135 | struct stat64 st; |
| 136 | |
| 137 | if (__xstat64 (_STAT_VER, path, &st) < 0 |
| 138 | || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode))) |
| 139 | return -1; |
| 140 | else |
| 141 | return 1; |
| 142 | } |
| 143 | #else |
| 144 | return -1; |
| 145 | #endif |
| 146 | |
| 147 | case _PC_PRIO_IO: |
| 148 | #ifdef _POSIX_PRIO_IO |
| 149 | return _POSIX_PRIO_IO; |
| 150 | #else |
| 151 | return -1; |
| 152 | #endif |
| 153 | |
| 154 | case _PC_SOCK_MAXBUF: |
| 155 | #ifdef SOCK_MAXBUF |
| 156 | return SOCK_MAXBUF; |
| 157 | #else |
| 158 | return -1; |
| 159 | #endif |
| 160 | |
| 161 | case _PC_FILESIZEBITS: |
| 162 | #ifdef FILESIZEBITS |
| 163 | return FILESIZEBITS; |
| 164 | #else |
| 165 | /* We let platforms with larger file sizes overwrite this value. */ |
| 166 | return 32; |
| 167 | #endif |
| 168 | |
| 169 | case _PC_REC_INCR_XFER_SIZE: |
| 170 | /* XXX It is not entirely clear what the limit is supposed to do. |
| 171 | What is incremented? */ |
| 172 | return -1; |
| 173 | |
| 174 | case _PC_REC_MAX_XFER_SIZE: |
| 175 | /* XXX It is not entirely clear what the limit is supposed to do. |
| 176 | In general there is no top limit of the number of bytes which |
| 177 | case be transported at once. */ |
| 178 | return -1; |
| 179 | |
| 180 | case _PC_REC_MIN_XFER_SIZE: |
| 181 | { |
| 182 | /* XXX It is not entirely clear what the limit is supposed to do. |
| 183 | I assume this is the block size of the filesystem. */ |
| 184 | struct statvfs64 sv; |
| 185 | |
| 186 | if (__statvfs64 (path, &sv) < 0) |
| 187 | return -1; |
| 188 | return sv.f_bsize; |
| 189 | } |
| 190 | |
| 191 | case _PC_REC_XFER_ALIGN: |
| 192 | { |
| 193 | /* XXX It is not entirely clear what the limit is supposed to do. |
| 194 | I assume that the number should reflect the minimal block |
| 195 | alignment. */ |
| 196 | struct statvfs64 sv; |
| 197 | |
| 198 | if (__statvfs64 (path, &sv) < 0) |
| 199 | return -1; |
| 200 | return sv.f_frsize; |
| 201 | } |
| 202 | |
| 203 | case _PC_ALLOC_SIZE_MIN: |
| 204 | { |
| 205 | /* XXX It is not entirely clear what the limit is supposed to do. |
| 206 | I assume that the number should reflect the minimal block |
| 207 | alignment. */ |
| 208 | struct statvfs64 sv; |
| 209 | |
| 210 | if (__statvfs64 (path, &sv) < 0) |
| 211 | return -1; |
| 212 | return sv.f_frsize; |
| 213 | } |
| 214 | |
| 215 | case _PC_SYMLINK_MAX: |
| 216 | /* In general there are no limits. If a system has one it should |
| 217 | overwrite this case. */ |
| 218 | return -1; |
| 219 | |
| 220 | case _PC_2_SYMLINKS: |
| 221 | /* Unix systems generally have symlinks. */ |
| 222 | return 1; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | #undef __pathconf |
| 227 | weak_alias (__pathconf, pathconf) |