]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdio-common/test-popen.c
[powerpc] No need to enter "Ignore Exceptions Mode"
[thirdparty/glibc.git] / stdio-common / test-popen.c
CommitLineData
04277e02 1/* Copyright (C) 1997-2019 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 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
993b3242 17
6591c335 18#include <errno.h>
28f540f4
RM
19#include <stdio.h>
20#include <stdlib.h>
21
cf3141a5 22static void
993b3242 23write_data (FILE *stream)
28f540f4
RM
24{
25 int i;
26 for (i=0; i<100; i++)
27 fprintf (stream, "%d\n", i);
6591c335
UD
28 if (ferror (stream))
29 {
30 fprintf (stderr, "Output to stream failed.\n");
31 exit (1);
28f540f4
RM
32 }
33}
34
cf3141a5 35static void
993b3242 36read_data (FILE *stream)
28f540f4
RM
37{
38 int i, j;
39
40 for (i=0; i<100; i++)
41 {
42 if (fscanf (stream, "%d\n", &j) != 1 || j != i)
43 {
44 if (ferror (stream))
45 perror ("fscanf");
46 puts ("Test FAILED!");
47 exit (1);
48 }
49 }
50}
51
29955b5d
AS
52static int
53do_test (void)
28f540f4
RM
54{
55 FILE *output, *input;
56 int wstatus, rstatus;
57
993b3242
UD
58 /* We must remove this entry to assure the `cat' binary does not use
59 the perhaps incompatible new shared libraries. */
60 unsetenv ("LD_LIBRARY_PATH");
61
27f10a09 62 output = popen ("/bin/cat >" OBJPFX "tstpopen.tmp", "w");
28f540f4
RM
63 if (output == NULL)
64 {
65 perror ("popen");
66 puts ("Test FAILED!");
67 exit (1);
68 }
69 write_data (output);
70 wstatus = pclose (output);
71 printf ("writing pclose returned %d\n", wstatus);
27f10a09 72 input = popen ("/bin/cat " OBJPFX "tstpopen.tmp", "r");
28f540f4
RM
73 if (input == NULL)
74 {
27f10a09 75 perror (OBJPFX "tstpopen.tmp");
28f540f4
RM
76 puts ("Test FAILED!");
77 exit (1);
78 }
79 read_data (input);
80 rstatus = pclose (input);
81 printf ("reading pclose returned %d\n", rstatus);
82
27f10a09 83 remove (OBJPFX "tstpopen.tmp");
ec4b0518 84
f43ce637
UD
85 errno = 0;
86 output = popen ("/bin/cat", "m");
87 if (output != NULL)
88 {
89 puts ("popen called with illegal mode does not return NULL");
90 puts ("Test FAILED!");
91 exit (1);
92 }
93 if (errno != EINVAL)
94 {
95 puts ("popen called with illegal mode does not set errno to EINVAL");
96 puts ("Test FAILED!");
97 exit (1);
98 }
99
28f540f4 100 puts (wstatus | rstatus ? "Test FAILED!" : "Test succeeded.");
cf3141a5 101 return (wstatus | rstatus);
28f540f4 102}
29955b5d
AS
103
104#define TEST_FUNCTION do_test ()
105#include "../test-skeleton.c"