1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/INC/SYSIF.H Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,228 @@
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 +#include <e32std.h>
1.20 +#include <e32base.h>
1.21 +#include <f32file.h>
1.22 +#include <es_sock.h>
1.23 +#include "ENVIRON.H"
1.24 +#include <stdlib.h>
1.25 +#include <c32comm.h>
1.26 +
1.27 +
1.28 +class MSystemInterface
1.29 +/**
1.30 +@internalComponent
1.31 +*/
1.32 + {
1.33 +public:
1.34 + virtual MSystemInterface& Clone()=0;
1.35 + virtual void Release()=0;
1.36 + virtual void TerminateProcess(int status)=0;
1.37 +
1.38 + virtual int dup (int fid, int& anErrno)=0;
1.39 + virtual int dup2 (int fid, int fid2, int& anErrno)=0;
1.40 + virtual int open (const wchar_t* name, int mode, int perms, int& anErrno)=0;
1.41 + virtual int read (int fid, char* buf, unsigned long len, int& anErrno)=0;
1.42 + virtual int write (int fid, const char* buf, unsigned long len, int& anErrno)=0;
1.43 + virtual int fsync (int fid, int& anErrno)=0;
1.44 + virtual int close (int fid, int& anErrno)=0;
1.45 + virtual int lseek (int fid, int offset, int whence, int& anErrno)=0;
1.46 + virtual int fstat (int fid, struct stat* st, int& anErrno)=0;
1.47 + virtual int ioctl (int fid, int cmd, void* param, int& anErrno)=0;
1.48 + virtual int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)=0;
1.49 + virtual int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)=0;
1.50 + virtual int ioctl_cancel (int fid, int& anErrno)=0;
1.51 +
1.52 + virtual wchar_t * getcwd (wchar_t * buf, unsigned long len, int& anErrno)=0;
1.53 + virtual int chdir (const wchar_t* path, int& anErrno)=0;
1.54 + virtual int mkdir (const wchar_t* path, int perms, int& anErrno)=0;
1.55 + virtual int rmdir (const wchar_t* path, int& anErrno)=0;
1.56 + virtual int chmod (const wchar_t* path, int perms, int& anErrno)=0;
1.57 + virtual int unlink (const wchar_t* path, int& anErrno)=0;
1.58 + virtual int stat (const wchar_t* name, struct stat* st, int& anErrno)=0;
1.59 + virtual int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno)=0;
1.60 +
1.61 + virtual TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename)=0;
1.62 +
1.63 + virtual int socket (int family, int style, int protocol, int& anErrno)=0;
1.64 + virtual int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno)=0;
1.65 + virtual int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno)=0;
1.66 + virtual int shutdown (int fd, int how, int& anErrno)=0;
1.67 + virtual int listen (int fd, int n, int& anErrno)=0;
1.68 + virtual int accept (int fd, int& anErrno)=0;
1.69 + virtual int bind (int fd, struct sockaddr* addr, unsigned long size, int& anErrno)=0;
1.70 + virtual int connect (int fd, struct sockaddr* addr, unsigned long size, int& anErrno)=0;
1.71 + virtual int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno)=0;
1.72 + virtual int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno)=0;
1.73 + virtual int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno)=0;
1.74 +
1.75 + virtual wchar_t* getenv (const wchar_t* name)=0;
1.76 + virtual void unsetenv (const wchar_t* name)=0;
1.77 + virtual int setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno)=0;
1.78 +
1.79 + virtual int popen3 (const wchar_t *file, const wchar_t *cmd, const wchar_t *mode, wchar_t** envp, int fids[3], int& anErrno)=0;
1.80 + virtual int waitpid (int pid, int* status, int options, int& anErrno)=0;
1.81 + };
1.82 +
1.83 +class CFileDescBase;
1.84 +class CFileTable
1.85 +/**
1.86 +@internalComponent
1.87 +*/
1.88 + {
1.89 +public:
1.90 + CFileTable();
1.91 + ~CFileTable();
1.92 +
1.93 + void InitL();
1.94 + void Close();
1.95 + void Default(CFileDescBase* aConsole);
1.96 + TInt Reserve();
1.97 + TInt Attach(TInt aFid, CFileDescBase* aFile);
1.98 + TInt Detach(TInt aFid, CFileDescBase*& aDetached);
1.99 + TInt At(TInt aFid, CFileDescBase*& aFound) const;
1.100 + TInt Reserve(TInt aFids[3]);
1.101 + TInt Detach(TInt aFids[3]);
1.102 +
1.103 + int dup (int fid, int& anErrno);
1.104 + int dup2 (int fid, int fid2, int& anErrno);
1.105 +// int open (const wchar_t* name, int mode, int perms, int& anErrno, RFs& aFs);
1.106 + int open (const wchar_t* name, int mode, int perms, int& anErrno, RSessionBase& aFs);
1.107 + int close (int fid, int& anErrno);
1.108 +
1.109 + int userclose (int fid, int& anErrno);
1.110 +
1.111 + int lseek (int fid, int offset, int whence, int& anErrno);
1.112 + int fstat (int fid, struct stat* st, int& anErrno);
1.113 + int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs);
1.114 + int listen (int fd, int n, int& anErrno);
1.115 + int bind (int fd, TSockAddr& address, int& anErrno);
1.116 + int sockname (int fd, TSockAddr& address, int anEnd, int& anErrno);
1.117 + int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
1.118 + int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
1.119 + int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
1.120 + int ioctlcancel (int fid, int& anErrno);
1.121 +
1.122 + TInt Asynch (int fid, CFileDescBase*& aFile);
1.123 +
1.124 +private:
1.125 + CArrayPtrSeg<CFileDescBase> iFids;
1.126 + TInt Dup(TInt& aFid);
1.127 + TInt Dup2(TInt aFid, TInt aFid2);
1.128 + void Release(TInt aFid);
1.129 + };
1.130 +
1.131 +class PosixFilesystem
1.132 +/**
1.133 +@internalComponent
1.134 +*/
1.135 + {
1.136 +public:
1.137 + static wchar_t* getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno);
1.138 + static int chdir (RFs& aFs, const wchar_t* path, int& anErrno);
1.139 + static int mkdir (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
1.140 + static int rmdir (RFs& aFs, const wchar_t* path, int& anErrno);
1.141 + static int chmod (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
1.142 + static int unlink (RFs& aFs, const wchar_t* path, int& anErrno);
1.143 + static int stat (RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno);
1.144 + static int rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno);
1.145 + static TInt ResolvePath (RFs& aFs, TParse& aResult, const wchar_t* path, TDes* aFilename);
1.146 + static TInt SetDefaultDir (RFs& aFs);
1.147 + };
1.148 +
1.149 +NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase, public MSystemInterface
1.150 +/**
1.151 +To make CleanupStack::PushL() and CleanupStack::Pop() work properly in the 2-phase constructor,
1.152 +derivation order must be: public CBase, public MSystemInterface.
1.153 +
1.154 +@internalComponent
1.155 +*/
1.156 + {
1.157 +public:
1.158 + static CLocalSystemInterface* NewL();
1.159 + ~CLocalSystemInterface();
1.160 +
1.161 + virtual MSystemInterface& Clone();
1.162 + virtual void Release();
1.163 + virtual void TerminateProcess(int status);
1.164 +
1.165 + virtual int dup (int fid, int& anErrno);
1.166 + virtual int dup2 (int fid, int fid2, int& anErrno);
1.167 + virtual int open (const wchar_t* name, int mode, int perms, int& anErrno);
1.168 + virtual int read (int fid, char* buf, unsigned long len, int& anErrno);
1.169 + virtual int write (int fid, const char* buf, unsigned long len, int& anErrno);
1.170 + virtual int fsync (int fid, int& anErrno);
1.171 + virtual int close (int fid, int& anErrno);
1.172 + virtual int lseek (int fid, int offset, int whence, int& anErrno);
1.173 + virtual int fstat (int fid, struct stat* st, int& anErrno);
1.174 + virtual int ioctl (int fid, int cmd, void* param, int& anErrno);
1.175 + virtual int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
1.176 + virtual int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
1.177 + virtual int ioctl_cancel (int fid, int& anErrno);
1.178 +
1.179 + virtual wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno);
1.180 +
1.181 +
1.182 + virtual int chdir (const wchar_t* path, int& anErrno);
1.183 + virtual int mkdir (const wchar_t* path, int perms, int& anErrno);
1.184 + virtual int rmdir (const wchar_t* path, int& anErrno);
1.185 + virtual int chmod (const wchar_t* path, int perms, int& anErrno);
1.186 + virtual int unlink (const wchar_t* path, int& anErrno);
1.187 + virtual int stat (const wchar_t* name, struct stat* st, int& anErrno);
1.188 + virtual int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno);
1.189 +
1.190 + virtual TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename);
1.191 +
1.192 + virtual int socket (int family, int style, int protocol, int& anErrno);
1.193 + virtual int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno);
1.194 + virtual int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno);
1.195 + virtual int shutdown (int fd, int how, int& anErrno);
1.196 + virtual int listen (int fd, int n, int& anErrno);
1.197 + virtual int accept (int fd, int& anErrno);
1.198 + virtual int bind (int fd, struct sockaddr* addr, unsigned long size, int& anErrno);
1.199 + virtual int connect (int fd, struct sockaddr* addr, unsigned long size, int& anErrno);
1.200 + virtual int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno);
1.201 + virtual int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
1.202 + virtual int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
1.203 +
1.204 + virtual wchar_t* getenv (const wchar_t* name);
1.205 + virtual void unsetenv (const wchar_t* name);
1.206 + virtual int setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno);
1.207 +
1.208 + virtual int popen3 (const wchar_t *file, const wchar_t *cmd, const wchar_t *mode, wchar_t** envp, int fids[3], int& anErrno);
1.209 + virtual int waitpid (int pid, int* status, int options, int& anErrno);
1.210 +
1.211 +private:
1.212 + CLocalSystemInterface();
1.213 + void ConstructL();
1.214 +
1.215 +private:
1.216 + TInt iUseCount;
1.217 + CFileTable iFids;
1.218 + RFs iFs;
1.219 + RSocketServ iSs;
1.220 +
1.221 + RCommServ iCs;
1.222 +
1.223 + CEnvironment iEnv;
1.224 + };
1.225 +
1.226 +#include <sys/reent.h>
1.227 +/**
1.228 +@internalComponent
1.229 +*/
1.230 +inline MSystemInterface& Interface(struct _reent* r)
1.231 + { return (*REINTERPRET_CAST(MSystemInterface*,r->_system)); }