Changeset 16901
- Timestamp:
- Mar 9, 2008, 9:10:57 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/gprint.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/gprint.c
r15791 r16901 146 146 } 147 147 148 148 149 void gprintSetFile (gpStream *stream, gpDest dest, char *filename) { 150 151 int i, Nmatch; 152 FILE *file; 149 153 150 154 /* if we have an open buffer, free it and null it */ … … 155 159 } 156 160 157 /* if we have an open file, flush it and close it */ 158 if (stream[0].file != NULL) { 159 fflush (stream[0].file); 160 if (stream[0].file == stdout) goto skip_close; 161 if (stream[0].file == stderr) goto skip_close; 162 fclose (stream[0].file); 163 } 164 skip_close: 161 stream[0].mode = GP_FILE; 165 162 166 163 // if NULL, reuse exising stream name … … 173 170 if (!strcmp (stream[0].name, "stdout")) { 174 171 stream[0].file = stdout; 175 goto skip_open;172 return; 176 173 } 177 174 if (!strcmp (stream[0].name, "stderr")) { 178 175 stream[0].file = stderr; 179 goto skip_open; 180 } 181 182 /* open the file */ 183 stream[0].file = fopen (stream[0].name, "a"); 184 if (stream[0].file == NULL) { 176 return; 177 } 178 179 // open the file : use a local FILE pointer. only close old pointer if no one else is 180 // using it 181 file = fopen (stream[0].name, "a"); 182 if (file == NULL) { 185 183 fprintf (stderr, "cannot open file %s\n", stream[0].name); 186 184 free (stream[0].name); 187 185 stream[0].file = (dest == GP_LOG) ? stdout : stderr; 188 186 stream[0].name = (dest == GP_LOG) ? strcreate ("stdout") : strcreate("stderr"); 189 } 190 191 skip_open: 192 stream[0].mode = GP_FILE; 187 return; 188 } 189 190 /* check the special cases */ 191 if (stream[0].file == stdout) { 192 stream[0].file = file; 193 return; 194 } 195 if (stream[0].file == stderr) { 196 stream[0].file = file; 197 return; 198 } 199 200 /* must we close the existing file? */ 201 if (stream[0].file != NULL) { 202 Nmatch = 0; 203 for (i = 0; i < Nstreams; i++) { 204 if (streams[i].file == stream[0].file) Nmatch ++; 205 } 206 if (file == stream[0].file) Nmatch ++; 207 if (Nmatch == 1) { 208 fflush (stream[0].file); 209 fclose (stream[0].file); 210 } 211 stream[0].file = file; 212 } 193 213 return; 194 214 }
Note:
See TracChangeset
for help on using the changeset viewer.
