31
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// connectors for re-entrant networking system calls
|
|
19 |
|
|
20 |
#include <sys/errno.h>
|
|
21 |
#include "sysreent.h"
|
|
22 |
#include "aeselectreent.h"
|
|
23 |
#include <unistd.h>
|
|
24 |
#include <fcntl.h> // for open()
|
|
25 |
#include <sys/ioctl.h>
|
|
26 |
#include <stdarg.h>
|
|
27 |
#include <utf.h>
|
|
28 |
#include <unistd.h>
|
|
29 |
#include <sys/types.h>
|
|
30 |
#include <spawn.h>
|
|
31 |
#include <charconv.h>
|
|
32 |
#include "sys/stat.h"
|
|
33 |
#include <wchar.h>
|
|
34 |
#include "systemspecialfilercg.h"
|
|
35 |
#include "link.h"
|
|
36 |
#include "errno.h"
|
|
37 |
|
|
38 |
#include "sysif.h"
|
|
39 |
#include "lposix.h"
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
#define MAXPATHLEN 256 /* E32STD.H: KMaxFullName */
|
|
44 |
|
|
45 |
TInt __EPOC32_WDIR::UpdateNarrow()
|
|
46 |
{
|
|
47 |
return -1; //this is not supported.
|
|
48 |
}
|
|
49 |
|
|
50 |
TInt __EPOC32_DIR::UpdateNarrow()
|
|
51 |
{
|
|
52 |
//update the narrow one
|
|
53 |
|
|
54 |
TInt ret = CnvUtfConverter::ConvertFromUnicodeToUtf8(iCurrentNarrowName, iCurrentName);
|
|
55 |
if (ret >= 0)
|
|
56 |
{
|
|
57 |
iCurrentNarrow.d_namlen=(short)iCurrentNarrowName.Length();
|
|
58 |
memcpy(iCurrentNarrow.d_name,iCurrentNarrowName.PtrZ(),iCurrentNarrowName.Length() + 1);
|
|
59 |
}
|
|
60 |
return ret;
|
|
61 |
}
|
|
62 |
|
|
63 |
__EPOC32_WDIR::~__EPOC32_WDIR()
|
|
64 |
{
|
|
65 |
delete iPath;
|
|
66 |
delete iEntries;
|
|
67 |
}
|
|
68 |
|
|
69 |
TInt __EPOC32_WDIR::Open(const wchar_t* _path,int* aErrno)
|
|
70 |
{
|
|
71 |
TParse name;
|
|
72 |
TInt err = Backend()->ResolvePath(name,_path,NULL);
|
|
73 |
if (!err)
|
|
74 |
err = Open(name.DriveAndPath());
|
|
75 |
if (err)
|
|
76 |
MapError(err,*aErrno);
|
|
77 |
return err;
|
|
78 |
}
|
|
79 |
|
|
80 |
TInt __EPOC32_WDIR::Open(const TDesC& aPath)
|
|
81 |
{
|
|
82 |
delete iPath;
|
|
83 |
iPath=aPath.Alloc(); //allocate space for a hbufc and initialise it to the TDesC contents
|
|
84 |
return Open();
|
|
85 |
}
|
|
86 |
|
|
87 |
TInt __EPOC32_WDIR::Open()
|
|
88 |
{
|
|
89 |
delete iEntries;
|
|
90 |
iEntries=0;
|
|
91 |
iIndex = 0;
|
|
92 |
iCount = 0 ;
|
|
93 |
if (iPath==0)
|
|
94 |
{
|
|
95 |
return ENOMEM;
|
|
96 |
}
|
|
97 |
|
|
98 |
RFs& session = Backend()->FileSession();
|
|
99 |
TInt err=session.GetDir(*iPath,KEntryAttMaskSupported,ESortByName+EDescending,iEntries);
|
|
100 |
|
|
101 |
if (!err)
|
|
102 |
{
|
|
103 |
// iCount is actually a Last Index, not the number of entries!
|
|
104 |
iCount = iEntries->Count()-1;
|
|
105 |
iIndex = 0;
|
|
106 |
}
|
|
107 |
return err;
|
|
108 |
}
|
|
109 |
|
|
110 |
extern "C" {
|
|
111 |
|
|
112 |
/* A reentrant version of open() */
|
|
113 |
EXPORT_C int _open_r (int *aErrno, const wchar_t *name, int mode, int perms)
|
|
114 |
{
|
|
115 |
return Backend()->open(name, mode, perms, *aErrno);
|
|
116 |
}
|
|
117 |
|
|
118 |
/*A reentrant version of wopen() */
|
|
119 |
EXPORT_C int _wopen_r (int *aErrno, const wchar_t *name, int mode, int perms)
|
|
120 |
{
|
|
121 |
return Backend()->open(name, mode, perms, *aErrno);
|
|
122 |
}
|
|
123 |
|
|
124 |
/* A reentrant version of read()*/
|
|
125 |
EXPORT_C int _read_r (int *aErrno, int fd, char *buf, size_t nbyte)
|
|
126 |
{
|
|
127 |
return Backend()->read(fd, buf, nbyte, *aErrno);
|
|
128 |
}
|
|
129 |
|
|
130 |
|
|
131 |
/* A reentrant version of write()*/
|
|
132 |
EXPORT_C int _write_r (int *aErrno, int fd, const char *buf, size_t nbyte)
|
|
133 |
{
|
|
134 |
return Backend()->write(fd, buf, nbyte, *aErrno);
|
|
135 |
}
|
|
136 |
|
|
137 |
|
|
138 |
/* A reentrant version of close()*/
|
|
139 |
EXPORT_C int _close_r (int *aErrno, int fd)
|
|
140 |
{
|
|
141 |
return Backend()->close(fd, *aErrno);
|
|
142 |
}
|
|
143 |
|
|
144 |
/* A reentrant version of fsync()*/
|
|
145 |
EXPORT_C int _fsync_r (int *aErrno, int fd)
|
|
146 |
{
|
|
147 |
return Backend()->fsync(fd, *aErrno);
|
|
148 |
}
|
|
149 |
|
|
150 |
/*A reentrant version of fseek()*/
|
|
151 |
EXPORT_C off_t _lseek_r (int *aErrno, int fd, off_t pos, int whence)
|
|
152 |
{
|
|
153 |
return Backend()->lseek(fd, pos, whence, *aErrno);
|
|
154 |
}
|
|
155 |
|
|
156 |
|
|
157 |
/* A reentrant version of fstat()*/
|
|
158 |
EXPORT_C int _fstat_r (int *aErrno, int fd, struct stat *st)
|
|
159 |
{
|
|
160 |
return Backend()->fstat(fd, st, *aErrno);
|
|
161 |
}
|
|
162 |
|
|
163 |
/* A reentrant version of stat().
|
|
164 |
*/
|
|
165 |
EXPORT_C int _stat_r (int *aErrno, const wchar_t *name, struct stat *st)
|
|
166 |
{
|
|
167 |
return Backend()->stat(name, st, *aErrno);
|
|
168 |
}
|
|
169 |
|
|
170 |
/* A reentrant version of lstat().
|
|
171 |
*/
|
|
172 |
EXPORT_C int _lstat_r (int *aErrno, const wchar_t *name, struct stat *st)
|
|
173 |
{
|
|
174 |
return Backend()->lstat(name, st, *aErrno);
|
|
175 |
}
|
|
176 |
|
|
177 |
EXPORT_C int _utime_r (int *aErrno, const wchar_t *name,const struct utimbuf *filetimes)
|
|
178 |
{
|
|
179 |
return Backend()->utime(name, filetimes, *aErrno);
|
|
180 |
}
|
|
181 |
|
|
182 |
|
|
183 |
/* A reentrant version of wstat().
|
|
184 |
*/
|
|
185 |
EXPORT_C int _wstat_r (int *aErrno, const wchar_t *name, struct stat *st)
|
|
186 |
{
|
|
187 |
return Backend()->stat(name, st, *aErrno);
|
|
188 |
}
|
|
189 |
|
|
190 |
/* A reentrant version of dup().
|
|
191 |
*/
|
|
192 |
EXPORT_C int _dup_r (int *aErrno, int aFid)
|
|
193 |
{
|
|
194 |
return Backend()->dup(aFid, *aErrno);
|
|
195 |
}
|
|
196 |
|
|
197 |
/* A reentrant version of dup2().
|
|
198 |
*/
|
|
199 |
EXPORT_C int _dup2_r (int *aErrno, int aFid1, int aFid2)
|
|
200 |
{
|
|
201 |
return Backend()->dup2(aFid1, aFid2, *aErrno);
|
|
202 |
}
|
|
203 |
|
|
204 |
/* A reentrant version of ioctl().
|
|
205 |
*/
|
|
206 |
EXPORT_C int _ioctl_r (int *aErrno, int aFid, int aCmd, void* aParam)
|
|
207 |
{
|
|
208 |
return Backend()->ioctl(aFid, aCmd, aParam, *aErrno);
|
|
209 |
}
|
|
210 |
|
|
211 |
/* A wide-character version of reentrant of getcwd().
|
|
212 |
*/
|
|
213 |
EXPORT_C wchar_t * _wgetcwd_r (int *aErrno, wchar_t *_buf, size_t _size)
|
|
214 |
{
|
|
215 |
if (_buf==0)
|
|
216 |
{
|
|
217 |
_buf=(wchar_t *)User::Alloc(_size*sizeof(wchar_t));
|
|
218 |
if (_buf==0)
|
|
219 |
{
|
|
220 |
*aErrno=ENOMEM;
|
|
221 |
return _buf;
|
|
222 |
}
|
|
223 |
}
|
|
224 |
return Backend()->getcwd(_buf, _size, *aErrno);
|
|
225 |
}
|
|
226 |
|
|
227 |
/* A reentrant version of chdir().
|
|
228 |
*/
|
|
229 |
EXPORT_C int _chdir_r (int *aErrno, const wchar_t *_path)
|
|
230 |
{
|
|
231 |
return Backend()->chdir(_path, *aErrno);
|
|
232 |
}
|
|
233 |
|
|
234 |
/* A reentrant version of wchdir().
|
|
235 |
*/
|
|
236 |
EXPORT_C int _wchdir_r (int *aErrno, const wchar_t *_path)
|
|
237 |
{
|
|
238 |
return Backend()->chdir(_path, *aErrno);
|
|
239 |
}
|
|
240 |
|
|
241 |
/* A reentrant version of rmdir().
|
|
242 |
*/
|
|
243 |
EXPORT_C int _rmdir_r (int *aErrno, const wchar_t *_path)
|
|
244 |
{
|
|
245 |
return Backend()->rmdir(_path, *aErrno);
|
|
246 |
}
|
|
247 |
|
|
248 |
|
|
249 |
/* A reentrant version of wrmdir().
|
|
250 |
*/
|
|
251 |
EXPORT_C int _wrmdir_r (int *aErrno, const wchar_t *_path)
|
|
252 |
{
|
|
253 |
return Backend()->rmdir(_path, *aErrno);
|
|
254 |
}
|
|
255 |
|
|
256 |
|
|
257 |
/* A reentrant version of mkdir().
|
|
258 |
*/
|
|
259 |
EXPORT_C int _mkdir_r (int *aErrno, const wchar_t *_path, mode_t _mode)
|
|
260 |
{
|
|
261 |
return Backend()->mkdir(_path, _mode, *aErrno);
|
|
262 |
}
|
|
263 |
|
|
264 |
/* A reentrant version of wmkdir().
|
|
265 |
*/
|
|
266 |
EXPORT_C int _wmkdir_r (int *aErrno, const wchar_t *_path, mode_t _mode)
|
|
267 |
{
|
|
268 |
return Backend()->mkdir(_path, _mode, *aErrno);
|
|
269 |
}
|
|
270 |
|
|
271 |
|
|
272 |
/* A reentrant version of chmod().
|
|
273 |
*/
|
|
274 |
EXPORT_C int _chmod_r (int *aErrno, const wchar_t *_path, mode_t _mode)
|
|
275 |
{
|
|
276 |
return Backend()->chmod(_path, _mode, *aErrno);
|
|
277 |
}
|
|
278 |
|
|
279 |
/* A reentrant version of chmod().
|
|
280 |
*/
|
|
281 |
EXPORT_C int _fchmod_r (int *aErrno, int _fd , mode_t _mode)
|
|
282 |
{
|
|
283 |
return Backend()->fchmod(_fd, _mode, *aErrno);
|
|
284 |
}
|
|
285 |
/* A reentrant version of wchmod().
|
|
286 |
*/
|
|
287 |
EXPORT_C int _wchmod_r (int *aErrno, const wchar_t *_path, mode_t _mode)
|
|
288 |
{
|
|
289 |
return Backend()->chmod(_path, _mode, *aErrno);
|
|
290 |
}
|
|
291 |
|
|
292 |
/* A wide-character version of reentrant of unlink().
|
|
293 |
*/
|
|
294 |
EXPORT_C int _wunlink_r (int *aErrno, const wchar_t *_path)
|
|
295 |
{
|
|
296 |
return Backend()->unlink(_path, *aErrno);
|
|
297 |
}
|
|
298 |
|
|
299 |
|
|
300 |
/* A reentrant version of rename().
|
|
301 |
*/
|
|
302 |
EXPORT_C int _rename_r (int *aErrno, const wchar_t *oldpath, const wchar_t *newpath)
|
|
303 |
{
|
|
304 |
return Backend()->rename(oldpath, newpath, *aErrno);
|
|
305 |
}
|
|
306 |
|
|
307 |
|
|
308 |
/* A wide-character version of reentrant of rename().
|
|
309 |
*/
|
|
310 |
EXPORT_C int _wrename_r (int *aErrno, const wchar_t *oldpath, const wchar_t *newpath)
|
|
311 |
{
|
|
312 |
return Backend()->rename(oldpath, newpath, *aErrno);
|
|
313 |
}
|
|
314 |
|
|
315 |
/* A wide-character version of reentrant of realpath().
|
|
316 |
*/
|
|
317 |
EXPORT_C wchar_t * _wrealpath_r (int *aErrno, const wchar_t *relpath, wchar_t *resolved)
|
|
318 |
{
|
|
319 |
if(relpath == NULL || resolved == NULL) //invalid arguments
|
|
320 |
{
|
|
321 |
*aErrno = EFAULT;
|
|
322 |
return (NULL);
|
|
323 |
}
|
|
324 |
TPtr16 name((TText16*)resolved,MAXPATHLEN);
|
|
325 |
TParse path;
|
|
326 |
TInt err = Backend()->ResolvePath(path, relpath, &name);
|
|
327 |
if (!err)
|
|
328 |
{
|
|
329 |
err = path.SetNoWild(path.DriveAndPath(),NULL,&name);
|
|
330 |
if (!err)
|
|
331 |
{
|
|
332 |
name = path.FullName();
|
|
333 |
name.ZeroTerminate();
|
|
334 |
return resolved;
|
|
335 |
}
|
|
336 |
}
|
|
337 |
MapError(err, *aErrno);
|
|
338 |
return 0;
|
|
339 |
}
|
|
340 |
|
|
341 |
LOCAL_C TInt _parseCmd (const wchar_t* command, wchar_t* exepath, TDes& buf)
|
|
342 |
{
|
|
343 |
TLex lexer((TText*)command);
|
|
344 |
buf = lexer.NextToken();
|
|
345 |
WcsCpy(exepath,(wchar_t*)buf.PtrZ());
|
|
346 |
|
|
347 |
lexer.SkipSpace();
|
|
348 |
if (!lexer.Eos())
|
|
349 |
{
|
|
350 |
buf = lexer.Remainder();
|
|
351 |
buf.TrimRight();
|
|
352 |
}
|
|
353 |
return KErrNone;
|
|
354 |
}
|
|
355 |
|
|
356 |
EXPORT_C int _wpopen_r (int* aErrno, const wchar_t* command, const char* mode)
|
|
357 |
{
|
|
358 |
wchar_t exepath[KMaxPath+1];
|
|
359 |
TFileName buf;
|
|
360 |
|
|
361 |
if (_parseCmd(command, exepath, buf) == KErrNotFound)
|
|
362 |
{
|
|
363 |
// no such file
|
|
364 |
*aErrno = ENOENT;
|
|
365 |
return -1;
|
|
366 |
}
|
|
367 |
|
|
368 |
return Backend()->popen(exepath, (wchar_t*)buf.PtrZ(), mode, *aErrno);
|
|
369 |
}
|
|
370 |
|
|
371 |
EXPORT_C int _pclose_r(int* aErrno, int aFid)
|
|
372 |
{
|
|
373 |
return Backend()->pclose(aFid, *aErrno);
|
|
374 |
}
|
|
375 |
|
|
376 |
/* A wide-character version of reentrant of popen3().
|
|
377 |
*/
|
|
378 |
EXPORT_C int _wpopen3_r (int* aErrno, const wchar_t* file, const wchar_t* cmd,
|
|
379 |
wchar_t** envp, int fids[3])
|
|
380 |
{
|
|
381 |
|
|
382 |
wchar_t* cmdargs = NULL;
|
|
383 |
if (cmd)
|
|
384 |
{
|
|
385 |
TFileName buf = (TText*)cmd;
|
|
386 |
buf.Trim();
|
|
387 |
cmdargs = (wchar_t*)buf.PtrZ();
|
|
388 |
}
|
|
389 |
|
|
390 |
return Backend()->popen3(file, cmdargs, envp, fids, *aErrno);
|
|
391 |
}
|
|
392 |
|
|
393 |
|
|
394 |
/* A reentrant version of waitpid().
|
|
395 |
*/
|
|
396 |
EXPORT_C int _waitpid_r (int *aErrno, int pid, int* status, int options)
|
|
397 |
{
|
|
398 |
return Backend()->waitpid(pid, status, options, *aErrno);
|
|
399 |
}
|
|
400 |
|
|
401 |
|
|
402 |
/* A reentrant version of wait().
|
|
403 |
*/
|
|
404 |
EXPORT_C int _wait_r (int *aErrno, int* status)
|
|
405 |
{
|
|
406 |
return _waitpid_r(aErrno, -1, status, 0);
|
|
407 |
}
|
|
408 |
|
|
409 |
|
|
410 |
/* A wide-character version of reentrant of system().
|
|
411 |
*/
|
|
412 |
EXPORT_C int _wsystem_r (int *aErrno, const wchar_t* command)
|
|
413 |
{
|
|
414 |
wchar_t exepath[KMaxPath+1];
|
|
415 |
TFileName buf;
|
|
416 |
|
|
417 |
if (NULL == command)
|
|
418 |
{
|
|
419 |
return 1; // special case, says that we do support wsystem().
|
|
420 |
}
|
|
421 |
|
|
422 |
if (_parseCmd(command, (wchar_t*)exepath, buf) == KErrNotFound)
|
|
423 |
{
|
|
424 |
// no such file
|
|
425 |
*aErrno = ENOENT;
|
|
426 |
return -1;
|
|
427 |
}
|
|
428 |
|
|
429 |
return Backend()->system(exepath, (wchar_t*)buf.PtrZ(), *aErrno);
|
|
430 |
}
|
|
431 |
|
|
432 |
|
|
433 |
/* A reentrant version of select().
|
|
434 |
*/
|
|
435 |
EXPORT_C int _select_r(int *aErrno, int maxfd, fd_set *readfds, fd_set *writefds,
|
|
436 |
fd_set *exceptfds, struct timeval *tvptr)
|
|
437 |
{
|
|
438 |
return Backend()->select(maxfd, readfds, writefds, exceptfds, tvptr, *aErrno);
|
|
439 |
}
|
|
440 |
|
|
441 |
|
|
442 |
EXPORT_C int _fchdir_r(int *aErrno, int filedesc)
|
|
443 |
{
|
|
444 |
struct stat st;
|
|
445 |
|
|
446 |
if(_fstat_r(aErrno, filedesc, &st)!=0)
|
|
447 |
{
|
|
448 |
*aErrno = EBADF ;//Not an open file descriptor
|
|
449 |
return -1;
|
|
450 |
}
|
|
451 |
else
|
|
452 |
{
|
|
453 |
if (!(S_ISDIR(st.st_mode)))
|
|
454 |
{
|
|
455 |
*aErrno = ENOTDIR ; //Not a directory
|
|
456 |
return -1;
|
|
457 |
}
|
|
458 |
}
|
|
459 |
|
|
460 |
const wchar_t* dirName(NULL) ;
|
|
461 |
dirName = Backend()->GetDirName (filedesc);
|
|
462 |
|
|
463 |
if( dirName )
|
|
464 |
{
|
|
465 |
return Backend()->chdir(dirName, *aErrno);
|
|
466 |
}
|
|
467 |
else
|
|
468 |
{
|
|
469 |
//fildesc does not refer to a valid fd.
|
|
470 |
*aErrno = ENOTDIR;
|
|
471 |
return -1;
|
|
472 |
}
|
|
473 |
}
|
|
474 |
|
|
475 |
|
|
476 |
/*
|
|
477 |
Gets the path name of the current working directory.
|
|
478 |
If a buffer is specified, the path name is placed in that buffer,
|
|
479 |
and the address of the buffer is returned.
|
|
480 |
@return If successful returns buf, if a non-null pointer was specified,
|
|
481 |
or the address of the allocated memory otherwise.
|
|
482 |
@param anErrno Ref to the error no.
|
|
483 |
@param _buf Points to the buffer to copy the current working directory to,
|
|
484 |
or NULL if getcwd() should allocate the buffer.
|
|
485 |
@param _size Is the size, in bytes, of the array of characters that buf points to.
|
|
486 |
*/
|
|
487 |
/* A reentrant version of getcwd()*/
|
|
488 |
EXPORT_C wchar_t * _getcwd_r (int *aErrno, wchar_t *_buf, size_t _size)
|
|
489 |
{
|
|
490 |
return Backend()->getcwd(_buf, _size, *aErrno);
|
|
491 |
}
|
|
492 |
|
|
493 |
// -----------------------------------------------------------------------------
|
|
494 |
// Function name: link
|
|
495 |
// Description: Provides link functionality.
|
|
496 |
// Returns: 0 : On success
|
|
497 |
// -1 : On error
|
|
498 |
// In case of error, errno value set
|
|
499 |
// Remark: This is a simulated functionality and not supported by the platform
|
|
500 |
// -----------------------------------------------------------------------------
|
|
501 |
//
|
|
502 |
|
|
503 |
EXPORT_C int _link_r(int *aErrno, const wchar_t *_oldwidename, const wchar_t *_newwidename)
|
|
504 |
{
|
|
505 |
return Backend()->link(_oldwidename, _newwidename, *aErrno);
|
|
506 |
}
|
|
507 |
|
|
508 |
|
|
509 |
// -----------------------------------------------------------------------------
|
|
510 |
// Function name: unlink
|
|
511 |
// Description: Provides unlink functionality.
|
|
512 |
// Returns: 0 : On success
|
|
513 |
// -1 : On error
|
|
514 |
// In case of error, errno value set
|
|
515 |
//
|
|
516 |
// -----------------------------------------------------------------------------
|
|
517 |
//
|
|
518 |
|
|
519 |
EXPORT_C int _unlink_r(int *aErrno, const wchar_t *_pathwidename)
|
|
520 |
{
|
|
521 |
return Backend()->unlink(_pathwidename, *aErrno);
|
|
522 |
}
|
|
523 |
|
|
524 |
|
|
525 |
EXPORT_C int _posix_spawn_r(pid_t* pid, const wchar_t* wpath,
|
|
526 |
const posix_spawn_file_actions_t* file_actions,
|
|
527 |
const posix_spawnattr_t* attrp,
|
|
528 |
const wchar_t* wargs,
|
|
529 |
wchar_t** wenvp)
|
|
530 |
{
|
|
531 |
return Backend()->posix_spawn(pid, wpath, file_actions, attrp, wargs, wenvp);
|
|
532 |
}
|
|
533 |
|
|
534 |
// -----------------------------------------------------------------------------
|
|
535 |
// Function name: exit
|
|
536 |
// Description: Provides exit functionality.
|
|
537 |
// In case of error, errno value set
|
|
538 |
//
|
|
539 |
// -----------------------------------------------------------------------------
|
|
540 |
//
|
|
541 |
EXPORT_C void _exit_r(int code)
|
|
542 |
{
|
|
543 |
return Backend()->Exit(code);
|
|
544 |
}
|
|
545 |
|
|
546 |
// -----------------------------------------------------------------------------
|
|
547 |
// _fcntl_r() : A reentrant version of fcntl().
|
|
548 |
// This API is used for setting a file descriptor as non-blocking
|
|
549 |
// Returns: System wide error code
|
|
550 |
// -----------------------------------------------------------------------------
|
|
551 |
//
|
|
552 |
EXPORT_C int _fcntl_r (int *aErrno, int aFid, int aCmd, long anArg)
|
|
553 |
{
|
|
554 |
return Backend()->fcntl(aFid, aCmd, anArg, *aErrno);
|
|
555 |
}
|
|
556 |
|
|
557 |
//
|
|
558 |
EXPORT_C DIR* _opendir_r (int* aErrno, const wchar_t* _path)
|
|
559 |
{
|
|
560 |
__EPOC32_DIR* dp = new __EPOC32_DIR();
|
|
561 |
if (!dp ||(Backend()->AddToDirList((DIR*)dp) != KErrNone))
|
|
562 |
{
|
|
563 |
*aErrno = ENOENT;
|
|
564 |
return 0;
|
|
565 |
}
|
|
566 |
TInt err = dp->Open(_path,aErrno);
|
|
567 |
if (err)
|
|
568 |
{
|
|
569 |
Backend()->RemoveDirFromList((DIR*)dp);
|
|
570 |
delete dp;
|
|
571 |
return 0;
|
|
572 |
}
|
|
573 |
|
|
574 |
return (DIR *)dp;
|
|
575 |
}
|
|
576 |
|
|
577 |
//
|
|
578 |
EXPORT_C int _wclosedir_r(int* aErrno, WDIR* dp)
|
|
579 |
{
|
|
580 |
if(Backend()->RemoveDirFromList((DIR*)dp) == KErrNotFound)
|
|
581 |
{
|
|
582 |
*aErrno = EBADF;
|
|
583 |
}
|
|
584 |
delete dp;
|
|
585 |
return 0;
|
|
586 |
}
|
|
587 |
|
|
588 |
//
|
|
589 |
|
|
590 |
EXPORT_C struct dirent* _readdir_r (int* aErrno, DIR *dp)
|
|
591 |
{
|
|
592 |
__EPOC32_DIR *Dp = (__EPOC32_DIR *)dp ;
|
|
593 |
|
|
594 |
if(!dp || Backend()->FindInDirList((DIR*)dp) == KErrNotFound )
|
|
595 |
{
|
|
596 |
*aErrno = EBADF;
|
|
597 |
return 0;
|
|
598 |
}
|
|
599 |
if (_wreaddir_r(Dp))
|
|
600 |
{
|
|
601 |
if (Dp->UpdateNarrow()>=0)
|
|
602 |
{
|
|
603 |
return &Dp->iCurrentNarrow;
|
|
604 |
}
|
|
605 |
else
|
|
606 |
{
|
|
607 |
*aErrno = EINVAL;
|
|
608 |
}
|
|
609 |
}
|
|
610 |
return 0;
|
|
611 |
}
|
|
612 |
|
|
613 |
EXPORT_C struct wdirent* _wreaddir_r(WDIR *dp)
|
|
614 |
{
|
|
615 |
struct wdirent *ep=&dp->iCurrent;
|
|
616 |
if ((dp->iIndex < 0) || (dp->iIndex > dp->iCount ))
|
|
617 |
return (wdirent *) NULL;
|
|
618 |
|
|
619 |
const TEntry& entry=(*dp->iEntries)[(dp->iIndex)++];
|
|
620 |
// in practice, these files must have been created as "X:\something", so they
|
|
621 |
// can't really be longer than KMaxFileName-3
|
|
622 |
dp->iCurrentName.Copy(entry.iName);
|
|
623 |
dp->iCurrentName.ZeroTerminate();
|
|
624 |
ep->d_namlen=(short)dp->iCurrentName.Length();
|
|
625 |
ep->d_name=(wchar_t*)dp->iCurrentName.PtrZ();
|
|
626 |
return ep;
|
|
627 |
}
|
|
628 |
|
|
629 |
EXPORT_C void _wrewinddir_r(WDIR *dp)
|
|
630 |
{
|
|
631 |
if (dp==0)
|
|
632 |
return;
|
|
633 |
(void) dp->Open(); // POSIX doesn't allow for rewind failing
|
|
634 |
}
|
|
635 |
|
|
636 |
// -----------------------------------------------------------------------------
|
|
637 |
//int _setecho_r(int *aErrno, int aFd, size_t aEchoVal)
|
|
638 |
//
|
|
639 |
//Sets the echo flag for this fd.
|
|
640 |
// -----------------------------------------------------------------------------
|
|
641 |
|
|
642 |
EXPORT_C int _setecho_r(int *aErrno, int aFd, uint8_t aEchoVal)
|
|
643 |
{
|
|
644 |
return Backend()->SetEcho(aFd, aEchoVal, *aErrno);
|
|
645 |
}
|
|
646 |
|
|
647 |
} //extern "C" end
|
|
648 |
|
|
649 |
// These functions should be out of extern "C"
|
|
650 |
/* A reentrant version of aselect().
|
|
651 |
*/
|
|
652 |
EXPORT_C int _aselect_r(int *aErrno, int maxfd, fd_set *readfds, fd_set *writefds,
|
|
653 |
fd_set *exceptfds, struct timeval *tvptr,
|
|
654 |
TRequestStatus* requeststatus)
|
|
655 |
{
|
|
656 |
return Backend()->aselect(maxfd, readfds, writefds, exceptfds, tvptr,requeststatus, *aErrno);
|
|
657 |
}
|
|
658 |
|
|
659 |
/* A reentrant version of cancelaselect().
|
|
660 |
*/
|
|
661 |
EXPORT_C int _cancelaselect_r(int *aErrno, TRequestStatus* requeststatus)
|
|
662 |
{
|
|
663 |
return Backend()->cancelaselect(requeststatus, *aErrno);
|
|
664 |
}
|
|
665 |
|
|
666 |
/* A reentrant version of eselect().
|
|
667 |
*/
|
|
668 |
EXPORT_C int _eselect_r(int *aErrno, int maxfd, fd_set *readfds, fd_set *writefds,
|
|
669 |
fd_set *exceptfds, struct timeval *tvptr, int numreqs,
|
|
670 |
TRequestStatus* waitarray)
|
|
671 |
{
|
|
672 |
return Backend()->eselect(maxfd, readfds, writefds, exceptfds, tvptr,numreqs, waitarray,*aErrno);
|
|
673 |
}
|
|
674 |
|