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.
14 // PosixFilesystem class
23 #include <sys/errno.h>
25 wchar_t * PosixFilesystem::getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno)
28 TInt err = aFs.SessionPath(name);
31 TPtr16 pathdes((TText16 *)buf, len);
32 if (pathdes.MaxLength() >= (name.Length() + 1)) //+1 to allow for the null terminator
35 pathdes.ZeroTerminate();
39 err = ERANGE; //out of range
41 MapError(err, anErrno);
45 int PosixFilesystem::chdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
48 TInt err=GetFullPath(name, (const TText16 *)aPath, aFs, NULL);
51 TPtrC path=name.DriveAndPath();
53 if (path.Length()==3) // Problem in F32 - the root directory has no attributes
56 err=aFs.Att(path, att);
59 err=aFs.SetSessionPath(path);
63 return MapError(err,anErrno);
66 int PosixFilesystem::rmdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
69 TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
72 TPtrC path=name.DriveAndPath();
75 err=EPERM; // no, you may not remove the root directory
77 err=aFs.Att(path, att);
83 err=EEXIST; // i.e. directory not empty
88 return MapError(err,anErrno);
93 int PosixFilesystem::mkdir (RFs& aFs, const wchar_t* aPath, int perms, int& anErrno)
96 TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
99 TPtrC path=name.DriveAndPath();
103 if ((perms&S_IWUSR)==0)
104 err=aFs.SetAtt(path,KEntryAttReadOnly,0);
107 return MapError(err,anErrno);
110 int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno)
113 TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
117 if (fullName.Length()==3)
119 entry.iAtt=KEntryAttDir;
120 entry.iModified==TTime(0);
123 err=aFs.Entry(fullName,entry);
126 st->st_size = entry.iSize;
127 st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName);
128 CFileDesc::MapStat(*st, entry.iModified, entry.iAtt);
132 return MapError(err, anErrno);
135 int PosixFilesystem::chmod (RFs& aFs, const wchar_t* name, int perms, int& anErrno)
138 TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
141 if ((perms&S_IWUSR)==0)
142 err=aFs.SetAtt(fullName,KEntryAttReadOnly,0);
144 err=aFs.SetAtt(fullName,0,KEntryAttReadOnly);
146 return MapError(err, anErrno);
149 int PosixFilesystem::unlink (RFs& aFs, const wchar_t* name, int& anErrno)
152 TInt err=GetFullFile(fullName, (TText16*)name, aFs);
156 err=aFs.Att(fullName, att);
158 if (att&KEntryAttDir)
161 err=aFs.Delete(fullName);
163 return MapError(err, anErrno);
166 int PosixFilesystem::rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno)
168 TFileName oldFullName;
169 TInt err = GetFullFile(oldFullName,(const TText16 *)oldname,aFs);
172 TFileName newFullName;
173 err = GetFullFile(newFullName,(const TText16 *)newname,aFs);
176 // ANSI doesn't require specific handling when newname exists,
177 // so we can just use the EPOC32 semantics and insist that
178 // newname doesn't currently exist.
179 err=aFs.Rename(oldFullName,newFullName);
182 return MapError(err, anErrno);
186 TInt PosixFilesystem::ResolvePath (RFs& aFs, TParse& aResult, const wchar_t* path, TDes* aFilename)
188 return GetFullPath(aResult,(const TText16*)path,aFs,aFilename);
193 TInt PosixFilesystem::SetDefaultDir (RFs& /*aFs*/)
195 // NB. don't do this on WINS because the executable is
196 // something like w:\epoc32\release\wins\deb\mytest.exe (or just mytest.exe or
201 TInt PosixFilesystem::SetDefaultDir (RFs& aFs)
204 parse.Set(RProcess().FileName(), NULL, NULL);
205 #ifdef __SECURE_DATA__
206 return aFs.SetSessionToPrivate(TDriveUnit(parse.Drive()));
208 return aFs.SetSessionPath(parse.DriveAndPath());