mpw/toolbox/os_internal.h

69 lines
1.3 KiB
C
Raw Normal View History

2013-02-25 17:47:58 -05:00
#ifndef __mpw_os_internal_h__
#define __mpw_os_internal_h__
#include <deque>
#include <string>
namespace OS { namespace Internal {
2013-02-28 18:58:17 -05:00
uint16_t errno_to_oserr(int xerrno);
2013-02-25 17:47:58 -05:00
2013-03-02 17:41:46 -05:00
uint16_t GetFinderInfo(const std::string &pathname, void *info);
uint16_t SetFinderInfo(const std::string &pathname, void *info);
uint16_t GetFileType(const std::string &pathname, uint16_t *fileType, uint32_t *auxType);
2013-03-03 22:07:25 -05:00
int32_t mac_seek(uint16_t refNum, uint16_t mode, int32_t offset);
2013-02-25 17:47:58 -05:00
struct FDEntry
{
int refcount;
bool text;
bool resource;
2013-02-25 20:16:55 -05:00
std::string filename;
2013-02-25 17:47:58 -05:00
FDEntry() :
refcount(0),
text(false),
resource(false)
{}
2013-02-25 20:16:55 -05: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-25 20:40:28 -05:00
static int close(int fd, bool force = false);
2013-02-25 20:16:55 -05: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 17:47:58 -05:00
};
} }
#endif