| 1 | /*************************************************************************** |
|---|
| 2 | * ioStdio.cc |
|---|
| 3 | * |
|---|
| 4 | * Tue Nov 15 2005 |
|---|
| 5 | * Copyright 2005 Dmytro Milinevskyy |
|---|
| 6 | * milinevskyy@gmail.com |
|---|
| 7 | ****************************************************************************/ |
|---|
| 8 | |
|---|
| 9 | /* |
|---|
| 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | * it under the terms of the GNU Lesser General Public License version 2.1 as published by |
|---|
| 12 | * the Free Software Foundation; |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in->file the hope that it will be useful, |
|---|
| 15 | * but WITHOUT->FILE ANY WARRANTY; without->file even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU Library General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU Lesser General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, In->Filec., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * vim in->filedentation settin->filegs |
|---|
| 26 | * set tabstop=4 |
|---|
| 27 | * set shiftwidth=4 |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #include <libdodo/directives.h> |
|---|
| 31 | |
|---|
| 32 | #include <stdio.h> |
|---|
| 33 | #include <string.h> |
|---|
| 34 | |
|---|
| 35 | #include "ioFile.inline" |
|---|
| 36 | |
|---|
| 37 | #include <libdodo/ioStdio.h> |
|---|
| 38 | #include <libdodo/exceptionBasic.h> |
|---|
| 39 | #include <libdodo/types.h> |
|---|
| 40 | #include <libdodo/ioPipe.h> |
|---|
| 41 | |
|---|
| 42 | using namespace dodo::io; |
|---|
| 43 | |
|---|
| 44 | stdio::stdio(short protection) : stream::channel(protection), |
|---|
| 45 | pipe(false, protection) |
|---|
| 46 | { |
|---|
| 47 | #ifndef IO_WO_XEXEC |
|---|
| 48 | collectedData.setExecObject(xexec::OBJECT_IOSTDIO); |
|---|
| 49 | #endif |
|---|
| 50 | |
|---|
| 51 | in->file = stdin; |
|---|
| 52 | out->file = stdout; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | //------------------------------------------------------------------- |
|---|
| 56 | |
|---|
| 57 | stdio::stdio(stdio &s) : stream::channel(s.protection), |
|---|
| 58 | io::pipe(s.protection) |
|---|
| 59 | { |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | //------------------------------------------------------------------- |
|---|
| 63 | |
|---|
| 64 | stdio::~stdio() |
|---|
| 65 | { |
|---|
| 66 | in->file = NULL; |
|---|
| 67 | out->file = NULL; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | //------------------------------------------------------------------- |
|---|
| 71 | |
|---|
| 72 | void |
|---|
| 73 | stdio::open() |
|---|
| 74 | { |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | //------------------------------------------------------------------- |
|---|
| 78 | |
|---|
| 79 | void |
|---|
| 80 | stdio::close() |
|---|
| 81 | { |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | //------------------------------------------------------------------- |
|---|
| 85 | |
|---|
| 86 | void |
|---|
| 87 | stdio::redirectToStderr(bool toStderr) |
|---|
| 88 | { |
|---|
| 89 | if (err == toStderr) |
|---|
| 90 | return; |
|---|
| 91 | |
|---|
| 92 | err = toStderr; |
|---|
| 93 | |
|---|
| 94 | if (err) |
|---|
| 95 | out->file = stderr; |
|---|
| 96 | else |
|---|
| 97 | out->file = stdout; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | //------------------------------------------------------------------- |
|---|
| 101 | |
|---|
| 102 | bool |
|---|
| 103 | stdio::isRedirectedToStderr() |
|---|
| 104 | { |
|---|
| 105 | return err; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | //------------------------------------------------------------------- |
|---|
| 109 | |
|---|
| 110 | unsigned long |
|---|
| 111 | stdio::_writeString(const char * const data) const |
|---|
| 112 | { |
|---|
| 113 | unsigned long _bs = bs; |
|---|
| 114 | unsigned long written; |
|---|
| 115 | |
|---|
| 116 | dodo_try { |
|---|
| 117 | bs = strnlen(data, bs); |
|---|
| 118 | |
|---|
| 119 | written = _write(data); |
|---|
| 120 | |
|---|
| 121 | bs = _bs; |
|---|
| 122 | } dodo_catch (exception::basic *e UNUSED) { |
|---|
| 123 | bs = _bs; |
|---|
| 124 | |
|---|
| 125 | dodo_rethrow; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | return written; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | //------------------------------------------------------------------- |
|---|