PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
file.h
Go to the documentation of this file.
1 /*
2  * file.h
3  *
4  * Operating System file I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 31371 $
30  * $Author: rjongbloed $
31  * $Date: 2014-02-06 13:34:49 +1100 (Thu, 06 Feb 2014) $
32  */
33 
34 
35 #ifndef PTLIB_FILE_H
36 #define PTLIB_FILE_H
37 
38 #ifdef P_USE_PRAGMA
39 #pragma interface
40 #endif
41 
42 #ifndef _WIN32
43 #include <sys/stat.h>
44 #endif
45 
46 #include <ptlib/bitwise_enum.h>
47 
48 
50 // Binary Files
51 
61 class PFile : public PChannel
62 {
63  PCLASSINFO(PFile, PChannel);
64 
65  public:
72  PFile();
73 
78  enum OpenMode {
82  };
83 
94  P_DECLARE_BITWISE_ENUM_EX(OpenOptions, 7,
95  (NoOptions,
96  MustExist,
97  Create,
98  Truncate,
99  Exclusive,
100  Temporary,
101  DenySharedRead,
102  DenySharedWrite
103  ),
104  ModeDefault = -1
105  );
106 
115  PFile(
116  OpenMode mode,
117  OpenOptions opts = ModeDefault
118  );
119 
126  PFile(
127  const PFilePath & name,
128  OpenMode mode = ReadWrite,
129  OpenOptions opts = ModeDefault
130  );
131 
133  ~PFile();
135 
136 
146  const PObject & obj
147  ) const;
149 
150 
159  virtual PString GetName() const;
160 
172  virtual PBoolean Read(
173  void * buf,
174  PINDEX len
175  );
176 
186  virtual PBoolean Write(
187  const void * buf,
188  PINDEX len
189  );
190 
194  virtual PBoolean Close();
196 
197 
207  static bool Exists(
208  const PFilePath & name
209  );
210 
218  bool Exists() const;
219 
229  static bool Access(
230  const PFilePath & name,
231  OpenMode mode
232  );
233 
244  bool Access(
245  OpenMode mode
246  );
247 
260  static bool Remove(
261  const PFilePath & name,
262  bool force = false
263  );
264  static bool Remove(
265  const PString & name,
266  bool force = false
267  );
268 
281  bool Remove(
282  bool force = false
283  );
284 
300  static bool Rename(
301  const PFilePath & oldname,
302  const PString & newname,
303  bool force = false
304  );
305 
322  bool Rename(
323  const PString & newname,
324  bool force = false
325  );
326 
332  static bool Copy(
333  const PFilePath & oldname,
334  const PFilePath & newname,
335  bool force = false,
336  bool recurse = false
337  );
338 
344  bool Copy(
345  const PFilePath & newname,
346  bool force = false,
347  bool recurse = false
348  );
349 
359  static bool Move(
360  const PFilePath & oldname,
361  const PFilePath & newname,
362  bool force = false,
363  bool recurse = false
364  );
365 
375  bool Move(
376  const PFilePath & newname,
377  bool force = false,
378  bool recurse = false
379  );
381 
390  const PFilePath & GetFilePath() const;
391 
395  void SetFilePath(
396  const PString & path
397  );
398 
399 
411  virtual PBoolean Open(
412  OpenMode mode = ReadWrite,
413  OpenOptions opts = ModeDefault
414  );
415 
423  virtual PBoolean Open(
424  OpenMode mode,
425  OpenOptions opts,
426  PFileInfo::Permissions permissions
427  );
428 
436  virtual PBoolean Open(
437  const PFilePath & name,
438  OpenMode mode = ReadWrite,
439  OpenOptions opts = ModeDefault
440  );
441 
449  virtual PBoolean Open(
450  const PFilePath & name,
451  OpenMode mode,
452  OpenOptions opts,
453  PFileInfo::Permissions permissions
454  );
455 
461  virtual off_t GetLength() const;
462 
469  virtual PBoolean SetLength(
470  off_t len // New length of file.
471  );
472 
475  Start = SEEK_SET,
476  Current = SEEK_CUR,
477  End = SEEK_END
478  };
479 
490  virtual PBoolean SetPosition(
491  off_t pos,
492  FilePositionOrigin origin = Start
493  );
494 
501  virtual off_t GetPosition() const;
502 
509  bool IsEndOfFile() const;
510 
516  static bool GetInfo(
517  const PFilePath & name,
518  PFileInfo & info
519  );
520 
526  bool GetInfo(
527  PFileInfo & info
528  );
529 
535  static bool SetPermissions(
536  const PFilePath & name,
537  PFileInfo::Permissions permissions
538  );
544  bool SetPermissions(
545  PFileInfo::Permissions permissions
546  );
548 
549  protected:
550  // Member variables
551 
554 
555 
556 // Include platform dependent part of class
557 #ifdef _WIN32
558 #include "msos/ptlib/file.h"
559 #else
560 #include "unix/ptlib/file.h"
561 #endif
562 };
563 
564 
565 #endif // PTLIB_FILE_H
566 
567 
568 // End Of File ///////////////////////////////////////////////////////////////