MCPcopy Create free account
hub / github.com/NetHack/NetHack / lib_dlb_fgets

Function lib_dlb_fgets

src/dlb.c:348–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346}
347
348staticfn char *
349lib_dlb_fgets(char *buf, int len, dlb *dp)
350{
351 int i;
352 char *bp, c = 0;
353
354 if (len <= 0)
355 return buf; /* sanity check */
356
357 /* return NULL on EOF */
358 if (dp->mark >= dp->size)
359 return (char *) 0;
360
361 len--; /* save room for null */
362 for (i = 0, bp = buf; i < len && dp->mark < dp->size && c != '\n';
363 i++, bp++) {
364 if (dlb_fread(bp, 1, 1, dp) <= 0)
365 break; /* EOF or error */
366 c = *bp;
367 }
368 *bp = '\0';
369
370#if defined(MSDOS) || defined(WIN32)
371 if ((bp = strchr(buf, '\r')) != 0) {
372 *bp++ = '\n';
373 *bp = '\0';
374 }
375#endif
376
377 return buf;
378}
379
380staticfn int
381lib_dlb_fgetc(dlb *dp)

Callers

nothing calls this directly

Calls 1

dlb_freadFunction · 0.85

Tested by

no test coverage detected