comparison output.c @ 24:daa801fe719e

fix some bugs
author David A. Holland
date Mon, 20 Dec 2010 04:30:02 -0500
parents cef2dc916269
children 01c3a2088ab4
comparison
equal deleted inserted replaced
23:fb83c2df2268 24:daa801fe719e
12 12
13 static 13 static
14 void 14 void
15 output_open(void) 15 output_open(void)
16 { 16 {
17 outputfd = open(mode.output_file, O_WRONLY|O_CREAT|O_TRUNC, 0664); 17 if (mode.output_file == NULL) {
18 if (outputfd < 0) { 18 outputfd = STDOUT_FILENO;
19 warn("%s", mode.output_file); 19 } else {
20 die(); 20 outputfd = open(mode.output_file, O_WRONLY|O_CREAT|O_TRUNC,
21 0664);
22 if (outputfd < 0) {
23 warn("%s", mode.output_file);
24 die();
25 }
21 } 26 }
22 } 27 }
23 28
24 static 29 static
25 void 30 void
98 pos--; 103 pos--;
99 continue; 104 continue;
100 } 105 }
101 } 106 }
102 } 107 }
108 pos++;
109
110 if (pos > start) {
111 if (!incomment || mode.output_retain_comments) {
112 dowrite(buf + start, pos - start);
113 }
114 }
103 } 115 }
104 116
105 void 117 void
106 output_eof(void) 118 output_eof(void)
107 { 119 {
108 if (outputfd >= 0) { 120 if (mode.output_file != NULL && outputfd >= 0) {
109 close(outputfd); 121 close(outputfd);
110 } 122 }
111 outputfd = -1; 123 outputfd = -1;
112 } 124 }