comparison lib-src/cvtmail.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents cc15677e0335
children 697ef44129c6
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
33 * 33 *
34 * Author: Larry Kolodney, 1985 34 * Author: Larry Kolodney, 1985
35 */ 35 */
36 36
37 37
38 #include <../src/config.h> 38 #include <config.h>
39 39
40 #include <stdio.h> 40 #include <stdio.h>
41 #include <string.h> 41 #include <string.h>
42 #include <stdlib.h>
42 43
43 #if __STDC__ || defined(STDC_HEADERS) 44 static void *xmalloc (size_t);
44 # include <stdlib.h> 45 static void *xrealloc (void *, size_t);
45 #else
46 char *malloc ();
47 char *getenv ();
48 #endif
49 static void *xmalloc (unsigned int);
50 static void *xrealloc (char *ptr, unsigned int);
51 static void skip_to_lf (FILE *stream); 46 static void skip_to_lf (FILE *stream);
52 static void fatal (CONST char *s1, CONST char *s2); 47 static void fatal (const char *s1, const char *s2);
53 static void error (CONST char *s1, CONST char *s2); 48 static void error (const char *s1, const char *s2);
54 49
55 int 50 int
56 main (argc, argv) 51 main (int argc, char *argv[])
57 int argc;
58 char *argv[];
59 { 52 {
60 char *hd; 53 char *hd;
61 char *md; 54 char *md;
62 char *mdd; 55 char *mdd;
63 char *mfile; 56 char *mfile;
68 FILE *cff; 61 FILE *cff;
69 char pre[10]; 62 char pre[10];
70 char name[14]; 63 char name[14];
71 int c; 64 int c;
72 65
73 hd = (char *) getenv ("HOME"); 66 hd = getenv ("HOME");
74 67
75 md = (char *) xmalloc (strlen (hd) + 10); 68 md = (char *) xmalloc (strlen (hd) + 10);
76 strcpy (md, hd); 69 strcpy (md, hd);
77 strcat (md, "/Messages"); 70 strcat (md, "/Messages");
78 71
116 fclose (mfilef); 109 fclose (mfilef);
117 return 0; 110 return 0;
118 } 111 }
119 112
120 static void 113 static void
121 skip_to_lf (stream) 114 skip_to_lf (FILE *stream)
122 FILE *stream;
123 { 115 {
124 register int c; 116 register int c;
125 while ((c = getc(stream)) != '\n') 117 while ((c = getc(stream)) != '\n')
126 ; 118 ;
127 } 119 }
128 120
129 static void * 121 static void *
130 xmalloc (size) 122 xmalloc (size_t size)
131 unsigned size;
132 { 123 {
133 char *result = (char *) malloc (size); 124 void *result = malloc (size);
134 if (!result) 125 if (!result)
135 fatal ("virtual memory exhausted", 0); 126 fatal ("virtual memory exhausted", 0);
136 return result; 127 return result;
137 } 128 }
138 129
139 static void * 130 static void *
140 xrealloc (ptr, size) 131 xrealloc (void *ptr, size_t size)
141 char *ptr;
142 unsigned size;
143 { 132 {
144 char *result = (char *) realloc (ptr, size); 133 void *result = realloc (ptr, size);
145 if (!result) 134 if (!result)
146 fatal ("virtual memory exhausted", 0); 135 fatal ("virtual memory exhausted", 0);
147 return result; 136 return result;
148 } 137 }
149 138
150 /* Print error message and exit. */ 139 /* Print error message and exit. */
151 140
152 static void 141 static void
153 fatal (CONST char *s1, CONST char *s2) 142 fatal (const char *s1, const char *s2)
154 { 143 {
155 error (s1, s2); 144 error (s1, s2);
156 exit (1); 145 exit (1);
157 } 146 }
158 147
159 static void 148 static void
160 error (CONST char *s1, CONST char *s2) 149 error (const char *s1, const char *s2)
161 { 150 {
162 fprintf (stderr, "cvtmail: "); 151 fprintf (stderr, "cvtmail: ");
163 fprintf (stderr, s1, s2); 152 fprintf (stderr, s1, s2);
164 fprintf (stderr, "\n"); 153 fprintf (stderr, "\n");
165 } 154 }