1
by Asheesh Laroia
Import upstream version 0.82+dfsg |
1 |
#if !defined(lint) && !defined(DOS)
|
2 |
static char rcsid[] = "$Id: popen.c 165 2006-10-04 01:09:47Z jpf@u.washington.edu $"; |
|
3 |
#endif
|
|
4 |
||
5 |
/*
|
|
6 |
* ========================================================================
|
|
7 |
* Copyright 2006 University of Washington
|
|
8 |
*
|
|
9 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10 |
* you may not use this file except in compliance with the License.
|
|
11 |
* You may obtain a copy of the License at
|
|
12 |
*
|
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14 |
*
|
|
15 |
* ========================================================================
|
|
16 |
*/
|
|
17 |
||
18 |
#include <system.h> |
|
19 |
#include <general.h> |
|
20 |
#include "../estruct.h" |
|
21 |
||
22 |
||
23 |
||
24 |
||
25 |
/*
|
|
26 |
* P_open - run the given command in a sub-shell returning a file pointer
|
|
27 |
* from which to read the output
|
|
28 |
*
|
|
29 |
* note:
|
|
30 |
* For OS's other than unix, you will have to rewrite this function.
|
|
31 |
* Hopefully it'll be easy to exec the command into a temporary file,
|
|
32 |
* and return a file pointer to that opened file or something.
|
|
33 |
*/
|
|
34 |
int
|
|
35 |
P_open(char *s) |
|
36 |
{
|
|
37 |
#if HAVE_POPEN
|
|
38 |
extern FIOINFO g_pico_fio; |
|
39 |
||
40 |
g_pico_fio.flags = FIOINFO_READ; |
|
41 |
g_pico_fio.name = "pipe"; |
|
42 |
||
43 |
if((g_pico_fio.fp = popen(s, "r")) != NULL) |
|
44 |
return(FIOSUC); |
|
45 |
||
46 |
return(FIOERR); |
|
47 |
#else
|
|
48 |
/* Windows never did this, but piping has been done elsewhere */
|
|
49 |
return(0); |
|
50 |
#endif
|
|
51 |
}
|
|
52 |
||
53 |
||
54 |
||
55 |
/*
|
|
56 |
* P_close - close the given descriptor
|
|
57 |
*
|
|
58 |
*/
|
|
59 |
void
|
|
60 |
P_close(void) |
|
61 |
{
|
|
62 |
#if HAVE_PCLOSE
|
|
63 |
extern FIOINFO g_pico_fio; |
|
64 |
||
65 |
if(g_pico_fio.fp) |
|
66 |
(void) pclose(g_pico_fio.fp); |
|
67 |
#endif
|
|
68 |
}
|