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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [linux/] [uClibc/] [libc/] [unistd/] [fpathconf.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* fpathconf -- 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
#include <errno.h>
21
#include <unistd.h>
22
#include <limits.h>
23
#include <sys/statfs.h>
24
#include <errno.h>
25
#include <stddef.h>
26
#include <unistd.h>
27
#include <limits.h>
28
#include <fcntl.h>
29
#include <sys/stat.h>
30
#include <sys/statfs.h>
31
//#include <sys/statvfs.h>
32
 
33
//#include "linux_fsinfo.h"
34
 
35
 
36
/* The Linux kernel headers mention this as a kind of generic value.  */
37
#define LINUX_LINK_MAX  127
38
 
39
 
40
/* Get file-specific information about descriptor FD.  */
41
long int fpathconf(int fd, int name)
42
{
43
    if (fd < 0)
44
    {
45
        __set_errno (EBADF);
46
        return -1;
47
    }
48
 
49
    if (name == _PC_LINK_MAX)
50
    {
51
        /* Cut some corners */
52
#if 0
53
        struct statfs fsbuf;
54
 
55
        /* Determine the filesystem type.  */
56
        if (fstatfs (fd, &fsbuf) < 0)
57
        {
58
            if (errno == ENOSYS)
59
                /* not possible, return the default value.  */
60
                return LINUX_LINK_MAX;
61
 
62
            /* Some error occured.  */
63
            return -1;
64
        }
65
 
66
        switch (fsbuf.f_type)
67
        {
68
            case EXT2_SUPER_MAGIC:
69
                return EXT2_LINK_MAX;
70
 
71
            case MINIX_SUPER_MAGIC:
72
            case MINIX_SUPER_MAGIC2:
73
                return MINIX_LINK_MAX;
74
 
75
            case MINIX2_SUPER_MAGIC:
76
            case MINIX2_SUPER_MAGIC2:
77
                return MINIX2_LINK_MAX;
78
 
79
            case XENIX_SUPER_MAGIC:
80
                return XENIX_LINK_MAX;
81
 
82
            case SYSV4_SUPER_MAGIC:
83
            case SYSV2_SUPER_MAGIC:
84
                return SYSV_LINK_MAX;
85
 
86
            case COH_SUPER_MAGIC:
87
                return COH_LINK_MAX;
88
 
89
            case UFS_MAGIC:
90
            case UFS_CIGAM:
91
                return UFS_LINK_MAX;
92
 
93
            case REISERFS_SUPER_MAGIC:
94
                return REISERFS_LINK_MAX;
95
 
96
            default:
97
                return LINUX_LINK_MAX;
98
        }
99
#else
100
        return LINUX_LINK_MAX;
101
#endif
102
    }
103
 
104
    switch (name)
105
    {
106
        default:
107
            __set_errno (EINVAL);
108
            return -1;
109
 
110
        case _PC_MAX_CANON:
111
#ifdef  MAX_CANON
112
            return MAX_CANON;
113
#else
114
            return -1;
115
#endif
116
 
117
        case _PC_MAX_INPUT:
118
#ifdef  MAX_INPUT
119
            return MAX_INPUT;
120
#else
121
            return -1;
122
#endif
123
 
124
        case _PC_NAME_MAX:
125
#ifdef  NAME_MAX
126
            {
127
                struct statfs buf;
128
                int save_errno = errno;
129
 
130
                if (fstatfs (fd, &buf) < 0)
131
                {
132
                    if (errno == ENOSYS)
133
                    {
134
                        errno = save_errno;
135
                        return NAME_MAX;
136
                    }
137
                    return -1;
138
                }
139
                else
140
                {
141
#ifdef _STATFS_F_NAMELEN
142
                    return buf.f_namelen;
143
#else
144
# ifdef _STATFS_F_NAME_MAX
145
                    return buf.f_name_max;
146
# else
147
                    return NAME_MAX;
148
# endif
149
#endif
150
                }
151
            }
152
#else
153
            return -1;
154
#endif
155
 
156
        case _PC_PATH_MAX:
157
#ifdef  PATH_MAX
158
            return PATH_MAX;
159
#else
160
            return -1;
161
#endif
162
 
163
        case _PC_PIPE_BUF:
164
#ifdef  PIPE_BUF
165
            return PIPE_BUF;
166
#else
167
            return -1;
168
#endif
169
 
170
        case _PC_CHOWN_RESTRICTED:
171
#ifdef  _POSIX_CHOWN_RESTRICTED
172
            return _POSIX_CHOWN_RESTRICTED;
173
#else
174
            return -1;
175
#endif
176
 
177
        case _PC_NO_TRUNC:
178
#ifdef  _POSIX_NO_TRUNC
179
            return _POSIX_NO_TRUNC;
180
#else
181
            return -1;
182
#endif
183
 
184
        case _PC_VDISABLE:
185
#ifdef  _POSIX_VDISABLE
186
            return _POSIX_VDISABLE;
187
#else
188
            return -1;
189
#endif
190
 
191
        case _PC_SYNC_IO:
192
#ifdef  _POSIX_SYNC_IO
193
            return _POSIX_SYNC_IO;
194
#else
195
            return -1;
196
#endif
197
 
198
        case _PC_ASYNC_IO:
199
#if defined _POSIX_ASYNC_IO && defined __UCLIBC_HAS_LFS__ 
200
            {
201
                /* AIO is only allowed on regular files and block devices.  */
202
                struct stat st;
203
 
204
                if (fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
205
                    return -1;
206
                else
207
                    return 1;
208
            }
209
#else
210
            return -1;
211
#endif
212
 
213
        case _PC_PRIO_IO:
214
#ifdef  _POSIX_PRIO_IO
215
            return _POSIX_PRIO_IO;
216
#else
217
            return -1;
218
#endif
219
 
220
        case _PC_SOCK_MAXBUF:
221
#ifdef  SOCK_MAXBUF
222
            return SOCK_MAXBUF;
223
#else
224
            return -1;
225
#endif
226
 
227
        case _PC_FILESIZEBITS:
228
#ifdef FILESIZEBITS
229
            return FILESIZEBITS;
230
#else
231
            /* We let platforms with larger file sizes overwrite this value.  */
232
            return 32;
233
#endif
234
 
235
            /* Be lazy -- skip these */
236
        case _PC_REC_INCR_XFER_SIZE:
237
        case _PC_REC_MAX_XFER_SIZE:
238
        case _PC_REC_MIN_XFER_SIZE:
239
        case _PC_REC_XFER_ALIGN:
240
        case _PC_ALLOC_SIZE_MIN:
241
        case _PC_SYMLINK_MAX:
242
            return -1;
243
    }
244
 
245
}
246
 

powered by: WebSVN 2.1.0

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