Whamcloud - gitweb
Branch b1_4
[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 = 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(opendir, __opendir)
69
70 int
71 SYSIO_INTERFACE_NAME(closedir)(DIR *dir)
72 {
73         int rc;
74         SYSIO_INTERFACE_DISPLAY_BLOCK;
75
76         SYSIO_INTERFACE_ENTER;
77
78         rc = SYSIO_INTERFACE_NAME(close)(dir->fd);
79         free(dir);
80
81         SYSIO_INTERFACE_RETURN(rc, 0);
82 }
83
84 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(closedir), 
85                      PREPEND(__, SYSIO_INTERFACE_NAME(closedir)))
86
87 int 
88 SYSIO_INTERFACE_NAME(dirfd)(DIR *dir)
89 {
90         return(dir->fd);
91 }
92
93 long int
94 SYSIO_INTERFACE_NAME(telldir)(DIR *dir)
95 {
96         return(dir->filepos);
97 }
98
99 void 
100 SYSIO_INTERFACE_NAME(seekdir)(DIR *dir, long int offset)
101 {
102         dir->filepos = offset;
103         dir->base = offset;
104         dir->effective = 0;
105         dir->cur = 0;
106 }
107
108 void 
109 SYSIO_INTERFACE_NAME(rewinddir)(DIR *dir)
110 {
111         dir->base = 0;
112         dir->filepos = 0;
113         dir->cur = 0;
114         dir->effective = 0;
115 }
116
117 #endif
118 #endif