| 1 | greg | 3.12 | /* RCSid $Id: rtprocess.h,v 3.11 2004/10/23 18:55:52 schorsch Exp $ */ | 
| 2 | schorsch | 3.1 | /* | 
| 3 |  |  | *   rtprocess.h | 
| 4 |  |  | *   Routines to communicate with separate process via dual pipes | 
| 5 |  |  | * | 
| 6 |  |  | *   WARNING: On Windows, there's a system header named <process.h>. | 
| 7 |  |  | */ | 
| 8 |  |  | #ifndef _RAD_PROCESS_H_ | 
| 9 |  |  | #define _RAD_PROCESS_H_ | 
| 10 |  |  |  | 
| 11 | schorsch | 3.3 | #include  <errno.h> | 
| 12 | schorsch | 3.1 | #ifdef _WIN32 | 
| 13 | schorsch | 3.3 | #include <windows.h> /* DWORD etc. */ | 
| 14 | schorsch | 3.6 | #include <stdio.h> | 
| 15 | schorsch | 3.10 | typedef DWORD RT_PID; | 
| 16 | schorsch | 3.3 | #include <process.h> /* getpid() and others */ | 
| 17 | schorsch | 3.5 | #define nice(inc) win_nice(inc) | 
| 18 | schorsch | 3.6 |  | 
| 19 |  |  | #ifdef __cplusplus | 
| 20 |  |  | extern "C" { | 
| 21 |  |  | #endif | 
| 22 |  |  | extern FILE *win_popen(char *command, char *type); | 
| 23 |  |  | extern int win_pclose(FILE *p); | 
| 24 | schorsch | 3.11 | int win_kill(RT_PID pid, int sig /* ignored */); | 
| 25 |  |  | #define kill(pid,sig) win_kill(pid,sig) | 
| 26 | schorsch | 3.6 | #ifdef __cplusplus | 
| 27 |  |  | } | 
| 28 |  |  | #endif | 
| 29 | greg | 3.12 | #ifdef _MSC_VER | 
| 30 |  |  | #define popen(cmd,mode) _popen(cmd,mode) | 
| 31 |  |  | #define pclose(p) _pclose(p) | 
| 32 |  |  | #else | 
| 33 |  |  | #define popen(cmd,mode) win_popen(cmd,mode) | 
| 34 |  |  | #define pclose(p) win_pclose(p) | 
| 35 |  |  | #endif | 
| 36 | schorsch | 3.1 | #else | 
| 37 | schorsch | 3.9 | #include <stdio.h> | 
| 38 | schorsch | 3.1 | #include <sys/param.h> | 
| 39 | schorsch | 3.10 | #include <sys/types.h> | 
| 40 |  |  | typedef pid_t RT_PID; | 
| 41 | schorsch | 3.1 | #endif | 
| 42 |  |  |  | 
| 43 |  |  | #include "paths.h" | 
| 44 |  |  |  | 
| 45 | schorsch | 3.4 | #ifdef __cplusplus | 
| 46 |  |  | extern "C" { | 
| 47 |  |  | #endif | 
| 48 | schorsch | 3.1 |  | 
| 49 |  |  | /* On Windows, a process ID is a DWORD. That might actually be the | 
| 50 |  |  | same thing as an int, but it's better not to assume anything. | 
| 51 |  |  |  | 
| 52 |  |  | This means that we shouldn't rely on PIDs and file descriptors | 
| 53 |  |  | being the same type, so we have to describe processes with a struct, | 
| 54 | schorsch | 3.10 | instead of the original int[3]. For that purpose, we typedef a | 
| 55 |  |  | platform independent RT_PID. | 
| 56 | schorsch | 3.1 | */ | 
| 57 |  |  |  | 
| 58 |  |  |  | 
| 59 |  |  | #ifndef PIPE_BUF | 
| 60 |  |  | #ifdef PIPSIZ | 
| 61 |  |  | #define PIPE_BUF    PIPSIZ | 
| 62 |  |  | #else | 
| 63 |  |  | #ifdef PIPE_MAX | 
| 64 |  |  | #define PIPE_BUF  PIPE_MAX | 
| 65 |  |  | #else | 
| 66 |  |  | #define PIPE_BUF  512             /* hyperconservative */ | 
| 67 |  |  | #endif | 
| 68 |  |  | #endif | 
| 69 |  |  | #endif | 
| 70 |  |  |  | 
| 71 |  |  | typedef struct { | 
| 72 |  |  | int r; /* read handle */ | 
| 73 |  |  | int w; /* write handle */ | 
| 74 |  |  | int running; /* doing something */ | 
| 75 | schorsch | 3.10 | RT_PID pid; /* process ID */ | 
| 76 | schorsch | 3.1 | } SUBPROC; | 
| 77 |  |  |  | 
| 78 |  |  | #define SP_INACTIVE {-1,-1,0,0} /* for static initializations */ | 
| 79 |  |  |  | 
| 80 |  |  | extern int open_process(SUBPROC *pd, char *av[]); | 
| 81 |  |  | extern int close_process(SUBPROC *pd); | 
| 82 |  |  | extern int process(SUBPROC *pd, char *recvbuf, char *sendbuf, int nbr, int nbs); | 
| 83 |  |  | extern int readbuf(int fd, char *bpos, int siz); | 
| 84 |  |  | extern int writebuf(int fd, char *bpos, int siz); | 
| 85 | schorsch | 3.5 |  | 
| 86 |  |  | #ifdef _WIN32 | 
| 87 |  |  | /* any non-negative increment will send the process to IDLE_PRIORITY_CLASS. */ | 
| 88 |  |  | extern int win_nice(int inc); | 
| 89 |  |  | #endif | 
| 90 | schorsch | 3.1 |  | 
| 91 |  |  |  | 
| 92 |  |  | #ifdef __cplusplus | 
| 93 |  |  | } | 
| 94 |  |  | #endif | 
| 95 |  |  | #endif /* _RAD_PROCESS_H_ */ | 
| 96 |  |  |  |