Commit 669469ca authored by Harris Hancock's avatar Harris Hancock

Depend on kj/miniposix.h instead of unistd.h in most places

This is necessary to get things working in MSVC. Note I swapped unistd.h
for miniposix.h in the compiler, too, which will be necessary to port the
compiler to MSVC.

This commit also pulls capnp/compiler/capnp.c++'s pipe() implementation
details (i.e., 8k reserved memory, _O_BINARY mode) into kj/miniposix.h.
parent 4b17e438
......@@ -28,7 +28,7 @@
#include <capnp/schema.capnp.h>
#include <kj/vector.h>
#include <kj/io.h>
#include <unistd.h>
#include <kj/miniposix.h>
#include <kj/debug.h>
#include "../message.h"
#include <iostream>
......@@ -43,9 +43,6 @@
#if _WIN32
#include <process.h>
#include <io.h>
#include <fcntl.h>
#define pipe(fds) _pipe(fds, 8192, _O_BINARY)
#else
#include <sys/wait.h>
#endif
......@@ -447,7 +444,7 @@ public:
}
int pipeFds[2];
KJ_SYSCALL(pipe(pipeFds));
KJ_SYSCALL(kj::miniposix::pipe(pipeFds));
kj::String exeName;
bool shouldSearchPath = true;
......
......@@ -30,7 +30,7 @@
#include <kj/vector.h>
#include "../schema-loader.h"
#include "../dynamic.h"
#include <unistd.h>
#include <kj/miniposix.h>
#include <unordered_map>
#include <unordered_set>
#include <map>
......@@ -50,10 +50,6 @@
#define VERSION "(unknown)"
#endif
#if _WIN32
#define mkdir(path, mode) mkdir(path)
#endif
namespace capnp {
namespace {
......@@ -2917,7 +2913,7 @@ private:
makeDirectory(kj::str(path.slice(0, *slashpos)));
}
if (mkdir(path.cStr(), 0777) < 0) {
if (kj::miniposix::mkdir(path.cStr(), 0777) < 0) {
int error = errno;
if (error != EEXIST) {
KJ_FAIL_SYSCALL("mkdir(path)", error, path);
......
......@@ -30,7 +30,7 @@
#include <kj/vector.h>
#include "../schema-loader.h"
#include "../dynamic.h"
#include <unistd.h>
#include <kj/miniposix.h>
#include <unordered_map>
#include <kj/main.h>
#include <algorithm>
......
......@@ -37,7 +37,7 @@
#include <time.h>
#include <kj/main.h>
#include <kj/io.h>
#include <unistd.h>
#include <kj/miniposix.h>
namespace capnp {
namespace compiler {
......
......@@ -28,7 +28,7 @@
#include <kj/io.h>
#include <capnp/message.h>
#include <map>
#include <unistd.h>
#include <kj/miniposix.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
......@@ -99,7 +99,7 @@ kj::Array<const byte> mmapForRead(kj::StringPtr filename) {
byte buffer[4096];
for (;;) {
ssize_t n;
kj::miniposix::ssize_t n;
KJ_SYSCALL(n = read(fd, buffer, sizeof(buffer)));
if (n == 0) break;
data.addAll(buffer, buffer + n);
......
......@@ -25,7 +25,7 @@
#include "serialize.h"
#include <kj/test.h>
#include <stdlib.h>
#include <unistd.h>
#include <kj/miniposix.h>
#include "test-util.h"
namespace capnp {
......
......@@ -31,7 +31,7 @@
#include <kj/vector.h>
#include <kj/debug.h>
#include <kj/io.h>
#include <unistd.h>
#include <kj/miniposix.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
......@@ -400,7 +400,7 @@ kj::Array<const char> SchemaFile::DiskFileReader::read(kj::StringPtr path) const
char buffer[4096];
for (;;) {
ssize_t n;
kj::miniposix::ssize_t n;
KJ_SYSCALL(n = ::read(fd, buffer, sizeof(buffer)));
if (n == 0) break;
data.addAll(buffer, buffer + n);
......
......@@ -22,17 +22,15 @@
#include "main.h"
#include "debug.h"
#include "arena.h"
#include "miniposix.h"
#include <map>
#include <set>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#if _WIN32
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#else
#include <sys/uio.h>
#endif
......
......@@ -19,8 +19,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef KJ_PORTABLE_FD_H_
#define KJ_PORTABLE_FD_H_
#ifndef KJ_MINIPOSIX_H_
#define KJ_MINIPOSIX_H_
// This header provides a small subset of the POSIX API which also happens to be available on
// Windows under slightly-different names.
......@@ -32,6 +32,7 @@
#if _WIN32
#include <io.h>
#include <direct.h>
#include <fcntl.h> // _O_BINARY
#else
#include <limits.h>
#include <errno.h>
......@@ -61,6 +62,17 @@ inline int close(int fd) {
return ::_close(fd);
}
#ifndef F_OK
#define F_OK 0 // access() existence test
#endif
#ifndef S_ISREG
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) // stat() regular file test
#endif
#ifndef S_ISDIR
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) // stat() directory test
#endif
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
......@@ -85,7 +97,7 @@ using ::close;
// We're on Windows, including MinGW. pipe() and mkdir() are non-standard even on MinGW.
inline int pipe(int fds[2]) {
return ::_pipe(fds, 4096, false);
return ::_pipe(fds, 8192, _O_BINARY);
}
inline int mkdir(const char* path, int mode) {
return ::_mkdir(path);
......@@ -133,4 +145,4 @@ inline size_t iovMax(size_t count) {
} // namespace miniposix
} // namespace kj
#endif // KJ_WIN32_FD_H_
#endif // KJ_MINIPOSIX_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment