win32 updates.
This commit is contained in:
parent
e7c146c19d
commit
dc26edee3f
|
@ -0,0 +1,2 @@
|
||||||
|
*.o
|
||||||
|
*.exe
|
|
@ -12,15 +12,24 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "win.h"
|
||||||
|
#else
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sysexits.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
#include <sysexits.h>
|
|
||||||
|
|
||||||
#include "applefile.h"
|
#include "applefile.h"
|
||||||
#include "mapped_file.h"
|
#include "mapped_file.h"
|
||||||
|
@ -42,7 +51,7 @@ struct AFP_Info {
|
||||||
uint32_t prodos_aux_type;
|
uint32_t prodos_aux_type;
|
||||||
uint8_t reserved[6];
|
uint8_t reserved[6];
|
||||||
};
|
};
|
||||||
#pragma pack pop
|
#pragma pack(pop)
|
||||||
|
|
||||||
void init_afp_info(AFP_Info &info) {
|
void init_afp_info(AFP_Info &info) {
|
||||||
static_assert(sizeof(AFP_Info) == 60, "Incorrect AFP_Info size");
|
static_assert(sizeof(AFP_Info) == 60, "Incorrect AFP_Info size");
|
||||||
|
@ -53,6 +62,11 @@ void init_afp_info(AFP_Info &info) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef O_BINARY
|
||||||
|
#define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> unlink_list;
|
std::vector<std::string> unlink_list;
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,19 +111,19 @@ void one_file(const std::string &data, const std::string &rsrc) noexcept try {
|
||||||
|
|
||||||
if (_v) fprintf(stdout, "Merging %s & %s\n", rsrc.c_str(), data.c_str());
|
if (_v) fprintf(stdout, "Merging %s & %s\n", rsrc.c_str(), data.c_str());
|
||||||
|
|
||||||
int fd = open(data.c_str(), O_RDONLY);
|
int fd = open(data.c_str(), O_RDONLY | O_BINARY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
if (_n) unlink_list.push_back(rsrc);
|
if (_n) unlink_list.push_back(rsrc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw_errno();
|
throw_errno("open");
|
||||||
}
|
}
|
||||||
defer close_fd([fd]{close(fd); });
|
defer close_fd([fd]{close(fd); });
|
||||||
|
|
||||||
|
|
||||||
if (stat(rsrc.c_str(), &rsrc_st) < 0) throw_errno();
|
if (stat(rsrc.c_str(), &rsrc_st) < 0) throw_errno("stat");
|
||||||
if (rsrc_st.st_size == 0) {
|
if (rsrc_st.st_size == 0) {
|
||||||
// mmapping a zero-length file throws EINVAL.
|
// mmapping a zero-length file throws EINVAL.
|
||||||
if (!_p) unlink_list.push_back(rsrc);
|
if (!_p) unlink_list.push_back(rsrc);
|
||||||
|
@ -154,7 +168,7 @@ void one_file(const std::string &data, const std::string &rsrc) noexcept try {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
std::for_each(begin, end, [&mf,fd](ASEntry &e){
|
std::for_each(begin, end, [&](ASEntry &e){
|
||||||
|
|
||||||
if (e.entryLength == 0) return;
|
if (e.entryLength == 0) return;
|
||||||
switch(e.entryID) {
|
switch(e.entryID) {
|
||||||
|
@ -181,7 +195,7 @@ void one_file(const std::string &data, const std::string &rsrc) noexcept try {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::string tmp = data + ":AFP_Resource";
|
std::string tmp = data + ":AFP_Resource";
|
||||||
int rfd = open(tmp.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
int rfd = open(tmp.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
|
||||||
if (rfd < 0) throw_errno("com.apple.ResourceFork");
|
if (rfd < 0) throw_errno("com.apple.ResourceFork");
|
||||||
defer close_fd([rfd](){ close(rfd); });
|
defer close_fd([rfd](){ close(rfd); });
|
||||||
int ok = write(rfd, mf.data() + e.entryOffset, e.entryLength);
|
int ok = write(rfd, mf.data() + e.entryOffset, e.entryLength);
|
||||||
|
@ -217,7 +231,7 @@ void one_file(const std::string &data, const std::string &rsrc) noexcept try {
|
||||||
memcpy(info.finder_info, mf.data() + e.entryOffset, 32);
|
memcpy(info.finder_info, mf.data() + e.entryOffset, 32);
|
||||||
|
|
||||||
std::string tmp = data + ":AFP_AfpInfo";
|
std::string tmp = data + ":AFP_AfpInfo";
|
||||||
int rfd = openat(tmp.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666);
|
int rfd = open(tmp.c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666);
|
||||||
if (rfd < 0) throw_errno("AFP_AfpInfo");
|
if (rfd < 0) throw_errno("AFP_AfpInfo");
|
||||||
defer close_fd([rfd](){ close(rfd); });
|
defer close_fd([rfd](){ close(rfd); });
|
||||||
|
|
||||||
|
@ -232,6 +246,7 @@ void one_file(const std::string &data, const std::string &rsrc) noexcept try {
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case AS_PRODOSINFO: {
|
case AS_PRODOSINFO: {
|
||||||
if (e.entryLength != 8) {
|
if (e.entryLength != 8) {
|
||||||
|
|
|
@ -65,13 +65,12 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
||||||
nullptr
|
nullptr
|
||||||
);
|
);
|
||||||
if (fh == INVALID_HANDLE_VALUE) {
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
throw_error();
|
throw_error("CreateFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fh_close = make_unique_resource(fh, CloseHandle);
|
auto fh_close = make_unique_resource(fh, CloseHandle);
|
||||||
|
|
||||||
|
if (length == -1) {
|
||||||
if (length == -1){
|
|
||||||
LARGE_INTEGER file_size;
|
LARGE_INTEGER file_size;
|
||||||
GetFileSizeEx(fh, &file_size);
|
GetFileSizeEx(fh, &file_size);
|
||||||
length = file_size.QuadPart;
|
length = file_size.QuadPart;
|
||||||
|
@ -90,13 +89,13 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
||||||
break;
|
break;
|
||||||
case priv:
|
case priv:
|
||||||
protect = PAGE_WRITECOPY;
|
protect = PAGE_WRITECOPY;
|
||||||
access = FILE_MAP_WRITE;
|
access = FILE_MAP_COPY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0);
|
mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0);
|
||||||
if (mh == INVALID_HANDLE_VALUE) {
|
if (mh == INVALID_HANDLE_VALUE) {
|
||||||
throw_error();
|
throw_error("CreateFileMapping");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mh_close = make_unique_resource(mh, CloseHandle);
|
auto mh_close = make_unique_resource(mh, CloseHandle);
|
||||||
|
@ -109,7 +108,7 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
||||||
length,
|
length,
|
||||||
nullptr);
|
nullptr);
|
||||||
if (!_data) {
|
if (!_data) {
|
||||||
throw_error();
|
throw_error("MapViewOfFileEx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,7 +145,7 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
nullptr
|
nullptr
|
||||||
);
|
);
|
||||||
if (fh == INVALID_HANDLE_VALUE) {
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
throw_error();
|
throw_error("CreateFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fh_close = make_unique_resource(fh, CloseHandle);
|
auto fh_close = make_unique_resource(fh, CloseHandle);
|
||||||
|
@ -154,11 +153,11 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
|
|
||||||
file_size.QuadPart = length;
|
file_size.QuadPart = length;
|
||||||
if (!SetFilePointerEx(fh, file_size, nullptr, FILE_BEGIN));
|
if (!SetFilePointerEx(fh, file_size, nullptr, FILE_BEGIN));
|
||||||
if (!SetEndOfFile(fh)) throw_error();
|
if (!SetEndOfFile(fh)) throw_error("SetEndOfFile");
|
||||||
|
|
||||||
mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0);
|
mh = CreateFileMapping(fh, nullptr, protect, 0, 0, 0);
|
||||||
if (mh == INVALID_HANDLE_VALUE) {
|
if (mh == INVALID_HANDLE_VALUE) {
|
||||||
throw_error();
|
throw_error("CreateFileMapping");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mh_close = make_unique_resource(mh, CloseHandle);
|
auto mh_close = make_unique_resource(mh, CloseHandle);
|
||||||
|
@ -171,7 +170,7 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
if (!_data) {
|
if (!_data) {
|
||||||
throw_error();
|
throw_error("MapViewOfFileEx");
|
||||||
}
|
}
|
||||||
|
|
||||||
_file_handle = fh_close.release();
|
_file_handle = fh_close.release();
|
||||||
|
@ -256,7 +255,7 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
||||||
|
|
||||||
if (_data == MAP_FAILED) {
|
if (_data == MAP_FAILED) {
|
||||||
_data = nullptr;
|
_data = nullptr;
|
||||||
throw_error(errno);
|
throw_error(errno, "mmap");
|
||||||
}
|
}
|
||||||
|
|
||||||
_fd = close_fd.release();
|
_fd = close_fd.release();
|
||||||
|
@ -277,7 +276,7 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
|
|
||||||
fd = ::open(p.c_str(), O_RDWR | O_CREAT | O_TRUNC);
|
fd = ::open(p.c_str(), O_RDWR | O_CREAT | O_TRUNC);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
throw_error(errno);
|
throw_error(errno, "open");
|
||||||
}
|
}
|
||||||
|
|
||||||
//defer([fd](){::close(fd); });
|
//defer([fd](){::close(fd); });
|
||||||
|
@ -286,7 +285,7 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
|
|
||||||
|
|
||||||
if (::ftruncate(fd, length) < 0) {
|
if (::ftruncate(fd, length) < 0) {
|
||||||
throw_error(errno);
|
throw_error(errno, "ftruncate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -297,7 +296,7 @@ void mapped_file_base::create(const path_type& p, size_t length) {
|
||||||
|
|
||||||
if (_data == MAP_FAILED) {
|
if (_data == MAP_FAILED) {
|
||||||
_data = nullptr;
|
_data = nullptr;
|
||||||
throw_error(errno);
|
throw_error(errno, "mmap");
|
||||||
}
|
}
|
||||||
|
|
||||||
_fd = close_fd.release();
|
_fd = close_fd.release();
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define ntohl __builtin_bswap32
|
||||||
|
#define ntohs __builtin_bswap16
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define ntohl _byteswap_ulong
|
||||||
|
#define ntohs _byteswap_ushort
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define EX_OK 0 /* successful termination */
|
||||||
|
|
||||||
|
#define EX__BASE 64 /* base value for error messages */
|
||||||
|
|
||||||
|
#define EX_USAGE 64 /* command line usage error */
|
||||||
|
#define EX_DATAERR 65 /* data format error */
|
||||||
|
#define EX_NOINPUT 66 /* cannot open input */
|
||||||
|
#define EX_NOUSER 67 /* addressee unknown */
|
||||||
|
#define EX_NOHOST 68 /* host name unknown */
|
||||||
|
#define EX_UNAVAILABLE 69 /* service unavailable */
|
||||||
|
#define EX_SOFTWARE 70 /* internal software error */
|
||||||
|
#define EX_OSERR 71 /* system error (e.g., can't fork) */
|
||||||
|
#define EX_OSFILE 72 /* critical OS file missing */
|
||||||
|
#define EX_CANTCREAT 73 /* can't create (user) output file */
|
||||||
|
#define EX_IOERR 74 /* input/output error */
|
||||||
|
#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
|
||||||
|
#define EX_PROTOCOL 76 /* remote error in protocol */
|
||||||
|
#define EX_NOPERM 77 /* permission denied */
|
||||||
|
#define EX_CONFIG 78 /* configuration error */
|
||||||
|
|
||||||
|
#define EX__MAX 78 /* maximum listed value */
|
||||||
|
|
||||||
|
#define warn(...) do { \
|
||||||
|
fputs("dot_clean: ", stderr); \
|
||||||
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
perror(NULL); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue