On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / netwerk / base / src / nsFileStreams.h
blob3bbf07c6c450c4fe13ff9756da451df47c942c16
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsFileStreams_h__
39 #define nsFileStreams_h__
41 #include "nsIFileStreams.h"
42 #include "nsIFile.h"
43 #include "nsIInputStream.h"
44 #include "nsIOutputStream.h"
45 #include "nsISafeOutputStream.h"
46 #include "nsISeekableStream.h"
47 #include "nsILineInputStream.h"
48 #include "nsCOMPtr.h"
49 #include "prlog.h"
50 #include "prio.h"
52 template<class CharType> class nsLineBuffer;
54 ////////////////////////////////////////////////////////////////////////////////
56 class nsFileStream : public nsISeekableStream
58 public:
59 NS_DECL_ISUPPORTS
60 NS_DECL_NSISEEKABLESTREAM
62 nsFileStream();
63 virtual ~nsFileStream();
65 nsresult Close();
66 nsresult InitWithFileDescriptor(PRFileDesc* fd, nsISupports* parent);
68 protected:
69 PRFileDesc* mFD;
70 nsCOMPtr<nsISupports> mParent; // strong reference to parent nsFileIO,
71 // which ensures mFD remains valid.
72 PRBool mCloseFD;
75 ////////////////////////////////////////////////////////////////////////////////
77 class nsFileInputStream : public nsFileStream,
78 public nsIFileInputStream,
79 public nsILineInputStream
81 public:
82 NS_DECL_ISUPPORTS_INHERITED
83 NS_DECL_NSIINPUTSTREAM
84 NS_DECL_NSIFILEINPUTSTREAM
85 NS_DECL_NSILINEINPUTSTREAM
87 // Overrided from nsFileStream
88 NS_IMETHOD Seek(PRInt32 aWhence, PRInt64 aOffset);
90 nsFileInputStream() : nsFileStream()
92 mLineBuffer = nsnull;
93 mBehaviorFlags = 0;
95 virtual ~nsFileInputStream()
97 Close();
100 static NS_METHOD
101 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
103 protected:
104 nsLineBuffer<char> *mLineBuffer;
107 * The file being opened. Only stored when DELETE_ON_CLOSE or
108 * REOPEN_ON_REWIND are true.
110 nsCOMPtr<nsIFile> mFile;
112 * The IO flags passed to Init() for the file open.
113 * Only set for REOPEN_ON_REWIND.
115 PRInt32 mIOFlags;
117 * The permissions passed to Init() for the file open.
118 * Only set for REOPEN_ON_REWIND.
120 PRInt32 mPerm;
122 * Flags describing our behavior. See the IDL file for possible values.
124 PRInt32 mBehaviorFlags;
126 protected:
128 * Internal, called to open a file. Parameters are the same as their
129 * Init() analogues.
131 nsresult Open(nsIFile* file, PRInt32 ioFlags, PRInt32 perm);
133 * Reopen the file (for OPEN_ON_READ only!)
135 nsresult Reopen() { return Open(mFile, mIOFlags, mPerm); }
138 ////////////////////////////////////////////////////////////////////////////////
140 class nsFileOutputStream : public nsFileStream,
141 public nsIFileOutputStream
143 public:
144 NS_DECL_ISUPPORTS_INHERITED
145 NS_DECL_NSIOUTPUTSTREAM
146 NS_DECL_NSIFILEOUTPUTSTREAM
148 nsFileOutputStream() : nsFileStream() {}
149 virtual ~nsFileOutputStream() { nsFileOutputStream::Close(); }
151 static NS_METHOD
152 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
155 ////////////////////////////////////////////////////////////////////////////////
157 class nsSafeFileOutputStream : public nsFileOutputStream,
158 public nsISafeOutputStream
160 public:
161 NS_DECL_ISUPPORTS_INHERITED
162 NS_DECL_NSISAFEOUTPUTSTREAM
164 nsSafeFileOutputStream() :
165 mTargetFileExists(PR_TRUE),
166 mWriteResult(NS_OK) {}
168 virtual ~nsSafeFileOutputStream() { nsSafeFileOutputStream::Close(); }
170 NS_IMETHODIMP Close();
171 NS_IMETHODIMP Write(const char *buf, PRUint32 count, PRUint32 *result);
172 NS_IMETHODIMP Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags);
174 protected:
175 nsCOMPtr<nsIFile> mTargetFile;
176 nsCOMPtr<nsIFile> mTempFile;
178 PRBool mTargetFileExists;
179 nsresult mWriteResult; // Internally set in Write()
182 ////////////////////////////////////////////////////////////////////////////////
184 #endif // nsFileStreams_h__