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>
30 #include "win32compat.h"
32 /* Prototype definitions within this file. */
33 int no_command (char *cmd);
34 FILE *uncompress_pipe (FILE *fp);
35 FILE *compress_pipe (FILE *fp);
38 /* Avoids the 'Broken pipe' message by reading the rest of the stream. */
39 void rsl_readflush(FILE *fp)
41 if (fork() == 0) { /* Child */
43 while(fread(buf, sizeof(char), sizeof(buf), fp)) continue;
48 int rsl_pclose(FILE *fp)
51 if ((rc=pclose(fp)) == EOF) {
52 perror ("pclose"); /* This or fclose do the job. */
53 if ((rc=fclose(fp)) == EOF)
54 perror ("fclose"); /* This or fclose do the job. */
59 int no_command (char *cmd)
62 /* Return 0 if there is the command 'cmd' on the system. */
63 /* Return !0 otherwise. */
65 if (rc == 0) return rc;
69 FILE *uncompress_pipe (FILE *fp)
71 /* Pass the file pointed to by 'fp' through the gzip pipe. */
76 if (no_command("gzip --version > /dev/null 2>&1")) return fp;
78 close(0); /* Redirect stdin for gzip. */
79 if (dup(fileno(fp)) < 0) {
80 perror("decompress_pipe");
84 fpipe = popen("gzip -q -d -f --stdout", "r");
85 if (fpipe == NULL) perror("uncompress_pipe");
87 if (dup(save_fd) < 0) {
88 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");