• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2001-2004 Brandon Long
3  * All Rights Reserved.
4  *
5  * ClearSilver Templating System
6  *
7  * This code is made available under the terms of the ClearSilver License.
8  * http://www.clearsilver.net/license.hdf
9  *
10  */
11 
12 #ifndef __NEO_FILTER_H_
13 #define __NEO_FILTER_H_ 1
14 
15 __BEGIN_DECLS
16 
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include "util/neo_misc.h"
20 #include "util/neo_err.h"
21 
22 /*
23  * Function: filter_wait - wrap waitpid to decode the exitcode and why
24  *           your filter quit
25  * Description: filter_wait wraps the waitpid call and raises an error
26  *              (with description) if the call failed.  Note that if the
27  *              ask for the exitcode and the process exited with a code
28  *              other than zero, we don't raise an error.  If you don't
29  *              ask for the exitcode, and it is non-zero, we raise an
30  *              error
31  * Input: pid -> the process identifier to wait for
32  *        options -> the options to pass to waitpid (see wait(2))
33  * Output: exitcode -> the exitcode if the process existed normally
34  * Returns: NERR_SYSTEM, NERR_ASSERT
35  */
36 NEOERR *filter_wait(pid_t pid, int options, int *exitcode);
37 
38 /*
39  * Function: filter_create_fd - Create a sub process and return the
40  * requested pipes
41  * Description: filter_create_fd and filter_create_fp are what popen
42  *              should have been: a mechanism to create sub processes
43  *              and have pipes to all their input/output.  The concept
44  *              was taken from mutt, though python has something similar
45  *              with popen3/popen4.  You control which pipes the
46  *              function returns by the fdin/fdout/fderr arguments.  A
47  *              NULL value means "don't create a pipe", a pointer to an
48  *              int will cause the pipes to be created and the value
49  *              of the file descriptor stored in the int.  You will have
50  *              to close(2) the file descriptors yourself.
51  * Input: cmd -> the sub command to execute.  Will be executed with
52  *               /bin/sh -c
53  *        fdin -> pointer to return the stdin pipe, or NULL if you don't
54  *                want the stdin pipe
55  *        fdout -> pointer to return the stdout pipe, or NULL if you don't
56  *                 want the stdout pipe
57  *        fderr -> pointer to return the stderr pipe, or NULL if you don't
58  *                 want the stderr pipe
59  * Output: fdin -> the stdin file descriptor of the sub process
60  *         fdout -> the stdout file descriptor of the sub process
61  *         fderr -> the stderr file descriptor of the sub process
62  *         pid -> the pid of the sub process
63  * Returns: NERR_SYSTEM
64  */
65 NEOERR *filter_create_fd(const char *cmd, int *fdin, int *fdout, int *fderr,
66                          pid_t *pid);
67 
68 /*
69  * Function: filter_create_fp - similar to filter_create_fd except with
70  *           buffered FILE*
71  * Description: filter_create_fp is identical to filter_create_fd,
72  *              except each of the pipes is wrapped in a buffered stdio FILE
73  * Input: cmd -> the sub command to execute.  Will be executed with
74  *               /bin/sh -c
75  *        in -> pointer to return the stdin pipe, or NULL if you don't
76  *              want the stdin pipe
77  *        out -> pointer to return the stdout pipe, or NULL if you don't
78  *               want the stdout pipe
79  *        err -> pointer to return the stderr pipe, or NULL if you don't
80  *                 want the stderr pipe
81  * Output: in -> the stdin FILE of the sub process
82  *         out -> the stdout FILE of the sub process
83  *         err -> the stderr FILE of the sub process
84  *         pid -> the pid of the sub process
85  * Returns: NERR_SYSTEM, NERR_IO
86  */
87 NEOERR *filter_create_fp(const char *cmd, FILE **in, FILE **out, FILE **err,
88                          pid_t *pid);
89 
90 __END_DECLS
91 
92 #endif /* __NEO_FILTER_H_ */
93