comparison lib-src/fakemail.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 84b14dcb0985
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
114 * and works regardless of the length of the line. 114 * and works regardless of the length of the line.
115 */ 115 */
116 116
117 struct linebuffer 117 struct linebuffer
118 { 118 {
119 long size; 119 size_t size;
120 char *buffer; 120 char *buffer;
121 }; 121 };
122 122
123 struct linebuffer lb; 123 struct linebuffer lb;
124 124
188 exit (1); 188 exit (1);
189 } 189 }
190 190
191 /* Like malloc but get fatal error if memory is exhausted. */ 191 /* Like malloc but get fatal error if memory is exhausted. */
192 192
193 static char * 193 static void *
194 xmalloc (size_t size) 194 xmalloc (size_t size)
195 { 195 {
196 char *result = (char *) malloc (size); 196 void *result = malloc (size);
197 if (result == ((char *) NULL)) 197 if (result == NULL)
198 fatal ("virtual memory exhausted", (char *) 0); 198 fatal ("virtual memory exhausted", (char *) 0);
199 return result; 199 return result;
200 } 200 }
201 201
202 static char * 202 static void *
203 xrealloc (char *ptr, size_t size) 203 xrealloc (void *ptr, size_t size)
204 { 204 {
205 char *result = realloc (ptr, ((unsigned) size)); 205 void *result = realloc (ptr, size);
206 if (result == ((char *) NULL)) 206 if (result == NULL)
207 fatal ("virtual memory exhausted", (char *) 0); 207 fatal ("virtual memory exhausted", (char *) 0);
208 return result; 208 return result;
209 } 209 }
210 210
211 /* Initialize a linebuffer for use */ 211 /* Initialize a linebuffer for use */
212 212
213 static void 213 static void
214 init_linebuffer (struct linebuffer *linebuffer) 214 init_linebuffer (struct linebuffer *linebuffer)
215 { 215 {
216 linebuffer->size = INITIAL_LINE_SIZE; 216 linebuffer->size = INITIAL_LINE_SIZE;
217 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); 217 linebuffer->buffer = (char *) xmalloc (INITIAL_LINE_SIZE);
218 } 218 }
219 219
220 /* Read a line of text from `stream' into `linebuffer'. 220 /* Read a line of text from `stream' into `linebuffer'.
221 * Return the length of the line. 221 * Return the length of the line.
222 */ 222 */
232 { 232 {
233 int c = getc (stream); 233 int c = getc (stream);
234 if (p == end) 234 if (p == end)
235 { 235 {
236 linebuffer->size *= 2; 236 linebuffer->size *= 2;
237 buffer = ((char *) xrealloc ((char *) buffer, 237 buffer = (char *) xrealloc (buffer, linebuffer->size);
238 (size_t) (linebuffer->size)));
239 p = buffer + (p - linebuffer->buffer); 238 p = buffer + (p - linebuffer->buffer);
240 end = buffer + linebuffer->size; 239 end = buffer + linebuffer->size;
241 linebuffer->buffer = buffer; 240 linebuffer->buffer = buffer;
242 } 241 }
243 if (c < 0 || c == '\n') 242 if (c < 0 || c == '\n')
277 276
278 static boolean 277 static boolean
279 has_keyword (char *field) 278 has_keyword (char *field)
280 { 279 {
281 char *ignored; 280 char *ignored;
282 return (get_keyword (field, &ignored) != ((char *) NULL)); 281 return (get_keyword (field, &ignored) != (char *) NULL);
283 } 282 }
284 283
285 static char * 284 static char *
286 add_field (line_list the_list, register char *field, register char *where) 285 add_field (line_list the_list, register char *field, register char *where)
287 { 286 {
398 { 397 {
399 FILE *the_stream = fopen (name, "a"); 398 FILE *the_stream = fopen (name, "a");
400 if (the_stream != ((FILE *) NULL)) 399 if (the_stream != ((FILE *) NULL))
401 { 400 {
402 add_a_stream (the_stream, my_fclose); 401 add_a_stream (the_stream, my_fclose);
403 if (the_user == ((char *) NULL)) 402 if (the_user == (char *) NULL)
404 file_preface = make_file_preface (); 403 file_preface = make_file_preface ();
405 write_line_list (file_preface, the_stream); 404 write_line_list (file_preface, the_stream);
406 return true; 405 return true;
407 } 406 }
408 return false; 407 return false;
643 mail_program_name = (char *) MAIL_PROGRAM_NAME; 642 mail_program_name = (char *) MAIL_PROGRAM_NAME;
644 name_length = strlen (mail_program_name); 643 name_length = strlen (mail_program_name);
645 644
646 my_name = MY_NAME; 645 my_name = MY_NAME;
647 the_streams = ((stream_list) NULL); 646 the_streams = ((stream_list) NULL);
648 the_date = ((char *) NULL); 647 the_date = (char *) NULL;
649 the_user = ((char *) NULL); 648 the_user = (char *) NULL;
650 649
651 the_header = read_header (); 650 the_header = read_header ();
652 command_line = alloc_string ((size_t) (name_length + 651 command_line = alloc_string ((size_t) (name_length +
653 args_size (the_header))); 652 args_size (the_header)));
654 strcpy (command_line, mail_program_name); 653 strcpy (command_line, mail_program_name);
655 parse_header (the_header, &command_line[name_length]); 654 parse_header (the_header, &command_line[name_length]);
656 655
657 the_pipe = popen (command_line, "w"); 656 the_pipe = popen (command_line, "w");
658 if (the_pipe == ((FILE *) NULL)) 657 if (the_pipe == ((FILE *) NULL))
659 fatal ("cannot open pipe to real mailer", (char *) 0); 658 fatal ("cannot open pipe to real mailer", (char *) NULL);
660 659
661 add_a_stream (the_pipe, pclose); 660 add_a_stream (the_pipe, pclose);
662 661
663 write_header (the_header); 662 write_header (the_header);
664 663