2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: file.h
|
2008-09-25 15:15:28 -04:00
|
|
|
// Purpose: interface of wxTempFile, wxFile
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxTempFile
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxTempFile provides a relatively safe way to replace the contents of the
|
|
|
|
existing file. The name is explained by the fact that it may be also used as
|
|
|
|
just a temporary file if you don't replace the old file contents.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Usually, when a program replaces the contents of some file it first opens it for
|
2008-09-25 10:03:38 -04:00
|
|
|
writing, thus losing all of the old data and then starts recreating it.
|
|
|
|
This approach is not very safe because during the regeneration of the file bad
|
|
|
|
things may happen: the program may find that there is an internal error preventing
|
|
|
|
it from completing file generation, the user may interrupt it (especially if file
|
2008-03-08 08:52:38 -05:00
|
|
|
generation takes long time) and, finally, any other external interrupts (power
|
|
|
|
supply failure or a disk error) will leave you without either the original file
|
|
|
|
or the new one.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxTempFile addresses this problem by creating a temporary file which is meant to
|
|
|
|
replace the original file - but only after it is fully written. So, if the user
|
|
|
|
interrupts the program during the file generation, the old file won't be lost.
|
|
|
|
Also, if the program discovers itself that it doesn't want to replace the old
|
|
|
|
file there is no problem - in fact, wxTempFile will @b not replace the old
|
2008-09-25 10:03:38 -04:00
|
|
|
file by default, you should explicitly call wxTempFile::Commit() to do it.
|
|
|
|
Calling wxTempFile::Discard() explicitly discards any modifications: it
|
|
|
|
closes and deletes the temporary file and leaves the original file unchanged.
|
2008-11-22 09:20:28 -05:00
|
|
|
If you call neither Commit() nor Discard(), the destructor will
|
2008-09-25 10:03:38 -04:00
|
|
|
call Discard() automatically.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
To summarize: if you want to replace another file, create an instance of
|
2008-11-22 09:20:28 -05:00
|
|
|
wxTempFile passing the name of the file to be replaced to the constructor.
|
|
|
|
(You may also use default constructor and pass the file name to wxTempFile::Open.)
|
2008-09-25 10:03:38 -04:00
|
|
|
Then you can write to wxTempFile using wxFile-like functions and later call
|
|
|
|
wxTempFile::Commit() to replace the old file (and close this one) or call
|
|
|
|
wxTempFile::Discard() to cancel the modifications.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{file}
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxTempFile
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2020-02-21 08:57:28 -05:00
|
|
|
/**
|
|
|
|
Default constructor doesn't do anything.
|
|
|
|
|
|
|
|
Call Open() later.
|
|
|
|
*/
|
|
|
|
wxTempFile();
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Associates wxTempFile with the file to be replaced and opens it.
|
2009-01-10 17:10:54 -05:00
|
|
|
|
|
|
|
@warning
|
2008-11-22 09:20:28 -05:00
|
|
|
You should use IsOpened() to verify that the constructor succeeded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2020-02-21 08:56:06 -05:00
|
|
|
explicit wxTempFile(const wxString& strName);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-11-22 09:20:28 -05:00
|
|
|
Destructor calls Discard() if temporary file is still open.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
~wxTempFile();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Validate changes: deletes the old file of name m_strName and renames the new
|
2008-09-25 10:03:38 -04:00
|
|
|
file to the old name. Returns @true if both actions succeeded.
|
|
|
|
|
|
|
|
If @false is returned it may unfortunately mean two quite different things:
|
2008-11-22 09:20:28 -05:00
|
|
|
either that the old file couldn't be deleted or that the new file
|
2008-09-25 10:03:38 -04:00
|
|
|
couldn't be renamed to the old name.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Commit();
|
|
|
|
|
|
|
|
/**
|
2008-11-22 09:20:28 -05:00
|
|
|
Discard changes: the old file contents are not changed, the temporary
|
|
|
|
file is deleted.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Discard();
|
|
|
|
|
2009-05-31 05:49:31 -04:00
|
|
|
/**
|
|
|
|
Flush the data written to the file to disk.
|
|
|
|
|
|
|
|
This simply calls wxFile::Flush() for the underlying file and may be
|
|
|
|
necessary with file systems such as XFS and Ext4 under Linux. Calling
|
|
|
|
this function may however have serious performance implications and
|
|
|
|
also is not necessary with many other file systems so it is not done by
|
|
|
|
default -- but you can call it before calling Commit() to absolutely
|
|
|
|
ensure that the data was indeed written to the disk correctly.
|
|
|
|
*/
|
|
|
|
bool Flush();
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns @true if the file was successfully opened.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOpened() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the file.
|
2008-09-19 04:11:44 -04:00
|
|
|
|
2017-12-15 11:19:09 -05:00
|
|
|
Returns ::wxInvalidOffset if the length couldn't be determined.
|
|
|
|
|
|
|
|
Please also note that there is @e no guarantee that reading that many
|
|
|
|
bytes from the file will always succeed. While this is true for regular
|
|
|
|
files (unless the file size has been changed by another process in
|
|
|
|
between Length() and Read() calls), some special files, such as most
|
|
|
|
files under @c /sys or @c /proc directories under Linux, don't actually
|
|
|
|
contain as much data as their size indicates.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxFileOffset Length() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Open the temporary file, returns @true on success, @false if an error
|
|
|
|
occurred.
|
2008-03-09 08:33:59 -04:00
|
|
|
@a strName is the name of file to be replaced. The temporary file is always
|
2008-09-25 10:03:38 -04:00
|
|
|
created in the directory where @a strName is. In particular, if @a strName
|
|
|
|
doesn't include the path, it is created in the current directory and the
|
|
|
|
program should have write access to it for the function to succeed.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Open(const wxString& strName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Seeks to the specified position.
|
|
|
|
*/
|
|
|
|
wxFileOffset Seek(wxFileOffset ofs,
|
|
|
|
wxSeekMode mode = wxFromStart);
|
|
|
|
|
|
|
|
/**
|
2009-01-13 12:29:34 -05:00
|
|
|
Returns the current position or ::wxInvalidOffset if file is not opened or
|
2008-09-25 10:03:38 -04:00
|
|
|
if another error occurred.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxFileOffset Tell() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Write to the file, return @true on success, @false on failure.
|
|
|
|
The second argument is only meaningful in Unicode build of wxWidgets when
|
2008-03-09 08:33:59 -04:00
|
|
|
@a conv is used to convert @a str to multibyte representation.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Write(const wxString& str,
|
|
|
|
const wxMBConv& conv = wxConvUTF8);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFile
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A wxFile performs raw file I/O. This is a very small class designed to
|
|
|
|
minimize the overhead of using it - in fact, there is hardly any overhead at
|
|
|
|
all, but using it brings you automatic error checking and hides differences
|
|
|
|
between platforms and compilers. wxFile also automatically closes the file in
|
2008-11-22 09:20:28 -05:00
|
|
|
its destructor so you won't forget to do so.
|
2008-09-25 10:03:38 -04:00
|
|
|
wxFile is a wrapper around @c file descriptor. - see also wxFFile for a
|
|
|
|
wrapper around @c FILE structure.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 10:03:38 -04:00
|
|
|
::wxFileOffset is used by the wxFile functions which require offsets as
|
|
|
|
parameter or return them. If the platform supports it, wxFileOffset is a
|
|
|
|
typedef for a native 64 bit integer, otherwise a 32 bit integer is used for
|
|
|
|
::wxFileOffset.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{file}
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxFile
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
The OpenMode enumeration defines the different modes for opening a file with wxFile.
|
|
|
|
It is also used with wxFile::Access function.
|
2008-07-01 04:48:17 -04:00
|
|
|
*/
|
2008-09-25 10:03:38 -04:00
|
|
|
enum OpenMode {
|
|
|
|
|
|
|
|
/** Open file for reading or test if it can be opened for reading with Access() */
|
|
|
|
read,
|
|
|
|
|
|
|
|
/** Open file for writing deleting the contents of the file if it already exists
|
|
|
|
or test if it can be opened for writing with Access(). */
|
|
|
|
write,
|
|
|
|
|
2011-03-22 10:17:38 -04:00
|
|
|
/** Open file for reading and writing; cannot be used with Access() */
|
2008-09-25 10:03:38 -04:00
|
|
|
read_write,
|
|
|
|
|
|
|
|
/** Open file for appending: the file is opened for writing, but the old contents
|
2008-11-22 09:20:28 -05:00
|
|
|
of the file are not erased and the file pointer is initially placed at the end
|
2011-03-22 10:17:38 -04:00
|
|
|
of the file; cannot be used with Access().
|
2008-09-25 10:03:38 -04:00
|
|
|
|
|
|
|
This is the same as OpenMode::write if the file doesn't exist.
|
|
|
|
*/
|
|
|
|
write_append,
|
|
|
|
|
|
|
|
/**
|
|
|
|
Open the file securely for writing (Uses O_EXCL | O_CREAT).
|
|
|
|
Will fail if the file already exists, else create and open it atomically.
|
|
|
|
Useful for opening temporary files without being vulnerable to race exploits.
|
|
|
|
*/
|
|
|
|
write_excl
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2008-07-01 04:48:17 -04:00
|
|
|
Standard file descriptors
|
|
|
|
*/
|
|
|
|
enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr };
|
|
|
|
|
2008-09-25 10:03:38 -04:00
|
|
|
/**
|
2008-07-01 04:48:17 -04:00
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxFile();
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-07-01 04:48:17 -04:00
|
|
|
/**
|
|
|
|
Opens a file with a filename.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param filename
|
2008-03-09 08:33:59 -04:00
|
|
|
The filename.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param mode
|
2008-09-25 10:03:38 -04:00
|
|
|
The mode in which to open the file.
|
2009-01-10 17:10:54 -05:00
|
|
|
|
|
|
|
@warning
|
|
|
|
You should use IsOpened() to verify that the constructor succeeded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFile(const wxString& filename,
|
|
|
|
wxFile::OpenMode mode = wxFile::read);
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-07-01 04:48:17 -04:00
|
|
|
/**
|
|
|
|
Associates the file with the given file descriptor, which has already been
|
|
|
|
opened. See Attach() for the list of predefined descriptors.
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-07-01 04:48:17 -04:00
|
|
|
@param fd
|
2008-09-25 10:03:38 -04:00
|
|
|
An existing file descriptor.
|
2008-07-01 04:48:17 -04:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFile(int fd);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor will close the file.
|
2008-11-22 09:20:28 -05:00
|
|
|
@note This destructor is not virtual so you should not use wxFile polymorphically.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
~wxFile();
|
|
|
|
|
2010-11-14 07:09:59 -05:00
|
|
|
/**
|
|
|
|
Returns the error code for the last unsuccessful operation.
|
|
|
|
|
|
|
|
The error code is system-dependent and corresponds to the value of the
|
|
|
|
standard @c errno variable when the last error occurred.
|
|
|
|
|
|
|
|
Notice that only simple accessors such as IsOpened() and Eof() (and
|
|
|
|
this method itself) don't modify the last error value, all other
|
|
|
|
methods can potentially change it if an error occurs, including the
|
|
|
|
const ones such as Tell() or Length().
|
|
|
|
|
|
|
|
@since 2.9.2
|
|
|
|
|
|
|
|
@see ClearLastError()
|
|
|
|
*/
|
|
|
|
int GetLastError() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Resets the error code.
|
|
|
|
|
|
|
|
GetLastError() will return 0 until the next error occurs.
|
|
|
|
|
|
|
|
@since 2.9.2
|
|
|
|
*/
|
|
|
|
void ClearLastError();
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-07-01 04:48:17 -04:00
|
|
|
This function verifies if we may access the given file in specified mode.
|
|
|
|
Only values of @c wxFile::read or @c wxFile::write really make sense here.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-25 10:03:38 -04:00
|
|
|
static bool Access(const wxString& name, wxFile::OpenMode mode);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Attaches an existing file descriptor to the wxFile object.
|
2008-11-22 09:20:28 -05:00
|
|
|
Examples of predefined file descriptors are 0, 1 and 2 which correspond to
|
2008-09-25 10:03:38 -04:00
|
|
|
stdin, stdout and stderr (and have symbolic names of @c wxFile::fd_stdin,
|
2008-07-01 04:48:17 -04:00
|
|
|
@c wxFile::fd_stdout and @c wxFile::fd_stderr).
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The descriptor should be already opened and it will be closed by wxFile
|
|
|
|
object.
|
|
|
|
*/
|
|
|
|
void Attach(int fd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the file.
|
|
|
|
*/
|
2008-10-29 11:34:31 -04:00
|
|
|
bool Close();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Creates a file for writing.
|
|
|
|
|
|
|
|
If the file already exists, setting @b overwrite to @true will ensure
|
|
|
|
it is overwritten.
|
|
|
|
|
2008-09-27 06:27:44 -04:00
|
|
|
@a access may be an OR combination of the ::wxPosixPermissions enumeration
|
|
|
|
values.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-25 10:03:38 -04:00
|
|
|
bool Create(const wxString& filename,
|
|
|
|
bool overwrite = false,
|
2008-03-08 08:52:38 -05:00
|
|
|
int access = wxS_DEFAULT);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get back a file descriptor from wxFile object - the caller is responsible for
|
2008-09-25 10:03:38 -04:00
|
|
|
closing the file if this descriptor is opened.
|
|
|
|
IsOpened() will return @false after call to Detach().
|
2013-09-12 16:49:10 -04:00
|
|
|
|
|
|
|
@return The file descriptor (this is new since wxWidgets 3.0.0, in the
|
|
|
|
previous versions this method didn't return anything).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2013-09-12 16:49:10 -04:00
|
|
|
int Detach();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the end of the file has been reached.
|
2008-11-22 09:20:28 -05:00
|
|
|
Note that the behaviour of the file pointer-based class wxFFile is
|
2008-09-25 10:03:38 -04:00
|
|
|
different as wxFFile::Eof() will return @true here only if an
|
2008-07-01 04:48:17 -04:00
|
|
|
attempt has been made to read @b past the last byte of the file, while
|
|
|
|
wxFile::Eof() will return @true even before such attempt is made if the
|
|
|
|
file pointer is at the last position in the file.
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Note also that this function doesn't work on unseekable file descriptors
|
|
|
|
(examples include pipes, terminals and sockets under Unix) and an attempt to
|
2008-11-22 09:20:28 -05:00
|
|
|
use it will result in an error message.
|
2008-09-25 10:03:38 -04:00
|
|
|
|
|
|
|
So, to read the entire file into memory, you should write a loop which uses
|
|
|
|
Read() repeatedly and tests its return condition instead of using Eof()
|
|
|
|
as this will not work for special files under Unix.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool Eof() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Returns @true if the given name specifies an existing regular file
|
2008-11-22 09:20:28 -05:00
|
|
|
(not a directory or a link).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
static bool Exists(const wxString& filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Flushes the file descriptor.
|
2008-09-25 10:03:38 -04:00
|
|
|
|
|
|
|
Note that Flush() is not implemented on some Windows compilers due to a
|
|
|
|
missing fsync function, which reduces the usefulness of this function
|
2008-03-08 08:52:38 -05:00
|
|
|
(it can still be called but it will do nothing on unsupported compilers).
|
|
|
|
*/
|
|
|
|
bool Flush();
|
|
|
|
|
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Returns the type of the file.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxFileKind GetKind() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the file has been opened.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOpened() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the file.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxFileOffset Length() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Opens the file, returning @true if successful.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param filename
|
2008-03-09 08:33:59 -04:00
|
|
|
The filename.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param mode
|
2008-09-25 10:03:38 -04:00
|
|
|
The mode in which to open the file.
|
2008-09-27 06:27:44 -04:00
|
|
|
@param access
|
2009-01-05 13:24:05 -05:00
|
|
|
An OR-combination of ::wxPosixPermissions enumeration values.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-29 11:34:31 -04:00
|
|
|
bool Open(const wxString& filename, wxFile::OpenMode mode = wxFile::read,
|
2008-09-27 06:27:44 -04:00
|
|
|
int access = wxS_DEFAULT);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Reads from the file into a memory buffer.
|
|
|
|
|
2008-07-01 04:48:17 -04:00
|
|
|
@param buffer
|
|
|
|
Buffer to write in
|
|
|
|
@param count
|
2008-09-25 10:03:38 -04:00
|
|
|
Bytes to read
|
|
|
|
|
2009-01-13 12:29:34 -05:00
|
|
|
@return The number of bytes read, or the symbol ::wxInvalidOffset.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-29 11:34:31 -04:00
|
|
|
ssize_t Read(void* buffer, size_t count);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2012-09-30 18:28:08 -04:00
|
|
|
/**
|
|
|
|
Reads the entire contents of the file into a string.
|
|
|
|
|
2017-12-15 12:34:43 -05:00
|
|
|
Since wxWidgets 3.1.1 this method also works for unseekable files.
|
|
|
|
|
2012-09-30 18:28:08 -04:00
|
|
|
@param str
|
|
|
|
Non-@NULL pointer to a string to read data into.
|
|
|
|
@param conv
|
|
|
|
Conversion object to use in Unicode build; by default supposes
|
|
|
|
that file contents is encoded in UTF-8 but falls back to the
|
|
|
|
current locale encoding (or Latin-1 if it is UTF-8 too) if it is
|
|
|
|
not.
|
|
|
|
|
|
|
|
@return @true if file was read successfully, @false otherwise.
|
|
|
|
|
|
|
|
@since 2.9.5
|
|
|
|
*/
|
|
|
|
bool ReadAll(wxString* str, const wxMBConv& conv = wxConvAuto());
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Seeks to the specified position.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param ofs
|
2008-03-09 08:33:59 -04:00
|
|
|
Offset to seek to.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param mode
|
2008-03-09 08:33:59 -04:00
|
|
|
One of wxFromStart, wxFromEnd, wxFromCurrent.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 12:29:34 -05:00
|
|
|
@return The actual offset position achieved, or ::wxInvalidOffset on
|
2008-09-25 10:03:38 -04:00
|
|
|
failure.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFileOffset Seek(wxFileOffset ofs,
|
|
|
|
wxSeekMode mode = wxFromStart);
|
|
|
|
|
|
|
|
/**
|
2008-09-25 10:03:38 -04:00
|
|
|
Moves the file pointer to the specified number of bytes relative to the
|
|
|
|
end of the file. For example, @c SeekEnd(-5) would position the pointer 5
|
2008-03-08 08:52:38 -05:00
|
|
|
bytes before the end.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param ofs
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of bytes before the end of the file.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-01-13 12:29:34 -05:00
|
|
|
@return The actual offset position achieved, or ::wxInvalidOffset on
|
2008-09-25 10:03:38 -04:00
|
|
|
failure.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFileOffset SeekEnd(wxFileOffset ofs = 0);
|
|
|
|
|
|
|
|
/**
|
2009-01-13 12:29:34 -05:00
|
|
|
Returns the current position or ::wxInvalidOffset if file is not opened or
|
2008-09-25 10:03:38 -04:00
|
|
|
if another error occurred.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxFileOffset Tell() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-07-01 04:48:17 -04:00
|
|
|
/**
|
|
|
|
Write data to the file (descriptor).
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-08-27 00:20:07 -04:00
|
|
|
@param buffer
|
2008-07-01 04:48:17 -04:00
|
|
|
Buffer from which to read data
|
|
|
|
@param count
|
|
|
|
Number of bytes to write
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-07-01 04:48:17 -04:00
|
|
|
@return The number of bytes written.
|
|
|
|
*/
|
|
|
|
size_t Write(const void *buffer, size_t count);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Writes the contents of the string to the file, returns @true on success.
|
|
|
|
The second argument is only meaningful in Unicode build of wxWidgets when
|
2008-07-01 04:48:17 -04:00
|
|
|
@a conv is used to convert @a s to a multibyte representation.
|
2008-09-25 10:03:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that this method only works with @c NUL-terminated strings, if you want
|
2008-03-08 09:43:31 -05:00
|
|
|
to write data with embedded @c NULs to the file you should use the other
|
2008-07-01 04:48:17 -04:00
|
|
|
Write() overload.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2020-02-21 08:30:43 -05:00
|
|
|
bool Write(const wxString& s, const wxMBConv& conv = wxConvAuto());
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the file descriptor associated with the file.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
int fd() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|