diff options
author | Steve Bennett <steveb@workware.net.au> | 2016-09-14 14:15:47 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-10-17 07:39:39 +1000 |
commit | 1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5 (patch) | |
tree | 78c2baa61687fa296dc418cd1b978b3e046813f6 /jimiocompat.h | |
parent | 4be55f10c4d2071f493b9a1b60197c5e20f3203d (diff) | |
download | jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.zip jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.tar.gz jimtcl-1fd4fb6a645fa107d644f1ca0a0a8d7aa702e1d5.tar.bz2 |
signal, exec, wait, pid: improvements, especially to exec
- fix popen [open "|pipeline ..."] to return meaningful status in close
(but note that stderr is not captured)
- popen pipelines can now be used as the target of exec redirection
- overally improvements to exec on windows. Now crt file descriptors
are used throughout
- add support for [pid], [wait] and popen on windows
- os.wait is now wait, and integrates with [exec ... &] to be able
to wait for running background tasks
- [socket pipe] is now also [pipe] and is supported on windows
- [file tempfile] is supported on windows
- move duplicated code between jim-aio.c and jim-exec.c to jimiocompat.c
- Fix [exec] on windows to match unix semantics wrt sharing the parent stream
unless redirected rather than using /dev/null
- On windows redirect to or from /dev/null is automatically converted to NUL:
- If signal support is disabled, implement a minimal Jim_SignalId() for exec and wait
- aio now supports getfd, to return the underlying file descriptor.
This is used by exec to support redirection, and allows popen channels
to support exec redirection.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jimiocompat.h')
-rw-r--r-- | jimiocompat.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/jimiocompat.h b/jimiocompat.h new file mode 100644 index 0000000..2cbb578 --- /dev/null +++ b/jimiocompat.h @@ -0,0 +1,80 @@ +#ifndef JIMIOCOMPAT_H +#define JIMIOCOMPAT_H + +/* + * Cross-platform compatibility functions and types for I/O. + * Currently used by jim-aio.c and jim-exec.c + */ + +#include <stdio.h> +#include <errno.h> + +#include "jimautoconf.h" +#include <jim.h> +#include <jim-win32compat.h> + +/** + * Set an error result based on errno and the given message. + */ +void Jim_SetResultErrno(Jim_Interp *interp, const char *msg); + +/** + * Opens the file for writing (and appending if append is true). + * Returns the file descriptor, or -1 on failure. + */ +int Jim_OpenForWrite(const char *filename, int append); + +/** + * Opens the file for reading. + * Returns the file descriptor, or -1 on failure. + */ +int Jim_OpenForRead(const char *filename); + +#if defined(__MINGW32__) + #ifndef STRICT + #define STRICT + #endif + #define WIN32_LEAN_AND_MEAN + #include <windows.h> + #include <fcntl.h> + #include <io.h> + #include <process.h> + + typedef HANDLE pidtype; + #define JIM_BAD_PID INVALID_HANDLE_VALUE + /* Note that this isn't a separate value on Windows since we don't have os.fork */ + #define JIM_NO_PID INVALID_HANDLE_VALUE + + /* These seem to accord with the conventions used by msys/mingw32 */ + #define WIFEXITED(STATUS) (((STATUS) & 0xff00) == 0) + #define WEXITSTATUS(STATUS) ((STATUS) & 0x00ff) + #define WIFSIGNALED(STATUS) (((STATUS) & 0xff00) != 0) + #define WTERMSIG(STATUS) (((STATUS) >> 8) & 0xff) + #define WNOHANG 1 + + /** + * Unix-compatible errno + */ + int Jim_Errno(void); + pidtype waitpid(pidtype pid, int *status, int nohang); + + #define HAVE_PIPE + #define pipe(P) _pipe((P), 0, O_NOINHERIT) + +#elif defined(HAVE_UNISTD_H) + #include <unistd.h> + #include <fcntl.h> + #include <sys/wait.h> + #include <sys/stat.h> + + typedef int pidtype; + #define Jim_Errno() errno + #define JIM_BAD_PID -1 + #define JIM_NO_PID 0 + + #ifndef HAVE_EXECVPE + #define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV) + #endif +#endif + +#endif |