]>
Commit | Line | Data |
---|---|---|
cf3141a5 | 1 | /* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. |
993b3242 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
993b3242 UD |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
993b3242 | 13 | |
41bdb6e2 AJ |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
993b3242 | 18 | |
6591c335 | 19 | #include <errno.h> |
28f540f4 RM |
20 | #include <stdio.h> |
21 | #include <stdlib.h> | |
22 | ||
cf3141a5 | 23 | static void |
993b3242 | 24 | write_data (FILE *stream) |
28f540f4 RM |
25 | { |
26 | int i; | |
27 | for (i=0; i<100; i++) | |
28 | fprintf (stream, "%d\n", i); | |
6591c335 UD |
29 | if (ferror (stream)) |
30 | { | |
31 | fprintf (stderr, "Output to stream failed.\n"); | |
32 | exit (1); | |
28f540f4 RM |
33 | } |
34 | } | |
35 | ||
cf3141a5 | 36 | static void |
993b3242 | 37 | read_data (FILE *stream) |
28f540f4 RM |
38 | { |
39 | int i, j; | |
40 | ||
41 | for (i=0; i<100; i++) | |
42 | { | |
43 | if (fscanf (stream, "%d\n", &j) != 1 || j != i) | |
44 | { | |
45 | if (ferror (stream)) | |
46 | perror ("fscanf"); | |
47 | puts ("Test FAILED!"); | |
48 | exit (1); | |
49 | } | |
50 | } | |
51 | } | |
52 | ||
53 | int | |
993b3242 | 54 | main (void) |
28f540f4 RM |
55 | { |
56 | FILE *output, *input; | |
57 | int wstatus, rstatus; | |
58 | ||
993b3242 UD |
59 | /* We must remove this entry to assure the `cat' binary does not use |
60 | the perhaps incompatible new shared libraries. */ | |
61 | unsetenv ("LD_LIBRARY_PATH"); | |
62 | ||
e66f63fb | 63 | output = popen ("/bin/cat >/tmp/tstpopen.tmp", "w"); |
28f540f4 RM |
64 | if (output == NULL) |
65 | { | |
66 | perror ("popen"); | |
67 | puts ("Test FAILED!"); | |
68 | exit (1); | |
69 | } | |
70 | write_data (output); | |
71 | wstatus = pclose (output); | |
72 | printf ("writing pclose returned %d\n", wstatus); | |
e66f63fb | 73 | input = popen ("/bin/cat /tmp/tstpopen.tmp", "r"); |
28f540f4 RM |
74 | if (input == NULL) |
75 | { | |
e66f63fb | 76 | perror ("/tmp/tstpopen.tmp"); |
28f540f4 RM |
77 | puts ("Test FAILED!"); |
78 | exit (1); | |
79 | } | |
80 | read_data (input); | |
81 | rstatus = pclose (input); | |
82 | printf ("reading pclose returned %d\n", rstatus); | |
83 | ||
ec4b0518 UD |
84 | remove ("/tmp/tstpopen.tmp"); |
85 | ||
f43ce637 UD |
86 | errno = 0; |
87 | output = popen ("/bin/cat", "m"); | |
88 | if (output != NULL) | |
89 | { | |
90 | puts ("popen called with illegal mode does not return NULL"); | |
91 | puts ("Test FAILED!"); | |
92 | exit (1); | |
93 | } | |
94 | if (errno != EINVAL) | |
95 | { | |
96 | puts ("popen called with illegal mode does not set errno to EINVAL"); | |
97 | puts ("Test FAILED!"); | |
98 | exit (1); | |
99 | } | |
100 | ||
28f540f4 | 101 | puts (wstatus | rstatus ? "Test FAILED!" : "Test succeeded."); |
cf3141a5 | 102 | return (wstatus | rstatus); |
28f540f4 | 103 | } |