linenoise: Update for optimised insert
[jimtcl.git] / jimiocompat.h
blob2cbb578e16251ab853f55abee3270245811c30cc
1 #ifndef JIMIOCOMPAT_H
2 #define JIMIOCOMPAT_H
4 /*
5 * Cross-platform compatibility functions and types for I/O.
6 * Currently used by jim-aio.c and jim-exec.c
7 */
9 #include <stdio.h>
10 #include <errno.h>
12 #include "jimautoconf.h"
13 #include <jim.h>
14 #include <jim-win32compat.h>
16 /**
17 * Set an error result based on errno and the given message.
19 void Jim_SetResultErrno(Jim_Interp *interp, const char *msg);
21 /**
22 * Opens the file for writing (and appending if append is true).
23 * Returns the file descriptor, or -1 on failure.
25 int Jim_OpenForWrite(const char *filename, int append);
27 /**
28 * Opens the file for reading.
29 * Returns the file descriptor, or -1 on failure.
31 int Jim_OpenForRead(const char *filename);
33 #if defined(__MINGW32__)
34 #ifndef STRICT
35 #define STRICT
36 #endif
37 #define WIN32_LEAN_AND_MEAN
38 #include <windows.h>
39 #include <fcntl.h>
40 #include <io.h>
41 #include <process.h>
43 typedef HANDLE pidtype;
44 #define JIM_BAD_PID INVALID_HANDLE_VALUE
45 /* Note that this isn't a separate value on Windows since we don't have os.fork */
46 #define JIM_NO_PID INVALID_HANDLE_VALUE
48 /* These seem to accord with the conventions used by msys/mingw32 */
49 #define WIFEXITED(STATUS) (((STATUS) & 0xff00) == 0)
50 #define WEXITSTATUS(STATUS) ((STATUS) & 0x00ff)
51 #define WIFSIGNALED(STATUS) (((STATUS) & 0xff00) != 0)
52 #define WTERMSIG(STATUS) (((STATUS) >> 8) & 0xff)
53 #define WNOHANG 1
55 /**
56 * Unix-compatible errno
58 int Jim_Errno(void);
59 pidtype waitpid(pidtype pid, int *status, int nohang);
61 #define HAVE_PIPE
62 #define pipe(P) _pipe((P), 0, O_NOINHERIT)
64 #elif defined(HAVE_UNISTD_H)
65 #include <unistd.h>
66 #include <fcntl.h>
67 #include <sys/wait.h>
68 #include <sys/stat.h>
70 typedef int pidtype;
71 #define Jim_Errno() errno
72 #define JIM_BAD_PID -1
73 #define JIM_NO_PID 0
75 #ifndef HAVE_EXECVPE
76 #define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
77 #endif
78 #endif
80 #endif