2013-02-25 22:47:58 +00:00
|
|
|
#ifndef __mpw_os_internal_h__
|
|
|
|
#define __mpw_os_internal_h__
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <string>
|
2015-02-17 00:23:12 +00:00
|
|
|
#include <sys/types.h>
|
2013-02-25 22:47:58 +00:00
|
|
|
|
2016-07-29 19:10:20 +00:00
|
|
|
namespace OS {
|
|
|
|
|
|
|
|
std::string realpath(const std::string &path);
|
|
|
|
|
|
|
|
namespace Internal {
|
2013-02-25 22:47:58 +00:00
|
|
|
|
2016-07-31 19:35:30 +00:00
|
|
|
|
2013-03-04 03:07:25 +00:00
|
|
|
int32_t mac_seek(uint16_t refNum, uint16_t mode, int32_t offset);
|
|
|
|
|
2016-07-29 19:10:20 +00:00
|
|
|
|
|
|
|
|
2013-02-25 22:47:58 +00:00
|
|
|
struct FDEntry
|
|
|
|
{
|
|
|
|
int refcount;
|
|
|
|
bool text;
|
|
|
|
bool resource;
|
|
|
|
|
2013-02-26 01:16:55 +00:00
|
|
|
std::string filename;
|
2013-02-25 22:47:58 +00:00
|
|
|
|
|
|
|
FDEntry() :
|
2015-02-18 14:32:01 +00:00
|
|
|
refcount(0),
|
|
|
|
text(false),
|
2013-02-25 22:47:58 +00:00
|
|
|
resource(false)
|
|
|
|
{}
|
2013-02-26 01:16:55 +00:00
|
|
|
|
|
|
|
static std::deque<FDEntry> FDTable;
|
|
|
|
|
|
|
|
static FDEntry& allocate(int fd);
|
|
|
|
static FDEntry& allocate(int fd, std::string &&filename);
|
|
|
|
static FDEntry& allocate(int fd, const std::string &filename);
|
|
|
|
|
|
|
|
static ssize_t read(int fd, void *buffer, size_t count);
|
|
|
|
static ssize_t write(int fd, const void *buffer, size_t count);
|
|
|
|
|
2013-02-26 01:40:28 +00:00
|
|
|
static int close(int fd, bool force = false);
|
|
|
|
|
2013-05-19 01:24:49 +00:00
|
|
|
static int open(const std::string &filename, int permission, int fork);
|
|
|
|
|
2013-02-26 01:16:55 +00:00
|
|
|
|
|
|
|
template<class F1, class F2>
|
|
|
|
static int32_t action(int fd, F1 good, F2 bad)
|
|
|
|
{
|
|
|
|
if (fd < 0 || fd >= FDTable.size())
|
|
|
|
{
|
|
|
|
return bad(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &e = FDTable[fd];
|
|
|
|
if (e.refcount)
|
|
|
|
{
|
|
|
|
return good(fd, e);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return bad(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-02-25 22:47:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
|
|
|
#endif
|