| 1 |
/* |
| 2 |
* Amanda, The Advanced Maryland Automatic Network Disk Archiver |
| 3 |
* Copyright (c) 1991-1998 University of Maryland at College Park |
| 4 |
* Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. |
| 5 |
* Copyright (c) 2013-2016 Carbonite, Inc. All Rights Reserved. |
| 6 |
* All Rights Reserved. |
| 7 |
* |
| 8 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 9 |
* documentation for any purpose is hereby granted without fee, provided that |
| 10 |
* the above copyright notice appear in all copies and that both that |
| 11 |
* copyright notice and this permission notice appear in supporting |
| 12 |
* documentation, and that the name of U.M. not be used in advertising or |
| 13 |
* publicity pertaining to distribution of the software without specific, |
| 14 |
* written prior permission. U.M. makes no representations about the |
| 15 |
* suitability of this software for any purpose. It is provided "as is" |
| 16 |
* without express or implied warranty. |
| 17 |
* |
| 18 |
* U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL |
| 19 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. |
| 20 |
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 21 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 22 |
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 23 |
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 |
* |
| 25 |
* Authors: the Amanda Development Team. Its members are listed in a |
| 26 |
* file named AUTHORS, in the root directory of this distribution. |
| 27 |
*/ |
| 28 |
/* |
| 29 |
* $Id: teecount.c $ |
| 30 |
* |
| 31 |
* read stdin and write to to stdout |
| 32 |
* print on stderr the number of bytes copied |
| 33 |
*/ |
| 34 |
|
| 35 |
#include "amanda.h" |
| 36 |
|
| 37 |
#define BUFFER 262144 |
| 38 |
|
| 39 |
int main(int argc, char **argv); |
| 40 |
int |
| 41 |
main( |
| 42 |
int argc G_GNUC_UNUSED, |
| 43 |
char **argv G_GNUC_UNUSED) |
| 44 |
{ |
| 45 |
char buffer[BUFFER]; |
| 46 |
off_t total = 0; |
| 47 |
off_t size; |
| 48 |
off_t sizew; |
| 49 |
|
| 50 |
while ((size = safe_read(0, buffer, BUFFER)) > 0) { |
| 51 |
if ((sizew = full_write(1, buffer, size)) < size) { |
| 52 |
total += sizew; |
| 53 |
fprintf(stderr, "%ju", (uintmax_t)total); |
| 54 |
exit (-1); |
| 55 |
} |
| 56 |
total += size; |
| 57 |
} |
| 58 |
fprintf(stderr, "%ju", (uintmax_t)total); |
| 59 |
if (size < 0) { |
| 60 |
exit(-1); |
| 61 |
} |
| 62 |
return 0; |
| 63 |
} |