Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
25 class MSystemInterface
31 virtual MSystemInterface& Clone()=0;
32 virtual void Release()=0;
33 virtual void TerminateProcess(int status)=0;
35 virtual int dup (int fid, int& anErrno)=0;
36 virtual int dup2 (int fid, int fid2, int& anErrno)=0;
37 virtual int open (const wchar_t* name, int mode, int perms, int& anErrno)=0;
38 virtual int read (int fid, char* buf, unsigned long len, int& anErrno)=0;
39 virtual int write (int fid, const char* buf, unsigned long len, int& anErrno)=0;
40 virtual int fsync (int fid, int& anErrno)=0;
41 virtual int close (int fid, int& anErrno)=0;
42 virtual int lseek (int fid, int offset, int whence, int& anErrno)=0;
43 virtual int fstat (int fid, struct stat* st, int& anErrno)=0;
44 virtual int ioctl (int fid, int cmd, void* param, int& anErrno)=0;
45 virtual int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)=0;
46 virtual int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)=0;
47 virtual int ioctl_cancel (int fid, int& anErrno)=0;
49 virtual wchar_t * getcwd (wchar_t * buf, unsigned long len, int& anErrno)=0;
50 virtual int chdir (const wchar_t* path, int& anErrno)=0;
51 virtual int mkdir (const wchar_t* path, int perms, int& anErrno)=0;
52 virtual int rmdir (const wchar_t* path, int& anErrno)=0;
53 virtual int chmod (const wchar_t* path, int perms, int& anErrno)=0;
54 virtual int unlink (const wchar_t* path, int& anErrno)=0;
55 virtual int stat (const wchar_t* name, struct stat* st, int& anErrno)=0;
56 virtual int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno)=0;
58 virtual TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename)=0;
60 virtual int socket (int family, int style, int protocol, int& anErrno)=0;
61 virtual int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno)=0;
62 virtual int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno)=0;
63 virtual int shutdown (int fd, int how, int& anErrno)=0;
64 virtual int listen (int fd, int n, int& anErrno)=0;
65 virtual int accept (int fd, int& anErrno)=0;
66 virtual int bind (int fd, struct sockaddr* addr, unsigned long size, int& anErrno)=0;
67 virtual int connect (int fd, struct sockaddr* addr, unsigned long size, int& anErrno)=0;
68 virtual int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno)=0;
69 virtual int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno)=0;
70 virtual int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno)=0;
72 virtual wchar_t* getenv (const wchar_t* name)=0;
73 virtual void unsetenv (const wchar_t* name)=0;
74 virtual int setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno)=0;
76 virtual int popen3 (const wchar_t *file, const wchar_t *cmd, const wchar_t *mode, wchar_t** envp, int fids[3], int& anErrno)=0;
77 virtual int waitpid (int pid, int* status, int options, int& anErrno)=0;
92 void Default(CFileDescBase* aConsole);
94 TInt Attach(TInt aFid, CFileDescBase* aFile);
95 TInt Detach(TInt aFid, CFileDescBase*& aDetached);
96 TInt At(TInt aFid, CFileDescBase*& aFound) const;
97 TInt Reserve(TInt aFids[3]);
98 TInt Detach(TInt aFids[3]);
100 int dup (int fid, int& anErrno);
101 int dup2 (int fid, int fid2, int& anErrno);
102 // int open (const wchar_t* name, int mode, int perms, int& anErrno, RFs& aFs);
103 int open (const wchar_t* name, int mode, int perms, int& anErrno, RSessionBase& aFs);
104 int close (int fid, int& anErrno);
106 int userclose (int fid, int& anErrno);
108 int lseek (int fid, int offset, int whence, int& anErrno);
109 int fstat (int fid, struct stat* st, int& anErrno);
110 int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs);
111 int listen (int fd, int n, int& anErrno);
112 int bind (int fd, TSockAddr& address, int& anErrno);
113 int sockname (int fd, TSockAddr& address, int anEnd, int& anErrno);
114 int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
115 int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
116 int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
117 int ioctlcancel (int fid, int& anErrno);
119 TInt Asynch (int fid, CFileDescBase*& aFile);
122 CArrayPtrSeg<CFileDescBase> iFids;
123 TInt Dup(TInt& aFid);
124 TInt Dup2(TInt aFid, TInt aFid2);
125 void Release(TInt aFid);
128 class PosixFilesystem
134 static wchar_t* getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno);
135 static int chdir (RFs& aFs, const wchar_t* path, int& anErrno);
136 static int mkdir (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
137 static int rmdir (RFs& aFs, const wchar_t* path, int& anErrno);
138 static int chmod (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
139 static int unlink (RFs& aFs, const wchar_t* path, int& anErrno);
140 static int stat (RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno);
141 static int rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno);
142 static TInt ResolvePath (RFs& aFs, TParse& aResult, const wchar_t* path, TDes* aFilename);
143 static TInt SetDefaultDir (RFs& aFs);
146 NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase, public MSystemInterface
148 To make CleanupStack::PushL() and CleanupStack::Pop() work properly in the 2-phase constructor,
149 derivation order must be: public CBase, public MSystemInterface.
155 static CLocalSystemInterface* NewL();
156 ~CLocalSystemInterface();
158 virtual MSystemInterface& Clone();
159 virtual void Release();
160 virtual void TerminateProcess(int status);
162 virtual int dup (int fid, int& anErrno);
163 virtual int dup2 (int fid, int fid2, int& anErrno);
164 virtual int open (const wchar_t* name, int mode, int perms, int& anErrno);
165 virtual int read (int fid, char* buf, unsigned long len, int& anErrno);
166 virtual int write (int fid, const char* buf, unsigned long len, int& anErrno);
167 virtual int fsync (int fid, int& anErrno);
168 virtual int close (int fid, int& anErrno);
169 virtual int lseek (int fid, int offset, int whence, int& anErrno);
170 virtual int fstat (int fid, struct stat* st, int& anErrno);
171 virtual int ioctl (int fid, int cmd, void* param, int& anErrno);
172 virtual int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
173 virtual int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
174 virtual int ioctl_cancel (int fid, int& anErrno);
176 virtual wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno);
179 virtual int chdir (const wchar_t* path, int& anErrno);
180 virtual int mkdir (const wchar_t* path, int perms, int& anErrno);
181 virtual int rmdir (const wchar_t* path, int& anErrno);
182 virtual int chmod (const wchar_t* path, int perms, int& anErrno);
183 virtual int unlink (const wchar_t* path, int& anErrno);
184 virtual int stat (const wchar_t* name, struct stat* st, int& anErrno);
185 virtual int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno);
187 virtual TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename);
189 virtual int socket (int family, int style, int protocol, int& anErrno);
190 virtual int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno);
191 virtual int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno);
192 virtual int shutdown (int fd, int how, int& anErrno);
193 virtual int listen (int fd, int n, int& anErrno);
194 virtual int accept (int fd, int& anErrno);
195 virtual int bind (int fd, struct sockaddr* addr, unsigned long size, int& anErrno);
196 virtual int connect (int fd, struct sockaddr* addr, unsigned long size, int& anErrno);
197 virtual int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno);
198 virtual int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
199 virtual int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
201 virtual wchar_t* getenv (const wchar_t* name);
202 virtual void unsetenv (const wchar_t* name);
203 virtual int setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno);
205 virtual int popen3 (const wchar_t *file, const wchar_t *cmd, const wchar_t *mode, wchar_t** envp, int fids[3], int& anErrno);
206 virtual int waitpid (int pid, int* status, int options, int& anErrno);
209 CLocalSystemInterface();
223 #include <sys/reent.h>
227 inline MSystemInterface& Interface(struct _reent* r)
228 { return (*REINTERPRET_CAST(MSystemInterface*,r->_system)); }