sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // 
sl@0: //
sl@0: 
sl@0: #include <unistd.h>
sl@0: #include <errno.h>
sl@0: #include "sysreent.h"
sl@0: #include <dirent.h>
sl@0: #include <utf.h>
sl@0: #include <stddef.h>
sl@0: #include <string.h>
sl@0: #include <stdlib.h>
sl@0: #include <wchar.h>
sl@0: #include <sys/errno.h>
sl@0: #include "sysif.h"
sl@0: 
sl@0: #define	MAXPATHLEN	260	/* E32STD.H: KMaxFullName + 4 to avoid data loss */
sl@0: 
sl@0: extern "C" {
sl@0: /*
sl@0: Opens a directory.
sl@0: */
sl@0: EXPORT_C DIR* opendir(const char* _path)
sl@0: 	{
sl@0: 	wchar_t _wpath[MAXPATHLEN+1];
sl@0: 	
sl@0: 	if (mbstowcs(_wpath, _path, MAXPATHLEN) == (size_t)-1)
sl@0: 		{
sl@0: 		errno = EILSEQ;
sl@0: 		return 0;
sl@0: 		}
sl@0: 	return _opendir_r(&errno, _wpath);
sl@0: 	}
sl@0: 
sl@0: /* 
sl@0: A wide-character version of opendir()
sl@0: */
sl@0: EXPORT_C WDIR* wopendir(const wchar_t* _wpath)
sl@0: 	{
sl@0: 	if (!_wpath)
sl@0: 		{
sl@0: 		errno = ENOENT;
sl@0: 		return NULL;
sl@0: 		}
sl@0: 	return (WDIR*)_opendir_r(&errno, _wpath);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C struct dirent* readdir(DIR* dp)
sl@0: 	{
sl@0: 	return _readdir_r(&errno, dp);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C struct wdirent* wreaddir(WDIR* wdp)
sl@0: 	{
sl@0: 	if (!wdp)
sl@0: 		{
sl@0: 		errno = EBADF;
sl@0: 		return NULL;
sl@0: 		}
sl@0: 	return _wreaddir_r(wdp);
sl@0: 	}
sl@0: 
sl@0: /*
sl@0: Sets the position (associated with the directory stream that dirp points to) 
sl@0: to the beginning of the directory. 
sl@0: Additionally, it causes the directory stream to refer to the current state of 
sl@0: the corresponding directory.
sl@0: */
sl@0: EXPORT_C void wrewinddir(WDIR* wdp)
sl@0: 	{
sl@0: 	_wrewinddir_r(wdp);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void rewinddir(DIR* dp)
sl@0: 	{
sl@0: 	WDIR* wdp = (__EPOC32_DIR*)dp;
sl@0: 	wrewinddir(wdp);
sl@0: 	}
sl@0: 
sl@0: /*
sl@0: closes the directory stream that dirp refers to. 
sl@0: The memory associated with the directory stream is released. 
sl@0: When this function returns, the value of dirp no longer point to 
sl@0: an accessible object of type DIR
sl@0: */
sl@0: 
sl@0: EXPORT_C int wclosedir(WDIR* wdp)
sl@0: 	{
sl@0: 	return _wclosedir_r(&errno,wdp);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C int closedir(DIR* dp)
sl@0: 	{
sl@0: 	if (!dp)
sl@0: 		{
sl@0: 		errno = EBADF;
sl@0: 		return -1;
sl@0: 		}
sl@0: 		
sl@0: 	WDIR* wdp =  (__EPOC32_DIR*)dp;
sl@0: 	return wclosedir(wdp);
sl@0: 	}
sl@0: 
sl@0: /*
sl@0: sets the position of the next readdir() operation on the directory 
sl@0: stream specified by dp to the position specified by index.
sl@0: */
sl@0: 
sl@0: EXPORT_C void wseekdir(WDIR* wdp, off_t index)
sl@0: 	{
sl@0: 	if(!wdp)
sl@0: 		{
sl@0: 	 	errno = EFAULT ;
sl@0: 		return ;	
sl@0: 		}
sl@0: 	wdp->iIndex = index;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void seekdir(DIR* dp, long index)
sl@0: 	{
sl@0:     WDIR* wdp = (__EPOC32_DIR*)dp;
sl@0: 	wseekdir(wdp, index);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: EXPORT_C off_t wtelldir(const WDIR* wdp)
sl@0: 	{
sl@0: 	if(!wdp)
sl@0: 		{
sl@0: 	 	errno = EFAULT ;
sl@0: 		return -1 ;	
sl@0: 		}
sl@0: 	if(wdp->iCount < 0 )
sl@0: 		{
sl@0: 		return -1;
sl@0: 		}
sl@0: 	return wdp->iIndex;
sl@0: 	}
sl@0: 
sl@0: /*
sl@0: Returns the current location associated with the directory stream dir.
sl@0: */
sl@0: EXPORT_C long telldir(DIR* dp)
sl@0: 	{
sl@0: 	WDIR* wdp =  (__EPOC32_DIR*)dp;
sl@0: 	return (long)wtelldir(wdp);
sl@0: 	}
sl@0: 
sl@0: }// extern "C"