File: nft_popen.h

package info (click to toggle)
cacti-spine 0.8.7e-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,900 kB
  • ctags: 534
  • sloc: ansic: 4,564; sh: 882; makefile: 70
file content (70 lines) | stat: -rw-r--r-- 2,532 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/******************************************************************************
 ex: set tabstop=4 shiftwidth=4 autoindent:
 *
 * (C) Copyright Xenadyne, Inc. 2002  All rights reserved.
 * 
 * Permission to use, copy, modify and distribute this software for
 * any purpose and without fee is hereby granted, provided that the 
 * above copyright notice appears in all copies.
 * 
 * XENADYNE INC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  
 * IN NO EVENT SHALL XENADYNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM THE 
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * File:    nft_popen.h
 *
 * PURPOSE
 *
 * Thread-safe substitute for popen() that doesn't use stdio streams.
 *
 ******************************************************************************
 */

/*!
 *  The nft_popen() function forks a command in a child process, and returns
 *  a pipe that is connected to the child's standard input and output. It is
 *  like the standard popen() call, except that it returns the file descriptor,
 *  instead of a stdio stream created by fdopen(). The file descriptor can be
 *  used with select() or poll(), or the caller can use fdopen() if a stdio
 *  FILE* is preferable.
 *
 *  The mode argument is defined as in standard popen(). 
 *
 *  On success, returns a file descriptor, or -1 on error.
 *  On failure, returns -1, with errno set to one of:
 *	EINVAL  The mode argument is incorrect.
 *	EMFILE	pipe() failed.
 *	ENFILE  pipe() failed.
 *	ENOMEM  malloc() failed.
 *	EAGAIN  fork() failed.
 */
extern int	nft_popen(const char * command, const char * mode);

/*!
 *  nft_pchild
 *
 *  Get the pid of the child process for an fd created by ntf_popen().
 *  
 *  On success, the pid of the child process is returned.
 *  On failure, nft_pchild() returns -1, with errno set to:
 *  
 *    EBADF	The fd is not an active nft_popen() file descriptor.
 */
extern int	nft_pchild(int fd);

/*!
 *  nft_pclose
 *
 *  Close the pipe and wait for the status of the child process.
 *  
 *  On success, the exit status of the child process is returned.
 *  On failure, nft_pclose() returns -1, with errno set to:
 *  
 *	EBADF	The fd is not an active popen() file descriptor.
 *	ECHILD	waitpid() failed.
 */
extern int	nft_pclose(int fd);