comparison th_ioctx.c @ 206:c2193323736d

Fix thfgets().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Feb 2016 00:16:49 +0200
parents 55f429dff750
children 3635415a2d03
comparison
equal deleted inserted replaced
205:c42a9c3f4d55 206:c2193323736d
211 } 211 }
212 212
213 213
214 char *thfgets(char *str, int size, th_ioctx *ctx) 214 char *thfgets(char *str, int size, th_ioctx *ctx)
215 { 215 {
216 char *ptr = str, *end = str + size - 1, c; 216 char *ptr = str, *end = str + size - 1;
217 int c;
217 218
218 if (size <= 0) 219 if (size <= 0)
219 return NULL; 220 return NULL;
220 221
221 while (ptr < end && (c = ctx->fops->fgetc(ctx)) != EOF) 222 while (ptr < end && (c = ctx->fops->fgetc(ctx)) != EOF)
222 { 223 {
223 *ptr++ = c; 224 *ptr++ = c;
224 if (c == '\n') 225 if (c == '\n')
225 break; 226 break;
226 } 227 }
227 *ptr++ = 0; 228 *ptr = 0;
228 229
229 return (ptr > str) ? str : NULL; 230 return (ptr > str) ? str : NULL;
230 } 231 }
231 232
232 233