2010-03-15 03:05:48 +00:00
|
|
|
#ifndef __FILE_H__
|
|
|
|
#define __FILE_H__
|
|
|
|
|
2010-05-21 18:51:00 +00:00
|
|
|
#include <new>
|
|
|
|
|
2010-03-17 03:42:27 +00:00
|
|
|
#include <sys/types.h>
|
2010-03-15 03:05:48 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2010-05-29 19:29:59 +00:00
|
|
|
|
2010-03-17 03:42:27 +00:00
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
class File {
|
|
|
|
|
|
|
|
public:
|
2010-05-29 19:29:59 +00:00
|
|
|
|
|
|
|
enum FileFlags {
|
|
|
|
ReadOnly = 1,
|
|
|
|
ReadWrite = 2
|
|
|
|
};
|
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
File();
|
|
|
|
File(File &);
|
|
|
|
File(int fd);
|
2010-05-21 18:51:00 +00:00
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
File(const char *name, int flags);
|
2010-05-26 02:03:29 +00:00
|
|
|
File(const char *name, int flags, mode_t mode);
|
2010-05-29 19:29:59 +00:00
|
|
|
File(const char *name, FileFlags flags);
|
2010-05-21 18:51:00 +00:00
|
|
|
|
|
|
|
File(const char *name, int flags, const std::nothrow_t &);
|
2010-05-26 02:03:29 +00:00
|
|
|
File(const char *name, int flags, mode_t mode, const std::nothrow_t &);
|
2010-05-29 19:29:59 +00:00
|
|
|
File(const char *name, FileFlags flags, const std::nothrow_t &);
|
2010-05-21 18:51:00 +00:00
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
~File();
|
|
|
|
|
2010-05-18 02:58:26 +00:00
|
|
|
bool isValid() const
|
|
|
|
{
|
|
|
|
return _fd >= 0;
|
|
|
|
}
|
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
int fd() const { return _fd; }
|
2010-05-18 02:58:26 +00:00
|
|
|
|
2010-05-31 00:07:02 +00:00
|
|
|
int release();
|
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
void close();
|
2010-03-17 03:42:27 +00:00
|
|
|
|
|
|
|
void adopt(File &f);
|
2010-05-19 23:47:32 +00:00
|
|
|
void adopt(int fd);
|
|
|
|
|
2010-03-17 03:42:27 +00:00
|
|
|
void swap(File &f);
|
2010-03-15 03:05:48 +00:00
|
|
|
|
|
|
|
private:
|
2010-03-17 03:42:27 +00:00
|
|
|
|
|
|
|
// could call dup() or something.
|
|
|
|
File& operator=(const File &f);
|
2010-03-15 03:05:48 +00:00
|
|
|
int _fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|