/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/fgetline.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:39 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: fgetline.c,v $ * Revision 1.2 2002/10/07 09:37:39 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:56 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/fgetline.c,v 1.2 2002/10/07 09:37:39 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include /* ------------------------------------------------------------------ Defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Structure definitions ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Global variables ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Function prototypes ------------------------------------------------------------------ */ /* --------------------------------------------------------------------------- Function : fget_line Summary : This function returns a line from a file, having : removed the trailing EOL character Input Parameters : FILE pointer : Pointer to line buffer : length of line buffer Output Parameters : None Global Variables : None Return Value : 0 = success, <> 0 failure (of some description) --------------------------------------------------------------------------*/ int fgetline( FILE *fh, char *line_buf, int line_len ) { int rv; char *cp; if (fgets(line_buf,line_len,fh) != NULL) { /* remove any trailing newline characters */ if (strlen(line_buf)) { cp = line_buf + strlen(line_buf) - 1; while ( cp >= line_buf && *cp == '\n') *cp-- = '\0'; } rv = 0; }else rv = -1; return(rv); } /* -- End of File -- */