OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [unistd/] [pathconf.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* pathconf -- adjusted for busybox
2
   Copyright (C) 1991,95,96,98,99,2000,2001 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
 
21
/* It would be great it this could be implemented using fpathconf,
22
 * but that doesn't work out very well (think FIFOs and sockets) */
23
 
24
#include <errno.h>
25
#include <unistd.h>
26
#include <limits.h>
27
#include <sys/statfs.h>
28
#include <errno.h>
29
#include <stddef.h>
30
#include <unistd.h>
31
#include <limits.h>
32
#include <fcntl.h>
33
#include <sys/stat.h>
34
#include <sys/statfs.h>
35
//#include <sys/statvfs.h>
36
 
37
//#include "linux_fsinfo.h"
38
 
39
 
40
/* The Linux kernel headers mention this as a kind of generic value.  */
41
#define LINUX_LINK_MAX  127
42
 
43
 
44
/* Get file-specific information about descriptor FD.  */
45
long int pathconf(const char *path, int name)
46
{
47
    if (path[0] == '\0')
48
    {
49
        __set_errno (ENOENT);
50
        return -1;
51
    }
52
 
53
    if (name == _PC_LINK_MAX)
54
    {
55
        /* Cut some corners */
56
#if 0
57
        struct statfs fsbuf;
58
 
59
        /* Determine the filesystem type.  */
60
        if (statfs (path, &fsbuf) < 0)
61
        {
62
            if (errno == ENOSYS)
63
                /* not possible, return the default value.  */
64
                return LINUX_LINK_MAX;
65
 
66
            /* Some error occured.  */
67
            return -1;
68
        }
69
 
70
        switch (fsbuf.f_type)
71
        {
72
            case EXT2_SUPER_MAGIC:
73
                return EXT2_LINK_MAX;
74
 
75
            case MINIX_SUPER_MAGIC:
76
            case MINIX_SUPER_MAGIC2:
77
                return MINIX_LINK_MAX;
78
 
79
            case MINIX2_SUPER_MAGIC:
80
            case MINIX2_SUPER_MAGIC2:
81
                return MINIX2_LINK_MAX;
82
 
83
            case XENIX_SUPER_MAGIC:
84
                return XENIX_LINK_MAX;
85
 
86
            case SYSV4_SUPER_MAGIC:
87
            case SYSV2_SUPER_MAGIC:
88
                return SYSV_LINK_MAX;
89
 
90
            case COH_SUPER_MAGIC:
91
                return COH_LINK_MAX;
92
 
93
            case UFS_MAGIC:
94
            case UFS_CIGAM:
95
                return UFS_LINK_MAX;
96
 
97
            case REISERFS_SUPER_MAGIC:
98
                return REISERFS_LINK_MAX;
99
 
100
            default:
101
                return LINUX_LINK_MAX;
102
        }
103
#else
104
        return LINUX_LINK_MAX;
105
#endif
106
    }
107
 
108
    switch (name)
109
    {
110
        default:
111
            __set_errno (EINVAL);
112
            return -1;
113
 
114
        case _PC_MAX_CANON:
115
#ifdef  MAX_CANON
116
            return MAX_CANON;
117
#else
118
            return -1;
119
#endif
120
 
121
        case _PC_MAX_INPUT:
122
#ifdef  MAX_INPUT
123
            return MAX_INPUT;
124
#else
125
            return -1;
126
#endif
127
 
128
        case _PC_NAME_MAX:
129
#ifdef  NAME_MAX
130
            {
131
                struct statfs buf;
132
                int save_errno = errno;
133
 
134
                if (statfs (path, &buf) < 0)
135
                {
136
                    if (errno == ENOSYS)
137
                    {
138
                        errno = save_errno;
139
                        return NAME_MAX;
140
                    }
141
                    return -1;
142
                }
143
                else
144
                {
145
#ifdef _STATFS_F_NAMELEN
146
                    return buf.f_namelen;
147
#else
148
# ifdef _STATFS_F_NAME_MAX
149
                    return buf.f_name_max;
150
# else
151
                    return NAME_MAX;
152
# endif
153
#endif
154
                }
155
            }
156
#else
157
            return -1;
158
#endif
159
 
160
        case _PC_PATH_MAX:
161
#ifdef  PATH_MAX
162
            return PATH_MAX;
163
#else
164
            return -1;
165
#endif
166
 
167
        case _PC_PIPE_BUF:
168
#ifdef  PIPE_BUF
169
            return PIPE_BUF;
170
#else
171
            return -1;
172
#endif
173
 
174
        case _PC_CHOWN_RESTRICTED:
175
#ifdef  _POSIX_CHOWN_RESTRICTED
176
            return _POSIX_CHOWN_RESTRICTED;
177
#else
178
            return -1;
179
#endif
180
 
181
        case _PC_NO_TRUNC:
182
#ifdef  _POSIX_NO_TRUNC
183
            return _POSIX_NO_TRUNC;
184
#else
185
            return -1;
186
#endif
187
 
188
        case _PC_VDISABLE:
189
#ifdef  _POSIX_VDISABLE
190
            return _POSIX_VDISABLE;
191
#else
192
            return -1;
193
#endif
194
 
195
        case _PC_SYNC_IO:
196
#ifdef  _POSIX_SYNC_IO
197
            return _POSIX_SYNC_IO;
198
#else
199
            return -1;
200
#endif
201
 
202
        case _PC_ASYNC_IO:
203
#if defined _POSIX_ASYNC_IO && defined __UCLIBC_HAS_LFS__ 
204
            {
205
                /* AIO is only allowed on regular files and block devices.  */
206
                struct stat st;
207
 
208
                if (stat (path, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
209
                    return -1;
210
                else
211
                    return 1;
212
            }
213
#else
214
            return -1;
215
#endif
216
 
217
        case _PC_PRIO_IO:
218
#ifdef  _POSIX_PRIO_IO
219
            return _POSIX_PRIO_IO;
220
#else
221
            return -1;
222
#endif
223
 
224
        case _PC_SOCK_MAXBUF:
225
#ifdef  SOCK_MAXBUF
226
            return SOCK_MAXBUF;
227
#else
228
            return -1;
229
#endif
230
 
231
        case _PC_FILESIZEBITS:
232
#ifdef FILESIZEBITS
233
            return FILESIZEBITS;
234
#else
235
            /* We let platforms with larger file sizes overwrite this value.  */
236
            return 32;
237
#endif
238
 
239
            /* Be lazy -- skip these */
240
        case _PC_REC_INCR_XFER_SIZE:
241
        case _PC_REC_MAX_XFER_SIZE:
242
        case _PC_REC_MIN_XFER_SIZE:
243
        case _PC_REC_XFER_ALIGN:
244
        case _PC_ALLOC_SIZE_MIN:
245
        case _PC_SYMLINK_MAX:
246
            return -1;
247
    }
248
 
249
}
250
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.