Only create gcc/configargs.h if gcc build directory is present
[official-gcc.git] / libio / pfstream.cc
bloba438718f3882484c3e93c57e73699a3798d1d307
1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
4 This file is part of the GNU IO Library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
25 /* Written by Per Bothner (bothner@cygnus.com). */
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30 #include "libioP.h"
31 #include <pfstream.h>
32 #include <procbuf.h>
33 #include <string.h>
35 ipfstream::ipfstream(const char *name, int mode, int prot)
37 const char* p;
39 // Look for '| command' (as used by ftp).
40 for (p = name; *p == ' ' || *p == '\t'; p++) ;
41 if (*p == '|') {
42 procbuf *pbuf = new procbuf();
43 init(pbuf);
44 if (!pbuf->open(p+1, mode))
45 set(ios::badbit);
46 return;
49 // Look for 'command |'
50 while (*p) p++; // Point to last
51 while (p[-1] == ' ' || p[-1] == '\t' || p[-1] == '\n') p--;
52 if (p[-1] == '|') {
53 // Must remove the final '|'.
54 p--;
55 #if !defined (__GNUC__) || defined (__STRICT_ANSI__)
56 char *command = new char[p-name+1];
57 #else
58 char command[p-name+1];
59 #endif
60 memcpy(command, name, p-name);
61 command[p-name] = '\0';
63 procbuf *pbuf = new procbuf();
64 if (pbuf->open(command, mode))
65 set(ios::badbit);
66 #if !defined (__GNUC__) || defined (__STRICT_ANSI__)
67 delete command;
68 #endif
69 return;
72 init(new filebuf());
73 if (!rdbuf()->open(name, mode, prot))
74 set(ios::badbit);
77 opfstream::opfstream(const char *name, int mode, int prot)
79 const char *p;
80 // Look for '| command'.
81 for (p = name; *p == ' ' || *p == '\t'; p++) ;
82 if (*p == '|') {
83 procbuf *pbuf = new procbuf();
84 init(pbuf);
85 if (!pbuf->open(p+1, mode))
86 set(ios::badbit);
88 else {
89 init(new filebuf());
90 if (!rdbuf()->open(name, mode, prot))
91 set(ios::badbit);