win32 compile fixes

This commit is contained in:
Kelvin Sherlock 2017-03-04 21:39:04 -05:00
parent f1d906d156
commit f51444e31d
3 changed files with 37 additions and 10 deletions

View File

@ -6,15 +6,21 @@
#include <system_error> #include <system_error>
#include <string> #include <string>
#include <vector> #include <vector>
#include <unistd.h> #include <unistd.h>
#include <sysexits.h>
#include <stdio.h> #include <stdio.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
#include "win.h"
#else
#include <err.h>
#include <sysexits.h>
#endif
#include "mapped_file.h" #include "mapped_file.h"
#include "xattr.h" #include "xattr.h"
@ -42,7 +48,7 @@
void usage() { void usage() {
fputs("Usage: applesingle [-hv] [-o outfile] file ...\n", stderr); fputs("Usage: appledouble [-hv] [-o outfile] file ...\n", stderr);
exit(EX_USAGE); exit(EX_USAGE);
} }
@ -107,7 +113,7 @@ std::vector<uint8_t> read_resource_fork(const std::string &path, std::error_code
rv.resize(ok); rv.resize(ok);
break; break;
} }
close fd; close(fd);
return rv; return rv;
#else #else

View File

@ -6,15 +6,21 @@
#include <system_error> #include <system_error>
#include <string> #include <string>
#include <vector> #include <vector>
#include <unistd.h> #include <unistd.h>
#include <sysexits.h>
#include <stdio.h> #include <stdio.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
#include "win.h"
#else
#include <err.h>
#include <sysexits.h>
#endif
#include "mapped_file.h" #include "mapped_file.h"
#include "xattr.h" #include "xattr.h"
@ -107,7 +113,7 @@ std::vector<uint8_t> read_resource_fork(const std::string &path, std::error_code
rv.resize(ok); rv.resize(ok);
break; break;
} }
close fd; close(fd);
return rv; return rv;
#else #else

17
win.h
View File

@ -1,10 +1,14 @@
#ifdef __GNUC__ #ifdef __GNUC__
#define ntohl __builtin_bswap32 #define ntohl __builtin_bswap32
#define ntohs __builtin_bswap16 #define ntohs __builtin_bswap16
#define htonl __builtin_bswap32
#define htons __builtin_bswap16
#else #else
#define ntohl _byteswap_ulong #define ntohl _byteswap_ulong
#define ntohs _byteswap_ushort #define ntohs _byteswap_ushort
#define htonl _byteswap_ulong
#define htons _byteswap_ushort
#endif #endif
#define EX_OK 0 /* successful termination */ #define EX_OK 0 /* successful termination */
@ -30,9 +34,20 @@
#define EX__MAX 78 /* maximum listed value */ #define EX__MAX 78 /* maximum listed value */
#define warn(...) do { \ #define warn(...) do { \
char *cp = strerror(errno); \
fputs("dot_clean: ", stderr); \ fputs("dot_clean: ", stderr); \
fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, __VA_ARGS__); \
perror(NULL); \ fprintf(stderr,": %s", cp); \
} while(0) } while(0)
#define warnx(...) do { \
fputs("dot_clean: ", stderr); \
fprintf(stderr, __VA_ARGS__); \
} while(0)
#define warnc(ec, ...) do { \
char *cp = strerror(ec); \
fputs("dot_clean: ", stderr); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr,": %s", cp); \
} while(0)