| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: lib.c,v 1.2 2008/08/26 14:46:21 joerg Exp $ */ | | 1 | /* $NetBSD: lib.c,v 1.3 2008/08/26 20:26:25 joerg Exp $ */ |
2 | | | 2 | |
3 | /**************************************************************** | | 3 | /**************************************************************** |
4 | Copyright (C) Lucent Technologies 1997 | | 4 | Copyright (C) Lucent Technologies 1997 |
5 | All Rights Reserved | | 5 | All Rights Reserved |
6 | | | 6 | |
7 | Permission to use, copy, modify, and distribute this software and | | 7 | Permission to use, copy, modify, and distribute this software and |
8 | its documentation for any purpose and without fee is hereby | | 8 | its documentation for any purpose and without fee is hereby |
9 | granted, provided that the above copyright notice appear in all | | 9 | granted, provided that the above copyright notice appear in all |
10 | copies and that both that the copyright notice and this | | 10 | copies and that both that the copyright notice and this |
11 | permission notice and warranty disclaimer appear in supporting | | 11 | permission notice and warranty disclaimer appear in supporting |
12 | documentation, and that the name Lucent Technologies or any of | | 12 | documentation, and that the name Lucent Technologies or any of |
13 | its entities not be used in advertising or publicity pertaining | | 13 | its entities not be used in advertising or publicity pertaining |
14 | to distribution of the software without specific, written prior | | 14 | to distribution of the software without specific, written prior |
| @@ -183,26 +183,28 @@ void nextfile(void) | | | @@ -183,26 +183,28 @@ void nextfile(void) |
183 | argno++; | | 183 | argno++; |
184 | } | | 184 | } |
185 | | | 185 | |
186 | int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf */ | | 186 | int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf */ |
187 | { | | 187 | { |
188 | int sep, c; | | 188 | int sep, c; |
189 | char *rr, *buf = *pbuf; | | 189 | char *rr, *buf = *pbuf; |
190 | int bufsize = *pbufsize; | | 190 | int bufsize = *pbufsize; |
191 | size_t len; | | 191 | size_t len; |
192 | | | 192 | |
193 | if ((len = strlen(*FS)) <= len_inputFS) { | | 193 | if ((len = strlen(*FS)) <= len_inputFS) { |
194 | strcpy(inputFS, *FS); /* for subsequent field splitting */ | | 194 | strcpy(inputFS, *FS); /* for subsequent field splitting */ |
195 | } else { | | 195 | } else { |
| | | 196 | if (inputFS != static_inputFS) |
| | | 197 | free(inputFS); |
196 | inputFS = malloc(len + 1); | | 198 | inputFS = malloc(len + 1); |
197 | if (inputFS == NULL) | | 199 | if (inputFS == NULL) |
198 | FATAL("field separator %.10s... is too long", *FS); | | 200 | FATAL("field separator %.10s... is too long", *FS); |
199 | len_inputFS = len; | | 201 | len_inputFS = len; |
200 | memcpy(inputFS, *FS, len + 1); | | 202 | memcpy(inputFS, *FS, len + 1); |
201 | } | | 203 | } |
202 | if ((sep = **RS) == 0) { | | 204 | if ((sep = **RS) == 0) { |
203 | sep = '\n'; | | 205 | sep = '\n'; |
204 | while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ | | 206 | while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ |
205 | ; | | 207 | ; |
206 | if (c != EOF) | | 208 | if (c != EOF) |
207 | ungetc(c, inf); | | 209 | ungetc(c, inf); |
208 | } | | 210 | } |