sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
//
|
sl@0
|
16 |
|
sl@0
|
17 |
#include <unistd.h>
|
sl@0
|
18 |
#include <errno.h>
|
sl@0
|
19 |
#include "sysreent.h"
|
sl@0
|
20 |
#include <dirent.h>
|
sl@0
|
21 |
#include <utf.h>
|
sl@0
|
22 |
#include <stddef.h>
|
sl@0
|
23 |
#include <string.h>
|
sl@0
|
24 |
#include <stdlib.h>
|
sl@0
|
25 |
#include <wchar.h>
|
sl@0
|
26 |
#include <sys/errno.h>
|
sl@0
|
27 |
#include "sysif.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
#define MAXPATHLEN 260 /* E32STD.H: KMaxFullName + 4 to avoid data loss */
|
sl@0
|
30 |
|
sl@0
|
31 |
extern "C" {
|
sl@0
|
32 |
/*
|
sl@0
|
33 |
Opens a directory.
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
EXPORT_C DIR* opendir(const char* _path)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
wchar_t _wpath[MAXPATHLEN+1];
|
sl@0
|
38 |
|
sl@0
|
39 |
if (mbstowcs(_wpath, _path, MAXPATHLEN) == (size_t)-1)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
errno = EILSEQ;
|
sl@0
|
42 |
return 0;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
return _opendir_r(&errno, _wpath);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
/*
|
sl@0
|
48 |
A wide-character version of opendir()
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
EXPORT_C WDIR* wopendir(const wchar_t* _wpath)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
if (!_wpath)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
errno = ENOENT;
|
sl@0
|
55 |
return NULL;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
return (WDIR*)_opendir_r(&errno, _wpath);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
EXPORT_C struct dirent* readdir(DIR* dp)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
return _readdir_r(&errno, dp);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
EXPORT_C struct wdirent* wreaddir(WDIR* wdp)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
if (!wdp)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
errno = EBADF;
|
sl@0
|
70 |
return NULL;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
return _wreaddir_r(wdp);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
/*
|
sl@0
|
76 |
Sets the position (associated with the directory stream that dirp points to)
|
sl@0
|
77 |
to the beginning of the directory.
|
sl@0
|
78 |
Additionally, it causes the directory stream to refer to the current state of
|
sl@0
|
79 |
the corresponding directory.
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
EXPORT_C void wrewinddir(WDIR* wdp)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
_wrewinddir_r(wdp);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
EXPORT_C void rewinddir(DIR* dp)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
WDIR* wdp = (__EPOC32_DIR*)dp;
|
sl@0
|
89 |
wrewinddir(wdp);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
/*
|
sl@0
|
93 |
closes the directory stream that dirp refers to.
|
sl@0
|
94 |
The memory associated with the directory stream is released.
|
sl@0
|
95 |
When this function returns, the value of dirp no longer point to
|
sl@0
|
96 |
an accessible object of type DIR
|
sl@0
|
97 |
*/
|
sl@0
|
98 |
|
sl@0
|
99 |
EXPORT_C int wclosedir(WDIR* wdp)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
return _wclosedir_r(&errno,wdp);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
EXPORT_C int closedir(DIR* dp)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
if (!dp)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
errno = EBADF;
|
sl@0
|
109 |
return -1;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
WDIR* wdp = (__EPOC32_DIR*)dp;
|
sl@0
|
113 |
return wclosedir(wdp);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
/*
|
sl@0
|
117 |
sets the position of the next readdir() operation on the directory
|
sl@0
|
118 |
stream specified by dp to the position specified by index.
|
sl@0
|
119 |
*/
|
sl@0
|
120 |
|
sl@0
|
121 |
EXPORT_C void wseekdir(WDIR* wdp, off_t index)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
if(!wdp)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
errno = EFAULT ;
|
sl@0
|
126 |
return ;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
wdp->iIndex = index;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
EXPORT_C void seekdir(DIR* dp, long index)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
WDIR* wdp = (__EPOC32_DIR*)dp;
|
sl@0
|
134 |
wseekdir(wdp, index);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
EXPORT_C off_t wtelldir(const WDIR* wdp)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
if(!wdp)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
errno = EFAULT ;
|
sl@0
|
143 |
return -1 ;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
if(wdp->iCount < 0 )
|
sl@0
|
146 |
{
|
sl@0
|
147 |
return -1;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
return wdp->iIndex;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
/*
|
sl@0
|
153 |
Returns the current location associated with the directory stream dir.
|
sl@0
|
154 |
*/
|
sl@0
|
155 |
EXPORT_C long telldir(DIR* dp)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
WDIR* wdp = (__EPOC32_DIR*)dp;
|
sl@0
|
158 |
return (long)wtelldir(wdp);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
}// extern "C"
|