3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996, 1997
6 Space Applications Corporation
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this library; if not, write to the Free
21 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/types.h>
29 #include <sys/resource.h>
33 /* Prototype definitions within this file. */
34 int no_command (char *cmd);
35 FILE *uncompress_pipe (FILE *fp);
36 FILE *compress_pipe (FILE *fp);
39 /* Avoids the 'Broken pipe' message by reading the rest of the stream. */
40 void rsl_readflush(FILE *fp)
42 if (fork() == 0) { /* Child */
44 while(fread(buf, sizeof(char), sizeof(buf), fp)) continue;
49 int rsl_pclose(FILE *fp)
52 if ((rc=pclose(fp)) == EOF) {
53 perror ("pclose"); /* This or fclose do the job. */
54 if ((rc=fclose(fp)) == EOF)
55 perror ("fclose"); /* This or fclose do the job. */
60 int no_command (char *cmd)
63 /* Return 0 if there is the command 'cmd' on the system. */
64 /* Return !0 otherwise. */
66 if (rc == 0) return rc;
70 FILE *uncompress_pipe (FILE *fp)
72 /* Pass the file pointed to by 'fp' through the gzip pipe. */
77 if (no_command("gzip --version > /dev/null 2>&1")) return fp;
79 close(0); /* Redirect stdin for gzip. */
80 if (dup(fileno(fp)) < 0) {
81 perror("decompress_pipe");
85 fpipe = popen("gzip -q -d -f --stdout", "r");
86 if (fpipe == NULL) perror("uncompress_pipe");
88 if (dup(save_fd) < 0) {
89 perror("decompress_pipe");
95 FILE *compress_pipe (FILE *fp)
97 /* Pass the file pointed to by 'fp' through the gzip pipe. */
102 if (no_command("gzip --version > /dev/null 2>&1")) return fp;
103 fflush(NULL); /* Flush all buffered output before opening this pipe. */
105 close(1); /* Redirect stdout for gzip. */
106 if (dup(fileno(fp)) < 0) {
107 perror("compress_pipe");
111 fpipe = popen("gzip -q -1 -c", "w");
112 if (fpipe == NULL) perror("compress_pipe");
114 if (dup(save_fd) < 0) {
115 perror("compress_pipe");