1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/opendir.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,161 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +//
1.19 +
1.20 +#include <unistd.h>
1.21 +#include <errno.h>
1.22 +#include "sysreent.h"
1.23 +#include <dirent.h>
1.24 +#include <utf.h>
1.25 +#include <stddef.h>
1.26 +#include <string.h>
1.27 +#include <stdlib.h>
1.28 +#include <wchar.h>
1.29 +#include <sys/errno.h>
1.30 +#include "sysif.h"
1.31 +
1.32 +#define MAXPATHLEN 260 /* E32STD.H: KMaxFullName + 4 to avoid data loss */
1.33 +
1.34 +extern "C" {
1.35 +/*
1.36 +Opens a directory.
1.37 +*/
1.38 +EXPORT_C DIR* opendir(const char* _path)
1.39 + {
1.40 + wchar_t _wpath[MAXPATHLEN+1];
1.41 +
1.42 + if (mbstowcs(_wpath, _path, MAXPATHLEN) == (size_t)-1)
1.43 + {
1.44 + errno = EILSEQ;
1.45 + return 0;
1.46 + }
1.47 + return _opendir_r(&errno, _wpath);
1.48 + }
1.49 +
1.50 +/*
1.51 +A wide-character version of opendir()
1.52 +*/
1.53 +EXPORT_C WDIR* wopendir(const wchar_t* _wpath)
1.54 + {
1.55 + if (!_wpath)
1.56 + {
1.57 + errno = ENOENT;
1.58 + return NULL;
1.59 + }
1.60 + return (WDIR*)_opendir_r(&errno, _wpath);
1.61 + }
1.62 +
1.63 +EXPORT_C struct dirent* readdir(DIR* dp)
1.64 + {
1.65 + return _readdir_r(&errno, dp);
1.66 + }
1.67 +
1.68 +EXPORT_C struct wdirent* wreaddir(WDIR* wdp)
1.69 + {
1.70 + if (!wdp)
1.71 + {
1.72 + errno = EBADF;
1.73 + return NULL;
1.74 + }
1.75 + return _wreaddir_r(wdp);
1.76 + }
1.77 +
1.78 +/*
1.79 +Sets the position (associated with the directory stream that dirp points to)
1.80 +to the beginning of the directory.
1.81 +Additionally, it causes the directory stream to refer to the current state of
1.82 +the corresponding directory.
1.83 +*/
1.84 +EXPORT_C void wrewinddir(WDIR* wdp)
1.85 + {
1.86 + _wrewinddir_r(wdp);
1.87 + }
1.88 +
1.89 +EXPORT_C void rewinddir(DIR* dp)
1.90 + {
1.91 + WDIR* wdp = (__EPOC32_DIR*)dp;
1.92 + wrewinddir(wdp);
1.93 + }
1.94 +
1.95 +/*
1.96 +closes the directory stream that dirp refers to.
1.97 +The memory associated with the directory stream is released.
1.98 +When this function returns, the value of dirp no longer point to
1.99 +an accessible object of type DIR
1.100 +*/
1.101 +
1.102 +EXPORT_C int wclosedir(WDIR* wdp)
1.103 + {
1.104 + return _wclosedir_r(&errno,wdp);
1.105 + }
1.106 +
1.107 +EXPORT_C int closedir(DIR* dp)
1.108 + {
1.109 + if (!dp)
1.110 + {
1.111 + errno = EBADF;
1.112 + return -1;
1.113 + }
1.114 +
1.115 + WDIR* wdp = (__EPOC32_DIR*)dp;
1.116 + return wclosedir(wdp);
1.117 + }
1.118 +
1.119 +/*
1.120 +sets the position of the next readdir() operation on the directory
1.121 +stream specified by dp to the position specified by index.
1.122 +*/
1.123 +
1.124 +EXPORT_C void wseekdir(WDIR* wdp, off_t index)
1.125 + {
1.126 + if(!wdp)
1.127 + {
1.128 + errno = EFAULT ;
1.129 + return ;
1.130 + }
1.131 + wdp->iIndex = index;
1.132 + }
1.133 +
1.134 +EXPORT_C void seekdir(DIR* dp, long index)
1.135 + {
1.136 + WDIR* wdp = (__EPOC32_DIR*)dp;
1.137 + wseekdir(wdp, index);
1.138 + }
1.139 +
1.140 +
1.141 +EXPORT_C off_t wtelldir(const WDIR* wdp)
1.142 + {
1.143 + if(!wdp)
1.144 + {
1.145 + errno = EFAULT ;
1.146 + return -1 ;
1.147 + }
1.148 + if(wdp->iCount < 0 )
1.149 + {
1.150 + return -1;
1.151 + }
1.152 + return wdp->iIndex;
1.153 + }
1.154 +
1.155 +/*
1.156 +Returns the current location associated with the directory stream dir.
1.157 +*/
1.158 +EXPORT_C long telldir(DIR* dp)
1.159 + {
1.160 + WDIR* wdp = (__EPOC32_DIR*)dp;
1.161 + return (long)wtelldir(wdp);
1.162 + }
1.163 +
1.164 +}// extern "C"