Message-ID: <3ED25E99.DB2873C3@yahoo.com> Date: Mon, 26 May 2003 14:36:09 -0400 From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: djgpp-workers Subject: Ggets - Propose addition to 2.04 library Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com ggets (and fggets) is my (public domain) implementation of a safe gets(). It is available at: The following is an extract from ggets.h: /* fggets and ggets [which is fggets(ln, stdin)] set *ln to a buffer filled with the next complete line from the text stream f. The storage has been allocated within fggets, and is normally reduced to be an exact fit. The trailing \n has been removed, so the resultant line is ready for dumping with puts. The buffer will be as large as is required to hold the complete line. Note: this means a final file line without a \n terminator has an effective \n appended, as EOF occurs within the read. If no error occurs fggets returns 0. If an EOF occurs on the input file, EOF is returned. For memory allocation errors some positive value is returned. In this case *ln may point to a partial line. For other errors memory is freed and *ln is set to NULL. Freeing of assigned storage is the callers responsibility */ int fggets(char* *ln, FILE *f); #define ggets(ln) fggets(ln, stdin) ------------- end extract ---------- The interface is designed to minimize the requirements on the caller, which is why newbies use gets in the first place. Thus I rejected any pre-assigned buffer, which would prevent guaranteeing that the returned value is suitable for free() or realloc(). To separate EOF and other errors from the normal return requires more than a NULL error return. Like gets the returned string *always* has the terminating \n stripped barring an unterminated final line which has no such to strip. Although no other system known to me includes this routine, why shouldn't DJGPP pioneer here? Maybe it will catch on. It is not a large chunk of code. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net) Available for consulting/temporary embedded and systems. USE worldnet address!