1 #ifndef CALLSYSTEM_INCLUDED
2 #define CALLSYSTEM_INCLUDED
4 callsystem - system() on steorids
7 - asynchonous running of a child process
8 - setup of the environment
9 - substitution of environment variables
10 - connect all 3 standard streams to pipes, null devices, or files
12 - #!shebang interpreter handling on any OS
14 ALL IN A PORTABLE WAY!
18 : is used as device identifier when the path starts with / ("/C:" becomes "C:\")
19 . is the current directory
20 .. is the parent directory
21 ~ is the users home directory
23 Environment variables:
24 only ${KEY} syntax is substituted in one pass, trying to substitute a non existing env var yields an error
28 first abstraction of a few types and loading OS specific headers
39 #if !defined(unix) && defined(__unix__) || defined(__NetBSD__)
43 #if defined(__APPLE__)
45 #include <sys/unistd.h>
51 #include <sys/resource.h>
54 #include <sys/types.h>
60 #error "system not supported!"
66 opaque process identifier type and value for an illegal pid
68 typedef pid_t callsystem_pid_t
;
69 #define CALLSYSTEM_ILG_PID 0
72 opaque file descriptors and values for illegal, std and potable null fd's
73 fd's are always used as pairs (two element array)
74 [0] is the used for reading
75 [1] is used for writing
76 either side might be CALLSYSTEM_ILG_FD for non-pipes, callsystem cares for closing the aprobiate sides
78 typedef int callsystem_fd_t
;
79 /* this is never an fd */
80 #define CALLSYSTEM_ILG_FD -1
84 typedef HANDLE callsystem_pid_t
;
85 #define CALLSYSTEM_ILG_PID NULL
86 typedef HANDLE callsystem_fd_t
;
87 #define CALLSYSTEM_ILG_FD INVALID_HANDLE_VALUE
89 #error "system unsupported"
95 INVOKING AND CONTROLLING CHILD PROGRAMS
99 callsystem(const char * cmd
,
102 callsystem_fd_t in
[2],
103 callsystem_fd_t out
[2],
104 callsystem_fd_t err
[2],
107 callsystem_pid_t
* const child
);
110 callsystem_running(callsystem_pid_t
* pid
);
113 callsystem_finished(callsystem_pid_t
* pid
);
116 callsystem_terminate(callsystem_pid_t
*);
119 callsystem_abort(callsystem_pid_t
*);
123 HANDLING FILE DESCRIPTORS AND PIPES
127 callsystem_pipe(callsystem_fd_t pipe
[2]);
130 callsystem_null(callsystem_fd_t null
[2]);
133 enum callsystem_filemode
{
134 CALLSYSTEM_MODE_READ
,
135 CALLSYSTEM_MODE_WRITE
,
136 CALLSYSTEM_MODE_CREATE
,
137 CALLSYSTEM_MODE_APPEND
,
138 CALLSYSTEM_MODE_OVERWRITE
,
139 CALLSYSTEM_MODE_BINARY
=8
143 callsystem_open(const char * filename
,
144 enum callsystem_filemode mode
,
145 callsystem_fd_t fd
[2]);
147 /* want sockets too? prolly not in the domain of this thing */
150 callsystem_close(callsystem_fd_t fds
[2]);
153 create a std C FILE stream to a underlying filedescriptor
156 callsystem_fdopen(callsystem_fd_t fds
[2], enum callsystem_filemode mode
);
165 callsystem_setenv(char ** env
[], const char * key
, const char * value
);
168 callsystem_getenv(char ** env
[], const char * key
);
171 callsystem_unsetenv(char ** env
[], const char * key
);
174 callsystem_exportenv(char ** env
[], const char * key
);
177 callsystem_exportdefaults(char ** env
[]);
180 callsystem_env_subst(char ** envp
[], const char * str
);
183 callsystem_env_clear(char ** env
[]);
193 callsystem_argv_pushback(char ** argv
[], const char * const arg
);
196 callsystem_argv_pushfront(char ** argv
[], const char * const arg
);
199 callsystem_argv_clear(char ** argv
[]);
203 PORTABLE PATHNAME HANDLING
208 callsystem_canonalize_path_to_host()
209 callsystem_canonalize_path_to_unix()
211 convert unix like filenames to OS specific filenames (and back)
213 checks that relative filenames do not leave their top directory
216 "/Letter:/" becomes "Letter:\"
217 "/foo/" becomes "\foo\"
219 needs much to worked out (UNC?)
221 callsystem_is_pathname()
222 check if some string could be a legal pathname on the actual host