2017-03-09 08:01:10 +08:00
|
|
|
/*********************************************************************
|
2018-12-07 06:36:53 +08:00
|
|
|
* Copyright 2018, UCAR/Unidata
|
2017-03-09 08:01:10 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2022-02-09 11:53:30 +08:00
|
|
|
#include "nc_tests.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
#define BUFLEN 100000
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
unsigned char buffer[BUFLEN];
|
|
|
|
size_t count, red, avail, trunc;
|
|
|
|
unsigned char* p = buffer;
|
2019-07-21 03:59:40 +08:00
|
|
|
size_t i;
|
2017-03-09 08:01:10 +08:00
|
|
|
FILE* input = stdin;
|
|
|
|
|
|
|
|
if(argc > 1) {
|
2022-02-09 11:53:30 +08:00
|
|
|
input = NCfopen(argv[1],"r");
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the whole file */
|
|
|
|
p = buffer;
|
|
|
|
red = 0;
|
|
|
|
avail = BUFLEN;
|
|
|
|
for(;;) {
|
|
|
|
count = fread(p,1,avail,input);
|
|
|
|
p += count;
|
|
|
|
red += count;
|
|
|
|
avail -= count;
|
|
|
|
if(feof(input)) break;
|
|
|
|
}
|
|
|
|
trunc = red;
|
|
|
|
for(i=(red-1);i>=0;i--) {
|
|
|
|
if(buffer[i] != '\0') {
|
|
|
|
trunc = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = buffer;
|
|
|
|
avail = trunc;
|
|
|
|
for(;;) {
|
|
|
|
count = fwrite(p,1,avail,stdout);
|
|
|
|
if(count == 0) break;
|
|
|
|
p += count;
|
|
|
|
avail -= count;
|
|
|
|
if(avail == 0) break;
|
|
|
|
}
|
|
|
|
if(avail > 0)
|
|
|
|
exit(1);
|
|
|
|
else
|
|
|
|
exit(0);
|
|
|
|
}
|