Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site sdcsvax.UUCP Path: utzoo!linus!decvax!ittatc!dcdwest!sdcsvax!davidson From: davidson@sdcsvax.UUCP (J. Greg Davidson) Newsgroups: net.sources Subject: Re: Routine to read arbitrary lenght lines from a stdio file desc. Message-ID: <1261@sdcsvax.UUCP> Date: Fri, 27-Dec-85 01:21:11 EST Article-I.D.: sdcsvax.1261 Posted: Fri Dec 27 01:21:11 1985 Date-Received: Sat, 28-Dec-85 12:58:54 EST References: <219@ucbjade.BERKELEY.EDU> Reply-To: davidson@sdcsvax.UUCP (J. Greg Davidson) Distribution: net Organization: EECS Dept. U.C. San Diego Lines: 48 Keywords: readline, getstr Summary: Here's a simpler solution #include char * readline( fd ) FILE *fd; /* Reads the next line ending in '\n' or EOF from fd. Stores it, NUL terminated, into a malloc'ed string array. Returns the address of the string. - greg@vis.UUCP ( J. Greg Davidson Virtual Infinity Systems, San Diego ) */ { char *rdln(); return rdln( fd, (unsigned) 1); } static char * rdln( fd, l ) FILE *fd; unsigned l; /* See readline. Call with l == 1. */ { int c; char *p; char *malloc(); c = getc( fd ); if (c == '\n' || c == EOF) { p = malloc( l ) + l; *--p = '\0'; } else { p = rdln( fd, l + 1 ); *--p = c; } return p; } /* J. Greg Davidson Virtual Infinity Systems (619) 452-8059 6231 Branting St; San Diego, CA 92122 greg@vis.uucp ucbvax--| telesoft--| davidson@sdcsvax.uucp decvax--+--sdcsvax--+--vis davidson@ucsd.arpa ihnp4--| noscvax--| */