Back to index

lightning-sunbird  0.9+nobinonly
nsLocalFileUnix.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Mike Shaver <shaver@mozilla.org>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /*
00041  * Implementation of nsIFile for ``Unixy'' systems.
00042  */
00043 
00044 #ifndef _nsLocalFileUNIX_H_
00045 #define _nsLocalFileUNIX_H_
00046 
00047 #include <sys/stat.h>
00048 #include <sys/types.h>
00049 #include <unistd.h>
00050 
00051 #include "nscore.h"
00052 #include "nsString.h"
00053 #include "nsReadableUtils.h"
00054 
00058 #ifdef HAVE_SYS_STATVFS_H
00059     #if defined(__osf__) && defined(__DECCXX)
00060         extern "C" int statvfs(const char *, struct statvfs *);
00061     #endif
00062     #include <sys/statvfs.h>
00063 #endif
00064 
00065 #ifdef HAVE_SYS_STATFS_H
00066     #include <sys/statfs.h>
00067 #endif
00068 
00069 #ifdef HAVE_STATVFS
00070     #define STATFS statvfs
00071 #else
00072     #define STATFS statfs
00073 #endif
00074 
00075 // so we can statfs on freebsd
00076 #if defined(__FreeBSD__)
00077     #define HAVE_SYS_STATFS_H
00078     #define STATFS statfs
00079     #include <sys/param.h>
00080     #include <sys/mount.h>
00081 #endif
00082 
00083 class NS_COM nsLocalFile : public nsILocalFile
00084 {
00085 public:
00086     NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
00087     
00088     nsLocalFile();
00089 
00090     static NS_METHOD nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
00091 
00092     // nsISupports
00093     NS_DECL_ISUPPORTS
00094 
00095     // nsIFile
00096     NS_DECL_NSIFILE
00097 
00098     // nsILocalFile
00099     NS_DECL_NSILOCALFILE
00100 
00101 public:
00102     static void GlobalInit();
00103     static void GlobalShutdown();
00104 
00105 private:
00106     nsLocalFile(const nsLocalFile& other);
00107     ~nsLocalFile() {}
00108 
00109 protected:
00110     struct stat  mCachedStat;
00111     nsCString    mPath;
00112     PRPackedBool mHaveCachedStat;
00113 
00114     void LocateNativeLeafName(nsACString::const_iterator &,
00115                               nsACString::const_iterator &);
00116 
00117     nsresult CopyDirectoryTo(nsIFile *newParent);
00118     nsresult CreateAllAncestors(PRUint32 permissions);
00119     nsresult GetNativeTargetPathName(nsIFile *newParent,
00120                                      const nsACString &newName,
00121                                      nsACString &_retval);
00122 
00123     void InvalidateCache() {
00124         mHaveCachedStat = PR_FALSE;
00125     }
00126     nsresult FillStatCache();
00127 
00128     nsresult CreateAndKeepOpen(PRUint32 type, PRIntn flags,
00129                                PRUint32 permissions, PRFileDesc **_retval);
00130 };
00131 
00132 #endif /* _nsLocalFileUNIX_H_ */