genericopenlibs/openenvcore/backend/src/syscall/handlefms.cpp
changeset 0 e4d67989cc36
child 15 18da5738c9b6
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 EXPORT_C int _utime_r (int *aErrno, const wchar_t *name,const  struct utimbuf *filetimes) 
       
   171 	{
       
   172 	return Backend()->utime(name, filetimes, *aErrno);
       
   173 	}
       
   174 
       
   175 
       
   176 /* A reentrant version of wstat().
       
   177 */
       
   178 EXPORT_C int _wstat_r (int *aErrno, const wchar_t *name, struct stat *st) 
       
   179 	{
       
   180 	return Backend()->stat(name, st, *aErrno);
       
   181 	}
       
   182 
       
   183 /* A reentrant version of dup().
       
   184 */
       
   185 EXPORT_C int _dup_r (int *aErrno, int aFid)
       
   186 	{
       
   187 	return Backend()->dup(aFid, *aErrno);
       
   188 	}
       
   189 
       
   190 /* A reentrant version of dup2().
       
   191 */
       
   192 EXPORT_C int _dup2_r (int *aErrno, int aFid1, int aFid2)
       
   193 	{
       
   194 	return Backend()->dup2(aFid1, aFid2, *aErrno);
       
   195 	}
       
   196 
       
   197 /* A reentrant version of ioctl().
       
   198 */
       
   199 EXPORT_C int _ioctl_r (int *aErrno, int aFid, int aCmd, void* aParam)
       
   200 	{
       
   201 	return Backend()->ioctl(aFid, aCmd, aParam, *aErrno);
       
   202 	}
       
   203 
       
   204 /* A wide-character version of reentrant of getcwd().
       
   205 */
       
   206 EXPORT_C wchar_t * _wgetcwd_r (int *aErrno, wchar_t *_buf, size_t _size)
       
   207 	{
       
   208 	if (_buf==0)
       
   209 		{
       
   210 		_buf=(wchar_t *)User::Alloc(_size*sizeof(wchar_t));
       
   211 		if (_buf==0)
       
   212 			{
       
   213 			*aErrno=ENOMEM;
       
   214 			return _buf;
       
   215 			}
       
   216 		}
       
   217 	return Backend()->getcwd(_buf, _size, *aErrno);
       
   218 	}
       
   219 
       
   220 /* A reentrant version of chdir().
       
   221 */
       
   222 EXPORT_C int _chdir_r (int *aErrno, const wchar_t *_path)
       
   223 	{
       
   224 	return Backend()->chdir(_path, *aErrno);
       
   225 	}
       
   226 
       
   227 /* A reentrant version of wchdir().
       
   228 */
       
   229 EXPORT_C int _wchdir_r (int *aErrno, const wchar_t *_path)
       
   230 	{
       
   231 	return Backend()->chdir(_path, *aErrno);
       
   232 	}
       
   233 
       
   234 /* A reentrant version of rmdir().
       
   235 */
       
   236 EXPORT_C int _rmdir_r (int *aErrno, const wchar_t *_path)
       
   237 	{
       
   238 	 return Backend()->rmdir(_path, *aErrno);
       
   239 	}
       
   240 
       
   241 
       
   242 /* A reentrant version of wrmdir().
       
   243 */
       
   244 EXPORT_C int _wrmdir_r (int *aErrno, const wchar_t *_path)
       
   245 	{
       
   246 	return Backend()->rmdir(_path, *aErrno);
       
   247 	}
       
   248 
       
   249 
       
   250 /* A reentrant version of mkdir().
       
   251 */
       
   252 EXPORT_C int _mkdir_r (int *aErrno, const wchar_t *_path, mode_t _mode)
       
   253 	{
       
   254 	return Backend()->mkdir(_path, _mode, *aErrno);
       
   255 	}
       
   256 
       
   257 /* A reentrant version of wmkdir().
       
   258 */
       
   259 EXPORT_C int _wmkdir_r (int *aErrno, const wchar_t *_path, mode_t _mode)
       
   260 	{
       
   261 	return Backend()->mkdir(_path, _mode, *aErrno);
       
   262 	}
       
   263 
       
   264 
       
   265 /* A reentrant version of chmod().
       
   266 */
       
   267 EXPORT_C int _chmod_r (int *aErrno, const wchar_t *_path, mode_t _mode)
       
   268 	{
       
   269 	return Backend()->chmod(_path, _mode, *aErrno);
       
   270 	}
       
   271 
       
   272 /* A reentrant version of chmod().
       
   273 */
       
   274 EXPORT_C int _fchmod_r (int *aErrno, int _fd , mode_t _mode)
       
   275 	{
       
   276 	return Backend()->fchmod(_fd, _mode, *aErrno);
       
   277 	}
       
   278 /* A reentrant version of wchmod().
       
   279 */
       
   280 EXPORT_C int _wchmod_r (int *aErrno, const wchar_t *_path, mode_t _mode)
       
   281 	{
       
   282 	return Backend()->chmod(_path, _mode, *aErrno);
       
   283 	}
       
   284 
       
   285 /* A wide-character version of reentrant of unlink().
       
   286 */
       
   287 EXPORT_C int _wunlink_r (int *aErrno, const wchar_t *_path)
       
   288 	{
       
   289 	return Backend()->unlink(_path, *aErrno);
       
   290 	}
       
   291 
       
   292 
       
   293 /* A reentrant version of rename().
       
   294 */
       
   295 EXPORT_C int _rename_r (int *aErrno, const wchar_t *oldpath, const wchar_t *newpath)
       
   296 	{
       
   297 	return Backend()->rename(oldpath, newpath, *aErrno);
       
   298 	}
       
   299 
       
   300 
       
   301 /* A wide-character version of reentrant of rename().
       
   302 */
       
   303 EXPORT_C int _wrename_r (int *aErrno, const wchar_t *oldpath, const wchar_t *newpath)
       
   304 	{
       
   305 	return Backend()->rename(oldpath, newpath, *aErrno);
       
   306 	}
       
   307 
       
   308 /* A wide-character version of reentrant of realpath().
       
   309 */
       
   310 EXPORT_C wchar_t * _wrealpath_r (int *aErrno, const wchar_t *relpath, wchar_t *resolved)
       
   311 	{
       
   312 		if(relpath == NULL || resolved == NULL)   //invalid arguments
       
   313 			{
       
   314 				*aErrno = EFAULT;
       
   315 				return (NULL);
       
   316 			}
       
   317 	TPtr16 name((TText16*)resolved,MAXPATHLEN);
       
   318 	TParse path;
       
   319 	TInt err = Backend()->ResolvePath(path, relpath, &name);
       
   320 	if (!err)
       
   321 		{
       
   322 		err = path.SetNoWild(path.DriveAndPath(),NULL,&name);
       
   323 		if (!err)
       
   324 			{
       
   325 			name = path.FullName();
       
   326 			name.ZeroTerminate();
       
   327 			return resolved;
       
   328 			}
       
   329 		}
       
   330 	MapError(err, *aErrno);
       
   331 	return 0;
       
   332 	}
       
   333 
       
   334 LOCAL_C TInt _parseCmd (const wchar_t* command, wchar_t* exepath, TDes& buf)
       
   335 	{
       
   336 	TLex lexer((TText*)command);
       
   337 	buf = lexer.NextToken();
       
   338 	WcsCpy(exepath,(wchar_t*)buf.PtrZ());
       
   339 
       
   340 	lexer.SkipSpace();
       
   341 	if (!lexer.Eos())
       
   342 		{
       
   343 		buf = lexer.Remainder();
       
   344 		buf.TrimRight();
       
   345 		}
       
   346 	return KErrNone;
       
   347 	}
       
   348 
       
   349 EXPORT_C int _wpopen_r (int* aErrno, const wchar_t* command, const char* mode)
       
   350 	{
       
   351 	wchar_t exepath[KMaxPath+1];
       
   352 	TFileName buf;
       
   353 
       
   354 	if (_parseCmd(command, exepath, buf) == KErrNotFound)
       
   355 		{
       
   356 		// no such file
       
   357 		*aErrno = ENOENT;
       
   358 		return -1;
       
   359 		}
       
   360 		
       
   361 	return Backend()->popen(exepath, (wchar_t*)buf.PtrZ(), mode, *aErrno);
       
   362 	}
       
   363 
       
   364 EXPORT_C int _pclose_r(int* aErrno, int aFid)
       
   365 	{
       
   366 	return Backend()->pclose(aFid, *aErrno);
       
   367 	}
       
   368 
       
   369 /* A wide-character version of reentrant of popen3().
       
   370 */
       
   371 EXPORT_C int _wpopen3_r (int* aErrno, const wchar_t* file, const wchar_t* cmd, 
       
   372 						 wchar_t** envp, int fids[3])
       
   373 	{
       
   374 			
       
   375 	wchar_t* cmdargs = NULL;
       
   376 	if (cmd)
       
   377 		{
       
   378 		TFileName buf = (TText*)cmd;
       
   379 		buf.Trim();
       
   380 		cmdargs = (wchar_t*)buf.PtrZ();
       
   381 		}
       
   382 
       
   383 	return Backend()->popen3(file, cmdargs, envp, fids, *aErrno);
       
   384 	}
       
   385 
       
   386 
       
   387 /* A reentrant version of waitpid().
       
   388 */
       
   389 EXPORT_C int _waitpid_r (int *aErrno, int pid, int* status, int options)
       
   390 	{
       
   391 	return Backend()->waitpid(pid, status, options, *aErrno);
       
   392 	}
       
   393 
       
   394 
       
   395 /* A reentrant version of wait().
       
   396 */
       
   397 EXPORT_C int _wait_r (int *aErrno, int* status)
       
   398 	{
       
   399 	return _waitpid_r(aErrno, -1, status, 0);
       
   400 	}
       
   401 
       
   402 
       
   403 /* A wide-character version of reentrant of system().
       
   404 */
       
   405 EXPORT_C int _wsystem_r (int *aErrno, const wchar_t* command)
       
   406 	{
       
   407 	wchar_t exepath[KMaxPath+1];
       
   408 	TFileName buf;		
       
   409 	
       
   410 	if (NULL == command)
       
   411 		{
       
   412 		return 1;	// special case, says that we do support wsystem().
       
   413 		}		
       
   414 		
       
   415 	if (_parseCmd(command, (wchar_t*)exepath, buf) == KErrNotFound)
       
   416 		{
       
   417 		// no such file
       
   418 		*aErrno = ENOENT;
       
   419 		return -1;
       
   420 		}
       
   421 	
       
   422 	return Backend()->system(exepath, (wchar_t*)buf.PtrZ(), *aErrno);
       
   423 	}
       
   424 
       
   425 
       
   426 /* A reentrant version of select().
       
   427 */
       
   428 EXPORT_C int _select_r(int *aErrno, int maxfd, fd_set *readfds, fd_set *writefds,
       
   429 					   fd_set *exceptfds, struct timeval *tvptr)
       
   430 	{
       
   431 	return Backend()->select(maxfd, readfds, writefds, exceptfds, tvptr, *aErrno);
       
   432 	}	
       
   433 
       
   434 
       
   435 EXPORT_C int _fchdir_r(int *aErrno, int filedesc)
       
   436 	{
       
   437 	struct stat st;
       
   438 	
       
   439 	if(_fstat_r(aErrno, filedesc, &st)!=0)
       
   440 		{
       
   441 		*aErrno  = EBADF ;//Not an open file descriptor
       
   442 		return -1;
       
   443 		}
       
   444 	else 
       
   445 		{
       
   446 		if (!(S_ISDIR(st.st_mode)))
       
   447 			{
       
   448 			*aErrno = ENOTDIR ; //Not a directory
       
   449 			return -1;
       
   450 			}
       
   451 		}
       
   452 		
       
   453 	const wchar_t* dirName(NULL) ;
       
   454 	dirName = Backend()->GetDirName (filedesc);
       
   455 
       
   456 	if( dirName )
       
   457 		{
       
   458 		return Backend()->chdir(dirName, *aErrno);
       
   459 		}
       
   460 	else
       
   461 		{
       
   462 		//fildesc does not refer to a valid fd.
       
   463 		*aErrno = ENOTDIR;
       
   464 		return -1;
       
   465 		}
       
   466 	}
       
   467 
       
   468 
       
   469 /*
       
   470 Gets the path name of the current working directory.
       
   471 If a buffer is specified, the path name is placed in that buffer,
       
   472 and the address of the buffer is returned. 
       
   473 @return If successful returns buf, if a non-null pointer was specified, 
       
   474 or the address of the allocated memory otherwise.
       
   475 @param anErrno Ref to the error no. 
       
   476 @param _buf Points to the buffer to copy the current working directory to, 
       
   477 or NULL if getcwd() should allocate the buffer.
       
   478 @param _size Is the size, in bytes, of the array of characters that buf points to.
       
   479 */
       
   480 /* A reentrant version of getcwd()*/
       
   481 EXPORT_C wchar_t * _getcwd_r (int *aErrno, wchar_t *_buf, size_t _size)
       
   482 	{
       
   483 	return Backend()->getcwd(_buf, _size, *aErrno);
       
   484 	}
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // Function name: link
       
   488 // Description: Provides link functionality.
       
   489 // Returns:  0    : On success
       
   490 //          -1    : On error
       
   491 // In case of error, errno value set
       
   492 // Remark: This is a simulated functionality and not supported by the platform     
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 
       
   496 EXPORT_C int _link_r(int *aErrno, const wchar_t *_oldwidename, const wchar_t *_newwidename)
       
   497 	{
       
   498    	return Backend()->link(_oldwidename, _newwidename, *aErrno);					            
       
   499 	}
       
   500 
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // Function name: unlink
       
   504 // Description: Provides unlink functionality.
       
   505 // Returns:  0    : On success
       
   506 //          -1    : On error
       
   507 // In case of error, errno value set
       
   508 //      
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 
       
   512 EXPORT_C int _unlink_r(int *aErrno, const wchar_t *_pathwidename)
       
   513 	{
       
   514 	return Backend()->unlink(_pathwidename, *aErrno);				            
       
   515 	}
       
   516 
       
   517    
       
   518 EXPORT_C int _posix_spawn_r(pid_t* pid, const wchar_t* wpath, 
       
   519 							const posix_spawn_file_actions_t* file_actions,
       
   520 							const posix_spawnattr_t* attrp,
       
   521 							const wchar_t* wargs, 
       
   522 							wchar_t** wenvp)
       
   523 	{
       
   524 	return Backend()->posix_spawn(pid, wpath, file_actions, attrp, wargs, wenvp);
       
   525 	}
       
   526 	
       
   527 // -----------------------------------------------------------------------------
       
   528 // Function name: exit
       
   529 // Description: Provides exit functionality.
       
   530 // In case of error, errno value set
       
   531 //      
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 EXPORT_C void _exit_r(int code)
       
   535 	{
       
   536 	return Backend()->Exit(code);
       
   537 	}
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 // _fcntl_r() : A reentrant version of fcntl().
       
   541 // This API is used for setting a file descriptor as non-blocking
       
   542 // Returns: System wide error code
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 EXPORT_C int _fcntl_r (int *aErrno, int aFid, int aCmd, long anArg)
       
   546 	{
       
   547 	return Backend()->fcntl(aFid, aCmd, anArg, *aErrno);
       
   548 	}
       
   549 	
       
   550 //
       
   551 EXPORT_C DIR* _opendir_r (int* aErrno, const wchar_t* _path)
       
   552 	{
       
   553 	 __EPOC32_DIR* dp = new __EPOC32_DIR();
       
   554 	if (!dp ||(Backend()->AddToDirList((DIR*)dp) != KErrNone))
       
   555 		{
       
   556 		*aErrno = ENOENT;
       
   557 		return 0;
       
   558 		}
       
   559 	TInt err = dp->Open(_path,aErrno);
       
   560 	if (err)
       
   561 		{
       
   562 		Backend()->RemoveDirFromList((DIR*)dp);
       
   563 		delete dp;
       
   564 		return 0;
       
   565 		}
       
   566 		
       
   567 	return (DIR *)dp;
       
   568 	}
       
   569 
       
   570 //
       
   571 EXPORT_C int _wclosedir_r(int* aErrno, WDIR* dp)
       
   572 	{
       
   573 	if(Backend()->RemoveDirFromList((DIR*)dp) == KErrNotFound)
       
   574 		{
       
   575 		*aErrno = EBADF;	
       
   576 		}
       
   577 	delete dp;
       
   578 	return 0;
       
   579 	}
       
   580 
       
   581 // 
       
   582 
       
   583 EXPORT_C struct dirent* _readdir_r (int* aErrno, DIR *dp)
       
   584     {
       
   585 	__EPOC32_DIR *Dp  = (__EPOC32_DIR *)dp ;
       
   586 	
       
   587 	if(!dp || Backend()->FindInDirList((DIR*)dp) == KErrNotFound )
       
   588 		{
       
   589 		*aErrno = EBADF;
       
   590 		return 0;	
       
   591 		}
       
   592 	if (_wreaddir_r(Dp))
       
   593 		{
       
   594 		if (Dp->UpdateNarrow()>=0)
       
   595 			{
       
   596 			return &Dp->iCurrentNarrow;	
       
   597 			}
       
   598 		else
       
   599 			{
       
   600 			*aErrno = EINVAL;
       
   601 			}
       
   602 		}
       
   603 	return 0;
       
   604 	}
       
   605 
       
   606 EXPORT_C struct wdirent* _wreaddir_r(WDIR *dp)
       
   607 	{
       
   608 	struct wdirent *ep=&dp->iCurrent;
       
   609 	if ((dp->iIndex < 0) ||  (dp->iIndex > dp->iCount ))
       
   610 		return  (wdirent *) NULL;
       
   611 	
       
   612 	const TEntry& entry=(*dp->iEntries)[(dp->iIndex)++];
       
   613 	// in practice, these files must have been created as "X:\something", so they
       
   614 	// can't really be longer than KMaxFileName-3
       
   615 	dp->iCurrentName.Copy(entry.iName);
       
   616 	dp->iCurrentName.ZeroTerminate();
       
   617 	ep->d_namlen=(short)dp->iCurrentName.Length();
       
   618 	ep->d_name=(wchar_t*)dp->iCurrentName.PtrZ();
       
   619 	return ep;
       
   620 	}
       
   621 
       
   622 EXPORT_C void _wrewinddir_r(WDIR *dp)
       
   623 	{
       
   624 	if (dp==0)
       
   625 		return;
       
   626 	(void) dp->Open();	// POSIX doesn't allow for rewind failing
       
   627 	}
       
   628 	
       
   629 // -----------------------------------------------------------------------------
       
   630 //int _setecho_r(int *aErrno, int aFd, size_t aEchoVal)
       
   631 //
       
   632 //Sets the echo flag for this fd.
       
   633 // -----------------------------------------------------------------------------
       
   634 
       
   635 EXPORT_C int _setecho_r(int *aErrno, int aFd, uint8_t aEchoVal)
       
   636 	{
       
   637 	return Backend()->SetEcho(aFd, aEchoVal, *aErrno);
       
   638 	}
       
   639 	
       
   640 } //extern "C" end
       
   641 
       
   642 // These functions should be out of extern "C"
       
   643 /* A reentrant version of aselect().
       
   644 */
       
   645 EXPORT_C int _aselect_r(int *aErrno, int maxfd, fd_set *readfds, fd_set *writefds, 
       
   646 						fd_set *exceptfds, struct timeval *tvptr,
       
   647 						TRequestStatus* requeststatus)
       
   648 	{
       
   649 	return Backend()->aselect(maxfd, readfds, writefds, exceptfds, tvptr,requeststatus, *aErrno);
       
   650 	}	
       
   651 
       
   652 /* A reentrant version of cancelaselect().
       
   653 */
       
   654 EXPORT_C int _cancelaselect_r(int *aErrno, TRequestStatus* requeststatus)
       
   655 	{
       
   656 	return Backend()->cancelaselect(requeststatus, *aErrno);
       
   657 	}	
       
   658 
       
   659 /* A reentrant version of eselect().
       
   660 */
       
   661 EXPORT_C int _eselect_r(int *aErrno, int maxfd, fd_set *readfds, fd_set *writefds,
       
   662 						fd_set *exceptfds, struct timeval *tvptr, int numreqs,
       
   663 						TRequestStatus* waitarray)
       
   664 	{
       
   665 	return Backend()->eselect(maxfd, readfds, writefds, exceptfds, tvptr,numreqs, waitarray,*aErrno);
       
   666 	}
       
   667