Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / io / nsLocalFileUnix.h
blobeb37e3effd87569e1a9cc4c774ed3bb56d8ac43c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * Implementation of nsIFile for ``Unixy'' systems.
9 */
11 #ifndef _nsLocalFileUNIX_H_
12 #define _nsLocalFileUNIX_H_
14 #include <sys/stat.h>
16 #include "nscore.h"
17 #include "nsString.h"
18 #ifdef MOZ_WIDGET_COCOA
19 # include "nsILocalFileMac.h"
20 #endif
22 // stat64 and lstat64 are deprecated on OS X. Normal stat and lstat are
23 // 64-bit by default on OS X 10.6+.
24 #if defined(HAVE_STAT64) && defined(HAVE_LSTAT64) && !defined(XP_DARWIN)
25 # if defined(AIX)
26 # if defined STAT
27 # undef STAT
28 # endif
29 # endif
30 # define STAT stat64
31 # define LSTAT lstat64
32 # define HAVE_STATS64 1
33 #else
34 # define STAT stat
35 # define LSTAT lstat
36 #endif
38 #if defined(HAVE_SYS_QUOTA_H) && defined(HAVE_LINUX_QUOTA_H)
39 # define USE_LINUX_QUOTACTL
40 #endif
42 class nsLocalFile final
43 #ifdef MOZ_WIDGET_COCOA
44 : public nsILocalFileMac
45 #else
46 : public nsIFile
47 #endif
49 public:
50 NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
52 nsLocalFile();
53 explicit nsLocalFile(const nsACString& aFilePath);
55 static nsresult nsLocalFileConstructor(const nsIID& aIID,
56 void** aInstancePtr);
58 NS_DECL_THREADSAFE_ISUPPORTS
59 NS_DECL_NSIFILE
60 #ifdef MOZ_WIDGET_COCOA
61 NS_DECL_NSILOCALFILEMAC
62 #endif
64 private:
65 nsLocalFile(const nsLocalFile& aOther);
66 ~nsLocalFile() = default;
68 protected:
69 // This stat cache holds the *last stat* - it does not invalidate.
70 // Call "FillStatCache" whenever you want to stat our file.
71 struct STAT mCachedStat;
72 nsCString mPath;
74 void LocateNativeLeafName(nsACString::const_iterator&,
75 nsACString::const_iterator&);
77 nsresult CopyDirectoryTo(nsIFile* aNewParent);
78 nsresult CreateAllAncestors(uint32_t aPermissions);
79 nsresult GetNativeTargetPathName(nsIFile* aNewParent,
80 const nsACString& aNewName,
81 nsACString& aResult);
83 bool FillStatCache();
85 nsresult CreateAndKeepOpen(uint32_t aType, int aFlags, uint32_t aPermissions,
86 bool aSkipAncestors, PRFileDesc** aResult);
88 enum class TimeField { AccessedTime, ModifiedTime };
89 nsresult SetTimeImpl(PRTime aTime, TimeField aTimeField, bool aFollowLinks);
90 nsresult GetTimeImpl(PRTime* aTime, TimeField aTimeField, bool aFollowLinks);
92 nsresult GetCreationTimeImpl(PRTime* aCreationTime, bool aFollowLinks);
94 #if defined(USE_LINUX_QUOTACTL)
95 template <typename StatInfoFunc, typename QuotaInfoFunc>
96 nsresult GetDiskInfo(StatInfoFunc&& aStatInfoFunc,
97 QuotaInfoFunc&& aQuotaInfoFunc, int64_t* aResult);
98 #else
99 template <typename StatInfoFunc>
100 nsresult GetDiskInfo(StatInfoFunc&& aStatInfoFunc, int64_t* aResult);
101 #endif
104 #endif /* _nsLocalFileUNIX_H_ */