Mercurial > hg > index.cgi
comparison lwar/replace.c @ 265:6f4c4d59666f
Make lwar use the "b" flag when opening files.
Due to the dumbness on Windows systems related to text vs. binary file
distinctions, one needs to add 'b' to fopen() calls when dealing with binary
files.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 10 Feb 2013 19:22:24 -0700 |
parents | 346966cffeef |
children | 221b5f58d8ad |
comparison
equal
deleted
inserted
replaced
264:346966cffeef | 265:6f4c4d59666f |
---|---|
39 char fnbuf[1024]; | 39 char fnbuf[1024]; |
40 char fnbuf2[1024]; | 40 char fnbuf2[1024]; |
41 | 41 |
42 sprintf(fnbuf, "%s.tmp", archive_file); | 42 sprintf(fnbuf, "%s.tmp", archive_file); |
43 | 43 |
44 f = fopen(archive_file, "r+"); | 44 f = fopen(archive_file, "rb+"); |
45 if (!f) | 45 if (!f) |
46 { | 46 { |
47 if (errno == ENOENT) | 47 if (errno == ENOENT) |
48 { | 48 { |
49 nf = fopen(fnbuf, "w"); | 49 nf = fopen(fnbuf, "wb"); |
50 if (nf) | 50 if (nf) |
51 { | 51 { |
52 fputs("LWAR1V", nf); | 52 fputs("LWAR1V", nf); |
53 goto doadd; | 53 goto doadd; |
54 } | 54 } |
61 { | 61 { |
62 fprintf(stderr, "%s is not a valid archive file.\n", archive_file); | 62 fprintf(stderr, "%s is not a valid archive file.\n", archive_file); |
63 exit(1); | 63 exit(1); |
64 } | 64 } |
65 | 65 |
66 nf = fopen(fnbuf, "w"); | 66 nf = fopen(fnbuf, "wb"); |
67 if (!nf) | 67 if (!nf) |
68 { | 68 { |
69 perror("Cannot create temp archive file"); | 69 perror("Cannot create temp archive file"); |
70 exit(1); | 70 exit(1); |
71 } | 71 } |
144 // done with the original file | 144 // done with the original file |
145 fclose(f); | 145 fclose(f); |
146 doadd: | 146 doadd: |
147 for (i = 0; i < nfiles; i++) | 147 for (i = 0; i < nfiles; i++) |
148 { | 148 { |
149 f2 = fopen(files[i], "r"); | 149 f2 = fopen(files[i], "rb"); |
150 if (!f2) | 150 if (!f2) |
151 { | 151 { |
152 fprintf(stderr, "Cannot open file %s:", files[i]); | 152 fprintf(stderr, "Cannot open file %s:", files[i]); |
153 perror(""); | 153 perror(""); |
154 exit(1); | 154 exit(1); |