From cef192d310c7445c3d85814ef3cd1e519bddc546 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 29 Aug 2011 00:03:22 +0000 Subject: [PATCH] Open files in binary mode for Win32 --- src/africa_to_radar.c | 4 ++-- src/anyformat_to_radar.c | 2 +- src/dorade_to_radar.c | 4 ++-- src/gzip.c | 4 ++-- src/histogram.c | 6 +++--- src/image_gen.c | 14 +++++++------- src/lassen_to_radar.c | 4 ++-- src/mcgill.c | 2 +- src/nsig.c | 4 ++-- src/radar_to_uf.c | 4 ++-- src/radtec.c | 2 +- src/rainbow_to_radar.c | 4 ++-- src/rapic_to_radar.c | 4 ++-- src/read_write.c | 6 +++--- src/toga.c | 2 +- src/uf_to_radar.c | 4 ++-- src/wsr88d.c | 6 +++--- src/wsr88d_get_site.c | 2 +- 18 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/africa_to_radar.c b/src/africa_to_radar.c index a5bffdd..b65fde2 100644 --- a/src/africa_to_radar.c +++ b/src/africa_to_radar.c @@ -69,9 +69,9 @@ Radar *RSL_africa_to_radar(char *infile) if (infile == NULL) { save_fd = dup(0); - fp = fdopen(save_fd, "r"); + fp = fdopen(save_fd, "rb"); } else { - fp = fopen(infile, "r"); + fp = fopen(infile, "rb"); } fp = uncompress_pipe(fp); n = 0; diff --git a/src/anyformat_to_radar.c b/src/anyformat_to_radar.c index 6f0d8fb..d3263bd 100644 --- a/src/anyformat_to_radar.c +++ b/src/anyformat_to_radar.c @@ -59,7 +59,7 @@ enum File_type RSL_filetype(char *infile) FILE *fp; char magic[11]; - if ((fp = fopen(infile, "r")) == NULL) { + if ((fp = fopen(infile, "rb")) == NULL) { perror(infile); return UNKNOWN; } diff --git a/src/dorade_to_radar.c b/src/dorade_to_radar.c index b3c8c66..f061665 100644 --- a/src/dorade_to_radar.c +++ b/src/dorade_to_radar.c @@ -184,9 +184,9 @@ Radar *RSL_dorade_to_radar(char *infile) if (infile == NULL) { int save_fd; save_fd = dup(0); - fp = fdopen(save_fd, "r"); + fp = fdopen(save_fd, "rb"); } else - if((fp=fopen(infile, "r"))==(FILE *)NULL) { + if((fp=fopen(infile, "rb"))==(FILE *)NULL) { perror(infile); return radar; } diff --git a/src/gzip.c b/src/gzip.c index 9c2ef31..8a34fa4 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -81,7 +81,7 @@ FILE *uncompress_pipe (FILE *fp) return NULL; } - fpipe = popen("gzip -q -d -f --stdout", "r"); + fpipe = popen("gzip -q -d -f --stdout", "rb"); if (fpipe == NULL) perror("uncompress_pipe"); close(0); if (dup(save_fd) < 0) { @@ -108,7 +108,7 @@ FILE *compress_pipe (FILE *fp) return NULL; } - fpipe = popen("gzip -q -1 -c", "w"); + fpipe = popen("gzip -q -1 -c", "wb"); if (fpipe == NULL) perror("compress_pipe"); close(1); if (dup(save_fd) < 0) { diff --git a/src/histogram.c b/src/histogram.c index ffefe1e..5acc7f1 100644 --- a/src/histogram.c +++ b/src/histogram.c @@ -107,7 +107,7 @@ void RSL_print_histogram(Histogram *histogram, int min_range, int max_range, } if (radar_verbose_flag) fprintf(stderr,"print_histogram: %s\n",filename); - if((fp = fopen(filename,"w")) == NULL ) { + if((fp = fopen(filename,"wb")) == NULL ) { perror(filename); return; } @@ -156,7 +156,7 @@ Histogram *RSL_read_histogram(char *infile) int nbins; Histogram *histogram; - if ((fp = fopen(infile, "r")) == NULL) { + if ((fp = fopen(infile, "rb")) == NULL) { perror(infile); return NULL; } @@ -191,7 +191,7 @@ int RSL_write_histogram(Histogram *histogram, char *outfile) FILE *fp; int n; - if ((fp = fopen(outfile, "w")) == NULL) { + if ((fp = fopen(outfile, "wb")) == NULL) { perror(outfile); return -1; } diff --git a/src/image_gen.c b/src/image_gen.c index ba968c2..3c69b7b 100644 --- a/src/image_gen.c +++ b/src/image_gen.c @@ -82,7 +82,7 @@ void RSL_load_color_table(char *infile, char buffer[256], int *num_colors) { FILE *fp; - fp = fopen(infile, "r"); + fp = fopen(infile, "rb"); if (fp == NULL) { perror(infile); exit(-1); @@ -290,7 +290,7 @@ void RSL_bscan_sweep(Sweep *s, char *outfile) FILE *fp; if (s == NULL) return; - fp = fopen(outfile,"w"); + fp = fopen(outfile,"wb"); if (fp == NULL) { perror(outfile); return; @@ -522,7 +522,7 @@ void RSL_write_gif(char *outfile, unsigned char *image, int xdim, int ydim, char fpipe = NULL; nbytes = xdim*ydim; (void)sprintf(pipecmd, "ppmtogif > %s 2>/dev/null", outfile); - fpipe = popen(pipecmd, "w"); /* Global FILE * */ + fpipe = popen(pipecmd, "wb"); /* Global FILE * */ if (fpipe == NULL) { perror("RSL_write_gif1"); return; @@ -563,7 +563,7 @@ void RSL_write_pict(char *outfile, unsigned char *image, int xdim, int ydim, cha } nbytes = xdim*ydim; (void)sprintf(pipecmd, "ppmtopict > %s 2>/dev/null", outfile); - fpipe = popen(pipecmd, "w"); /* Global FILE * */ + fpipe = popen(pipecmd, "wb"); /* Global FILE * */ fprintf(fpipe, "P6\n# %s\n%d %d\n255\n",outfile, xdim, ydim); for (i=0; i %s.gz 2>/dev/null", outfile); - fpipe = popen(pipecmd, "w"); /* Global FILE * */ + fpipe = popen(pipecmd, "wb"); /* Global FILE * */ fprintf(fpipe, "P5\n# %s\n%d %d\n255\n",outfile, xdim, ydim); if (fwrite(image, sizeof(char), nbytes, fpipe) != nbytes) fprintf(stderr, "RSL_write_pgm: short write\n"); @@ -625,7 +625,7 @@ void RSL_write_pgm(char *outfile, unsigned char *image, int xdim, int ydim) /* The following is commented and is for non compressed. */ #ifdef COMPILE nbytes = xdim*ydim; - fpipe = fopen(outfile, "w"); /* Global FILE * */ + fpipe = fopen(outfile, "wb"); /* Global FILE * */ fprintf(fpipe, "P5\n# %s\n%d %d\n255\n",outfile, xdim, ydim); (void)fwrite(image, sizeof(char), nbytes, fpipe); (void)fclose(fpipe); diff --git a/src/lassen_to_radar.c b/src/lassen_to_radar.c index 7925c50..4b42f69 100644 --- a/src/lassen_to_radar.c +++ b/src/lassen_to_radar.c @@ -278,9 +278,9 @@ Radar *RSL_lassen_to_radar(char *infile) if (infile == NULL) { int save_fd; save_fd = dup(0); - f = fdopen(save_fd, "r"); + f = fdopen(save_fd, "rb"); } else - if((f=fopen(infile, "r"))==(FILE *)NULL) { + if((f=fopen(infile, "rb"))==(FILE *)NULL) { perror(infile); return NULL; } diff --git a/src/mcgill.c b/src/mcgill.c index f4805ca..5b9174b 100644 --- a/src/mcgill.c +++ b/src/mcgill.c @@ -126,7 +126,7 @@ mcgFile_t *mcgFileOpen(int *code, char *filename) } /* Open Mcgill data file for reading */ - if ((file->fp = fopen(filename, "r")) == NULL) + if ((file->fp = fopen(filename, "rb")) == NULL) { *code = MCG_OPEN_FILE_ERR; return(NULL); diff --git a/src/nsig.c b/src/nsig.c index 9ae5913..bb07fc4 100644 --- a/src/nsig.c +++ b/src/nsig.c @@ -70,8 +70,8 @@ FILE *nsig_open(char *file_name) /* Open input file */ if (file_name == NULL) { /* Use stdin */ save_fd = dup(0); - fp = fdopen(save_fd, "r"); - } else if((fp = fopen(file_name,"r")) == NULL) { + fp = fdopen(save_fd, "rb"); + } else if((fp = fopen(file_name,"rb")) == NULL) { perror(file_name); return fp; } diff --git a/src/radar_to_uf.c b/src/radar_to_uf.c index fae49a2..de1f96d 100644 --- a/src/radar_to_uf.c +++ b/src/radar_to_uf.c @@ -527,7 +527,7 @@ void RSL_radar_to_uf(Radar *r, char *outfile) return; } - if ((fp = fopen(outfile, "w")) == NULL) { + if ((fp = fopen(outfile, "wb")) == NULL) { perror(outfile); return; } @@ -549,7 +549,7 @@ void RSL_radar_to_uf_gzip(Radar *r, char *outfile) return; } - if ((fp = fopen(outfile, "w")) == NULL) { + if ((fp = fopen(outfile, "wb")) == NULL) { perror(outfile); return; } diff --git a/src/radtec.c b/src/radtec.c index 366bbce..b17d7ab 100644 --- a/src/radtec.c +++ b/src/radtec.c @@ -239,7 +239,7 @@ Radtec_file *radtec_read_file(char *infile) if (infile == NULL) { fp = stdin; } else { - if((fp = fopen(infile, "r")) == NULL) { + if((fp = fopen(infile, "rb")) == NULL) { perror(infile); return NULL; } diff --git a/src/rainbow_to_radar.c b/src/rainbow_to_radar.c index 5dc0a28..c3f05bc 100644 --- a/src/rainbow_to_radar.c +++ b/src/rainbow_to_radar.c @@ -85,9 +85,9 @@ Radar *RSL_rainbow_to_radar(char *infile) if (infile == NULL) { int save_fd; save_fd = dup(0); - fp = fdopen(save_fd, "r"); + fp = fdopen(save_fd, "rb"); } - else if ((fp = fopen(infile, "r")) == NULL) { + else if ((fp = fopen(infile, "rb")) == NULL) { perror(infile); return NULL; } diff --git a/src/rapic_to_radar.c b/src/rapic_to_radar.c index 7d9b7ca..a2d8dea 100644 --- a/src/rapic_to_radar.c +++ b/src/rapic_to_radar.c @@ -15,9 +15,9 @@ Radar *RSL_rapic_to_radar(char *infile) radar = NULL; if (infile == NULL) { save_fd = dup(0); - fp = fdopen(save_fd, "r"); + fp = fdopen(save_fd, "rb"); } else { - if ((fp = fopen(infile, "r")) == NULL) { + if ((fp = fopen(infile, "rb")) == NULL) { perror(infile); return radar; } diff --git a/src/read_write.c b/src/read_write.c index 8c93987..65b378c 100644 --- a/src/read_write.c +++ b/src/read_write.c @@ -194,7 +194,7 @@ Radar *RSL_read_radar(char *infile) int nradar; char title[100]; - if ((fp = fopen(infile, "r")) == NULL) { + if ((fp = fopen(infile, "rb")) == NULL) { perror(infile); return NULL; } @@ -366,7 +366,7 @@ int RSL_write_radar(Radar *radar, char *outfile) if (radar == NULL) return 0; - if ((fp = fopen(outfile, "w")) == NULL) { + if ((fp = fopen(outfile, "wb")) == NULL) { perror(outfile); return -1; } @@ -386,7 +386,7 @@ int RSL_write_radar_gzip(Radar *radar, char *outfile) int n; if (radar == NULL) return 0; - if ((fp = fopen(outfile, "w")) == NULL) { + if ((fp = fopen(outfile, "wb")) == NULL) { perror(outfile); return -1; } diff --git a/src/toga.c b/src/toga.c index 38edd6b..d249ea8 100644 --- a/src/toga.c +++ b/src/toga.c @@ -102,7 +102,7 @@ int tg_open(char *filename,tg_file_str *tg_file) /* Unfortunately, there is no tg_close to modularize the following * pipe close. Shouldn't be any problems anyway. */ - (void) uncompress_pipe(fdopen(tg_file->fd, "r")); /* Redirect through gunzip. */ + (void) uncompress_pipe(fdopen(tg_file->fd, "rb")); /* Redirect through gunzip. */ /* initialize buffer pointers, flags */ tg_file->buf_ind = 32769; tg_file->buf_end = 32769; diff --git a/src/uf_to_radar.c b/src/uf_to_radar.c index d9d0673..463f969 100644 --- a/src/uf_to_radar.c +++ b/src/uf_to_radar.c @@ -604,8 +604,8 @@ Radar *RSL_uf_to_radar(char *infile) if (infile == NULL) { int save_fd; save_fd = dup(0); - fp = fdopen(save_fd, "r"); - } else if ((fp = fopen(infile, "r")) == NULL) { + fp = fdopen(save_fd, "rb"); + } else if ((fp = fopen(infile, "rb")) == NULL) { perror(infile); return radar; } diff --git a/src/wsr88d.c b/src/wsr88d.c index eeadeb8..5ab590d 100644 --- a/src/wsr88d.c +++ b/src/wsr88d.c @@ -240,9 +240,9 @@ Wsr88d_file *wsr88d_open(char *filename) if ( strcmp(filename, "stdin") == 0 ) { save_fd = dup(0); - wf->fptr = fdopen(save_fd,"r"); + wf->fptr = fdopen(save_fd,"rb"); } else { - wf->fptr = fopen(filename, "r"); + wf->fptr = fopen(filename, "rb"); } if (wf->fptr == NULL) return NULL; @@ -324,7 +324,7 @@ int wsr88d_read_tape_header(char *first_file, int n; char c; - if ((fp = fopen(first_file, "r")) == NULL) { + if ((fp = fopen(first_file, "rb")) == NULL) { perror(first_file); return 0; } diff --git a/src/wsr88d_get_site.c b/src/wsr88d_get_site.c index 6b5f661..4f08e81 100644 --- a/src/wsr88d_get_site.c +++ b/src/wsr88d_get_site.c @@ -46,7 +46,7 @@ Wsr88d_site_info *wsr88d_get_site(char *in_sitenm) struct radar_site *currsite=NULL; FILE *in_file; - if((in_file=fopen(WSR88D_SITE_INFO_FILE, "r")) !=NULL) + if((in_file=fopen(WSR88D_SITE_INFO_FILE, "rb")) !=NULL) { /* read each line */ while (fgets(line,sizeof(line),in_file) != NULL) -- 2.43.2