Home | History | Annotate | Download | only in utils
      1 /* Copyright (C) 2011 The Android Open Source Project
      2 **
      3 ** This software is licensed under the terms of the GNU General Public
      4 ** License version 2, as published by the Free Software Foundation, and
      5 ** may be copied, distributed, and modified under those terms.
      6 **
      7 ** This program is distributed in the hope that it will be useful,
      8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 ** GNU General Public License for more details.
     11 */
     12 #ifndef _ANDROID_UTILS_LINEINPUT_H
     13 #define _ANDROID_UTILS_LINEINPUT_H
     14 
     15 #include <stdio.h>
     16 
     17 /* A LineInput is used to read input text, one line at a time,
     18  * into a temporary buffer owner by the LineInput object.
     19  */
     20 typedef struct LineInput LineInput;
     21 
     22 /* Create a LineInput object that reads from a FILE* object */
     23 LineInput*  lineInput_newFromStdFile( FILE* file );
     24 
     25 /* Read next line from input. The result is zero-terminated with
     26  * all newlines removed (\n, \r or \r\n) automatically.
     27  *
     28  * Returns NULL in case of error, or when the end of file is reached.
     29  * See lineInput_isEof() and lineInput_getError()
     30  *
     31  * The returned string is owned by the LineInput object and its
     32  * value will not persist any other call to any LineInput functions.
     33  */
     34 const char* lineInput_getLine( LineInput* input );
     35 
     36 /* Same as lineInput_getLine(), but also returns the line size into
     37  * '*pSize' to save you a strlen() call.
     38  */
     39 const char* lineInput_getLineAndSize( LineInput* input, size_t *pSize );
     40 
     41 /* Returns the number of the last line read by lineInput_getLine */
     42 int lineInput_getLineNumber( LineInput* input );
     43 
     44 /* Returns TRUE iff the end of file was reached */
     45 int lineInput_isEof( LineInput* input );
     46 
     47 /* Return the error condition of a LineInput object.
     48  * These are standard errno code for the last operation.
     49  * Note: EOF corresponds to 0 here.
     50  */
     51 int lineInput_getError( LineInput* input );
     52 
     53 /* Free a LineInput object. */
     54 void lineInput_free( LineInput* input );
     55 
     56 #endif /* _ANDROID_UTILS_LINEINPUT_H */
     57