|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Implementation of nsIFile for ``Unixy'' systems. |
|
8 */ |
|
9 |
|
10 #ifndef _nsLocalFileUNIX_H_ |
|
11 #define _nsLocalFileUNIX_H_ |
|
12 |
|
13 #include <sys/stat.h> |
|
14 #include <sys/types.h> |
|
15 #include <unistd.h> |
|
16 |
|
17 #include "nscore.h" |
|
18 #include "nsString.h" |
|
19 #include "nsReadableUtils.h" |
|
20 #include "nsIHashable.h" |
|
21 #include "nsIClassInfoImpl.h" |
|
22 #include "mozilla/Attributes.h" |
|
23 #ifdef MOZ_WIDGET_COCOA |
|
24 #include "nsILocalFileMac.h" |
|
25 #endif |
|
26 |
|
27 /** |
|
28 * we need these for statfs() |
|
29 */ |
|
30 #ifdef HAVE_SYS_STATVFS_H |
|
31 #if defined(__osf__) && defined(__DECCXX) |
|
32 extern "C" int statvfs(const char *, struct statvfs *); |
|
33 #endif |
|
34 #include <sys/statvfs.h> |
|
35 #endif |
|
36 |
|
37 #ifdef HAVE_SYS_STATFS_H |
|
38 #include <sys/statfs.h> |
|
39 #endif |
|
40 |
|
41 #ifdef HAVE_SYS_VFS_H |
|
42 #include <sys/vfs.h> |
|
43 #endif |
|
44 |
|
45 #ifdef HAVE_SYS_MOUNT_H |
|
46 #include <sys/param.h> |
|
47 #include <sys/mount.h> |
|
48 #endif |
|
49 |
|
50 #if defined(HAVE_STATVFS64) && (!defined(LINUX) && !defined(__osf__)) |
|
51 #define STATFS statvfs64 |
|
52 #define F_BSIZE f_frsize |
|
53 #elif defined(HAVE_STATVFS) && (!defined(LINUX) && !defined(__osf__)) |
|
54 #define STATFS statvfs |
|
55 #define F_BSIZE f_frsize |
|
56 #elif defined(HAVE_STATFS64) |
|
57 #define STATFS statfs64 |
|
58 #define F_BSIZE f_bsize |
|
59 #elif defined(HAVE_STATFS) |
|
60 #define STATFS statfs |
|
61 #define F_BSIZE f_bsize |
|
62 #endif |
|
63 |
|
64 // stat64 and lstat64 are deprecated on OS X. Normal stat and lstat are |
|
65 // 64-bit by default on OS X 10.6+. |
|
66 #if defined(HAVE_STAT64) && defined(HAVE_LSTAT64) && !defined(XP_MACOSX) |
|
67 #if defined (AIX) |
|
68 #if defined STAT |
|
69 #undef STAT |
|
70 #endif |
|
71 #endif |
|
72 #define STAT stat64 |
|
73 #define LSTAT lstat64 |
|
74 #define HAVE_STATS64 1 |
|
75 #else |
|
76 #define STAT stat |
|
77 #define LSTAT lstat |
|
78 #endif |
|
79 |
|
80 |
|
81 class nsLocalFile MOZ_FINAL : |
|
82 #ifdef MOZ_WIDGET_COCOA |
|
83 public nsILocalFileMac, |
|
84 #else |
|
85 public nsILocalFile, |
|
86 #endif |
|
87 public nsIHashable |
|
88 { |
|
89 public: |
|
90 NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID) |
|
91 |
|
92 nsLocalFile(); |
|
93 |
|
94 static nsresult nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); |
|
95 |
|
96 NS_DECL_THREADSAFE_ISUPPORTS |
|
97 NS_DECL_NSIFILE |
|
98 NS_DECL_NSILOCALFILE |
|
99 #ifdef MOZ_WIDGET_COCOA |
|
100 NS_DECL_NSILOCALFILEMAC |
|
101 #endif |
|
102 NS_DECL_NSIHASHABLE |
|
103 |
|
104 public: |
|
105 static void GlobalInit(); |
|
106 static void GlobalShutdown(); |
|
107 |
|
108 private: |
|
109 nsLocalFile(const nsLocalFile& other); |
|
110 ~nsLocalFile() {} |
|
111 |
|
112 protected: |
|
113 // This stat cache holds the *last stat* - it does not invalidate. |
|
114 // Call "FillStatCache" whenever you want to stat our file. |
|
115 struct STAT mCachedStat; |
|
116 nsCString mPath; |
|
117 |
|
118 void LocateNativeLeafName(nsACString::const_iterator &, |
|
119 nsACString::const_iterator &); |
|
120 |
|
121 nsresult CopyDirectoryTo(nsIFile *newParent); |
|
122 nsresult CreateAllAncestors(uint32_t permissions); |
|
123 nsresult GetNativeTargetPathName(nsIFile *newParent, |
|
124 const nsACString &newName, |
|
125 nsACString &_retval); |
|
126 |
|
127 bool FillStatCache(); |
|
128 |
|
129 nsresult CreateAndKeepOpen(uint32_t type, int flags, |
|
130 uint32_t permissions, PRFileDesc **_retval); |
|
131 }; |
|
132 |
|
133 #endif /* _nsLocalFileUNIX_H_ */ |