Whamcloud - gitweb
LU-433 ldiskfs: remove jbd2-jcberr patch from kernel
[fs/lustre-release.git] / libsysio / src / stddir.c
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  * 
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  * 
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  */
17
18 #ifdef __linux__
19 #include <features.h>
20 #if defined(__GLIBC__) && !defined(REDSTORM) 
21
22 /*
23  * stddir.c
24  *
25  * As of glibc 2.3, the new capability to define functions with a 'hidden'
26  * attribute means that any time glibc decides to use that capability
27  * we will no longer be able to successfully intercept low level calls
28  * in a link against default system glibc. Thus the following imported 
29  * functions.
30  */
31
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <fcntl.h>
36 #include <dirent.h>
37
38 #include <sysio.h>
39
40 #include "sysio-symbols.h"
41 #include "stddir.h"
42
43 /***********************************************************
44  * dir series functions                                    *
45  ***********************************************************/
46
47 DIR* 
48 SYSIO_INTERFACE_NAME(opendir)(const char *name)
49 {
50         DIR *dir;
51
52         SYSIO_INTERFACE_DISPLAY_BLOCK;
53
54         SYSIO_INTERFACE_ENTER;
55
56         dir = (DIR * )calloc(1, sizeof(DIR));
57         if (!dir)
58                 SYSIO_INTERFACE_RETURN(NULL, -ENOMEM);
59
60         dir->fd = SYSIO_INTERFACE_NAME(open)(name, O_RDONLY);
61         if (dir->fd < 0) {
62                 free(dir);
63                 SYSIO_INTERFACE_RETURN(NULL, -errno);
64         }
65         return dir;
66 }
67
68 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(opendir),
69                      PREPEND(__, SYSIO_INTERFACE_NAME(opendir)))
70
71 int
72 SYSIO_INTERFACE_NAME(closedir)(DIR *dir)
73 {
74         int rc;
75         SYSIO_INTERFACE_DISPLAY_BLOCK;
76
77         SYSIO_INTERFACE_ENTER;
78
79         rc = SYSIO_INTERFACE_NAME(close)(dir->fd);
80         free(dir);
81
82         SYSIO_INTERFACE_RETURN(rc, 0);
83 }
84
85 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(closedir), 
86                      PREPEND(__, SYSIO_INTERFACE_NAME(closedir)))
87
88 int 
89 SYSIO_INTERFACE_NAME(dirfd)(DIR *dir)
90 {
91         return(dir->fd);
92 }
93
94 long int
95 SYSIO_INTERFACE_NAME(telldir)(DIR *dir)
96 {
97         return(dir->filepos);
98 }
99
100 void 
101 SYSIO_INTERFACE_NAME(seekdir)(DIR *dir, long int offset)
102 {
103         dir->filepos = offset;
104         dir->base = offset;
105         dir->effective = 0;
106         dir->cur = 0;
107 }
108
109 void 
110 SYSIO_INTERFACE_NAME(rewinddir)(DIR *dir)
111 {
112         dir->base = 0;
113         dir->filepos = 0;
114         dir->cur = 0;
115         dir->effective = 0;
116 }
117
118 #endif
119 #endif