Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 2 | /* |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 3 | * echo implementation for busybox |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 4 | * |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 5 | * Copyright (c) 1991, 1993 |
| 6 | * The Regents of the University of California. All rights reserved. |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 9 | * |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 10 | * Original copyright notice is retained at the end of this file. |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 13 | /* BB_AUDIT SUSv3 compliant -- unless configured as fancy echo. */ |
| 14 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/echo.html */ |
| 15 | |
| 16 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
| 17 | * |
| 18 | * Because of behavioral differences, implemented configurable SUSv3 |
| 19 | * or 'fancy' gnu-ish behaviors. Also, reduced size and fixed bugs. |
| 20 | * 1) In handling '\c' escape, the previous version only suppressed the |
| 21 | * trailing newline. SUSv3 specifies _no_ output after '\c'. |
| 22 | * 2) SUSv3 specifies that octal escapes are of the form \0{#{#{#}}}. |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 23 | * The previous version did not allow 4-digit octals. |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 26 | //usage:#define echo_trivial_usage |
| 27 | //usage: IF_FEATURE_FANCY_ECHO("[-neE] ") "[ARG]..." |
| 28 | //usage:#define echo_full_usage "\n\n" |
| 29 | //usage: "Print the specified ARGs to stdout" |
| 30 | //usage: IF_FEATURE_FANCY_ECHO( "\n" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 31 | //usage: "\n -n Suppress trailing newline" |
| 32 | //usage: "\n -e Interpret backslash escapes (i.e., \\t=tab)" |
| 33 | //usage: "\n -E Don't interpret backslash escapes (default)" |
| 34 | //usage: ) |
| 35 | //usage: |
| 36 | //usage:#define echo_example_usage |
| 37 | //usage: "$ echo \"Erik is cool\"\n" |
| 38 | //usage: "Erik is cool\n" |
| 39 | //usage: IF_FEATURE_FANCY_ECHO("$ echo -e \"Erik\\nis\\ncool\"\n" |
| 40 | //usage: "Erik\n" |
| 41 | //usage: "is\n" |
| 42 | //usage: "cool\n" |
| 43 | //usage: "$ echo \"Erik\\nis\\ncool\"\n" |
| 44 | //usage: "Erik\\nis\\ncool\n") |
| 45 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 46 | #include "libbb.h" |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 47 | |
Denis Vlasenko | fe5e23b | 2007-11-24 02:23:51 +0000 | [diff] [blame] | 48 | /* This is a NOFORK applet. Be very careful! */ |
| 49 | |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 50 | /* NB: can be used by shell even if not enabled as applet */ |
Denis Vlasenko | fe5e23b | 2007-11-24 02:23:51 +0000 | [diff] [blame] | 51 | |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 52 | /* |
| 53 | * NB2: we don't use stdio, we need better error handing. |
| 54 | * Examples include writing into non-opened stdout and error on write. |
| 55 | * |
| 56 | * With stdio, output gets shoveled into stdout buffer, and even |
| 57 | * fflush cannot clear it out. It seems that even if libc receives |
| 58 | * EBADF on write attempts, it feels determined to output data no matter what. |
| 59 | * If echo is called by shell, it will try writing again later, and possibly |
| 60 | * will clobber future output. Not good. |
| 61 | * |
| 62 | * Solaris has fpurge which discards buffered input. glibc has __fpurge. |
| 63 | * But this function is not standard. |
| 64 | */ |
| 65 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 66 | int echo_main(int argc UNUSED_PARAM, char **argv) |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 67 | { |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 68 | char **pp; |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 69 | const char *arg; |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 70 | char *out; |
| 71 | char *buffer; |
| 72 | unsigned buflen; |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 73 | #if !ENABLE_FEATURE_FANCY_ECHO |
Denis Vlasenko | a9d7d24 | 2007-04-10 16:34:00 +0000 | [diff] [blame] | 74 | enum { |
| 75 | eflag = '\\', |
| 76 | nflag = 1, /* 1 -- print '\n' */ |
| 77 | }; |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 78 | |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 79 | argv++; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 80 | #else |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 81 | char nflag = 1; |
| 82 | char eflag = 0; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 83 | |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 84 | while ((arg = *++argv) != NULL) { |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 85 | char n, e; |
| 86 | |
| 87 | if (arg[0] != '-') |
| 88 | break; /* not an option arg, echo it */ |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 89 | |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 90 | /* If it appears that we are handling options, then make sure |
| 91 | * that all of the options specified are actually valid. |
| 92 | * Otherwise, the string should just be echoed. |
| 93 | */ |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 94 | arg++; |
| 95 | n = nflag; |
| 96 | e = eflag; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 97 | do { |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 98 | if (*arg == 'n') |
| 99 | n = 0; |
| 100 | else if (*arg == 'e') |
| 101 | e = '\\'; |
| 102 | else if (*arg != 'E') { |
| 103 | /* "-ccc" arg with one of c's invalid, echo it */ |
| 104 | /* arg consisting from just "-" also handled here */ |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 105 | goto just_echo; |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 106 | } |
| 107 | } while (*++arg); |
| 108 | nflag = n; |
| 109 | eflag = e; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 110 | } |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 111 | just_echo: |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 112 | #endif |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 113 | |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 114 | buflen = 0; |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 115 | pp = argv; |
| 116 | while ((arg = *pp) != NULL) { |
| 117 | buflen += strlen(arg) + 1; |
| 118 | pp++; |
| 119 | } |
Denys Vlasenko | 4fdb67c | 2011-02-15 18:35:54 +0100 | [diff] [blame] | 120 | out = buffer = xmalloc(buflen + 1); /* +1 is needed for "no args" case */ |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 121 | |
| 122 | while ((arg = *argv) != NULL) { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 123 | int c; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 124 | |
Denis Vlasenko | a9d7d24 | 2007-04-10 16:34:00 +0000 | [diff] [blame] | 125 | if (!eflag) { |
| 126 | /* optimization for very common case */ |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 127 | out = stpcpy(out, arg); |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 128 | } else |
| 129 | while ((c = *arg++) != '\0') { |
| 130 | if (c == eflag) { |
| 131 | /* This is an "\x" sequence */ |
| 132 | |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 133 | if (*arg == 'c') { |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 134 | /* "\c" means cancel newline and |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 135 | * ignore all subsequent chars. */ |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 136 | goto do_write; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 137 | } |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 138 | /* Since SUSv3 mandates a first digit of 0, 4-digit octals |
| 139 | * of the form \0### are accepted. */ |
| 140 | if (*arg == '0') { |
| 141 | if ((unsigned char)(arg[1] - '0') < 8) { |
| 142 | /* 2nd char is 0..7: skip leading '0' */ |
| 143 | arg++; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 144 | } |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 145 | } |
| 146 | /* bb_process_escape_sequence handles NUL correctly |
| 147 | * ("...\" case). */ |
| 148 | { |
| 149 | /* optimization: don't force arg to be on-stack, |
| 150 | * use another variable for that. ~30 bytes win */ |
| 151 | const char *z = arg; |
| 152 | c = bb_process_escape_sequence(&z); |
| 153 | arg = z; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 156 | *out++ = c; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 159 | if (!*++argv) |
Denis Vlasenko | 7e754f1 | 2007-04-09 13:04:50 +0000 | [diff] [blame] | 160 | break; |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 161 | *out++ = ' '; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 164 | if (nflag) { |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 165 | *out++ = '\n'; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 166 | } |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 167 | |
| 168 | do_write: |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 169 | /* Careful to error out on partial writes too (think ENOSPC!) */ |
| 170 | errno = 0; |
| 171 | /*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer); |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 172 | free(buffer); |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 173 | if (/*WRONG:r < 0*/ errno) { |
Denys Vlasenko | 8ee2ada | 2011-02-07 02:03:51 +0100 | [diff] [blame] | 174 | bb_perror_msg(bb_msg_write_error); |
| 175 | return 1; |
| 176 | } |
| 177 | return 0; |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 180 | /* |
Paul Fox | 6ab0378 | 2006-06-08 21:37:26 +0000 | [diff] [blame] | 181 | * Copyright (c) 1991, 1993 |
| 182 | * The Regents of the University of California. All rights reserved. |
| 183 | * |
| 184 | * This code is derived from software contributed to Berkeley by |
| 185 | * Kenneth Almquist. |
| 186 | * |
| 187 | * Redistribution and use in source and binary forms, with or without |
| 188 | * modification, are permitted provided that the following conditions |
| 189 | * are met: |
| 190 | * 1. Redistributions of source code must retain the above copyright |
| 191 | * notice, this list of conditions and the following disclaimer. |
| 192 | * 2. Redistributions in binary form must reproduce the above copyright |
| 193 | * notice, this list of conditions and the following disclaimer in the |
| 194 | * documentation and/or other materials provided with the distribution. |
| 195 | * |
| 196 | * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change |
| 197 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> |
| 198 | * |
| 199 | * California, Berkeley and its contributors. |
| 200 | * 4. Neither the name of the University nor the names of its contributors |
| 201 | * may be used to endorse or promote products derived from this software |
| 202 | * without specific prior written permission. |
| 203 | * |
| 204 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 205 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 206 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 207 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 208 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 209 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 210 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 211 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 212 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 213 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 214 | * SUCH DAMAGE. |
| 215 | * |
| 216 | * @(#)echo.c 8.1 (Berkeley) 5/31/93 |
| 217 | */ |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 218 | |
| 219 | #ifdef VERSION_WITH_WRITEV |
| 220 | /* We can't use stdio. |
| 221 | * The reason for this is highly non-obvious. |
Denis Vlasenko | fe5e23b | 2007-11-24 02:23:51 +0000 | [diff] [blame] | 222 | * echo_main is used from shell. Shell must correctly handle "echo foo" |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 223 | * if stdout is closed. With stdio, output gets shoveled into |
| 224 | * stdout buffer, and even fflush cannot clear it out. It seems that |
| 225 | * even if libc receives EBADF on write attempts, it feels determined |
| 226 | * to output data no matter what. So it will try later, |
| 227 | * and possibly will clobber future output. Not good. |
| 228 | * |
| 229 | * Using writev instead, with 'direct' conversion of argv vector. |
| 230 | */ |
| 231 | |
Denis Vlasenko | fe5e23b | 2007-11-24 02:23:51 +0000 | [diff] [blame] | 232 | int echo_main(int argc, char **argv) |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 233 | { |
| 234 | struct iovec io[argc]; |
| 235 | struct iovec *cur_io = io; |
| 236 | char *arg; |
| 237 | char *p; |
| 238 | #if !ENABLE_FEATURE_FANCY_ECHO |
| 239 | enum { |
| 240 | eflag = '\\', |
| 241 | nflag = 1, /* 1 -- print '\n' */ |
| 242 | }; |
| 243 | arg = *++argv; |
| 244 | if (!arg) |
| 245 | goto newline_ret; |
| 246 | #else |
| 247 | char nflag = 1; |
| 248 | char eflag = 0; |
| 249 | |
| 250 | while (1) { |
| 251 | arg = *++argv; |
| 252 | if (!arg) |
| 253 | goto newline_ret; |
| 254 | if (*arg != '-') |
| 255 | break; |
| 256 | |
| 257 | /* If it appears that we are handling options, then make sure |
| 258 | * that all of the options specified are actually valid. |
| 259 | * Otherwise, the string should just be echoed. |
| 260 | */ |
| 261 | p = arg + 1; |
| 262 | if (!*p) /* A single '-', so echo it. */ |
| 263 | goto just_echo; |
| 264 | |
| 265 | do { |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 266 | if (!strchr("neE", *p)) |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 267 | goto just_echo; |
| 268 | } while (*++p); |
| 269 | |
| 270 | /* All of the options in this arg are valid, so handle them. */ |
| 271 | p = arg + 1; |
| 272 | do { |
| 273 | if (*p == 'n') |
| 274 | nflag = 0; |
| 275 | if (*p == 'e') |
| 276 | eflag = '\\'; |
| 277 | } while (*++p); |
| 278 | } |
| 279 | just_echo: |
| 280 | #endif |
| 281 | |
| 282 | while (1) { |
| 283 | /* arg is already == *argv and isn't NULL */ |
| 284 | int c; |
| 285 | |
| 286 | cur_io->iov_base = p = arg; |
| 287 | |
| 288 | if (!eflag) { |
| 289 | /* optimization for very common case */ |
| 290 | p += strlen(arg); |
| 291 | } else while ((c = *arg++)) { |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 292 | if (c == eflag) { |
| 293 | /* This is an "\x" sequence */ |
| 294 | |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 295 | if (*arg == 'c') { |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 296 | /* "\c" means cancel newline and |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 297 | * ignore all subsequent chars. */ |
| 298 | cur_io->iov_len = p - (char*)cur_io->iov_base; |
| 299 | cur_io++; |
| 300 | goto ret; |
| 301 | } |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 302 | /* Since SUSv3 mandates a first digit of 0, 4-digit octals |
| 303 | * of the form \0### are accepted. */ |
| 304 | if (*arg == '0' && (unsigned char)(arg[1] - '0') < 8) { |
| 305 | arg++; |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 306 | } |
Denys Vlasenko | b934844 | 2011-02-14 15:42:18 +0100 | [diff] [blame] | 307 | /* bb_process_escape_sequence can handle nul correctly */ |
| 308 | c = bb_process_escape_sequence( (void*) &arg); |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 309 | } |
| 310 | *p++ = c; |
| 311 | } |
| 312 | |
| 313 | arg = *++argv; |
| 314 | if (arg) |
| 315 | *p++ = ' '; |
| 316 | cur_io->iov_len = p - (char*)cur_io->iov_base; |
| 317 | cur_io++; |
| 318 | if (!arg) |
| 319 | break; |
| 320 | } |
| 321 | |
| 322 | newline_ret: |
| 323 | if (nflag) { |
| 324 | cur_io->iov_base = (char*)"\n"; |
| 325 | cur_io->iov_len = 1; |
| 326 | cur_io++; |
| 327 | } |
| 328 | ret: |
| 329 | /* TODO: implement and use full_writev? */ |
Denis Vlasenko | f7be20e | 2007-12-24 14:09:19 +0000 | [diff] [blame] | 330 | return writev(1, io, (cur_io - io)) >= 0; |
Denis Vlasenko | 7d75a96 | 2007-11-22 08:16:57 +0000 | [diff] [blame] | 331 | } |
| 332 | #endif |