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 #include "android/utils/compiler.h"
     18 
     19 ANDROID_BEGIN_HEADER
     20 
     21 /* A LineInput is used to read input text, one line at a time,
     22  * into a temporary buffer owner by the LineInput object.
     23  */
     24 typedef struct LineInput LineInput;
     25 
     26 /* Create a LineInput object that reads from a FILE* object */
     27 LineInput*  lineInput_newFromStdFile( FILE* file );
     28 
     29 /* Read next line from input. The result is zero-terminated with
     30  * all newlines removed (\n, \r or \r\n) automatically.
     31  *
     32  * Returns NULL in case of error, or when the end of file is reached.
     33  * See lineInput_isEof() and lineInput_getError()
     34  *
     35  * The returned string is owned by the LineInput object and its
     36  * value will not persist any other call to any LineInput functions.
     37  */
     38 const char* lineInput_getLine( LineInput* input );
     39 
     40 /* Same as lineInput_getLine(), but also returns the line size into
     41  * '*pSize' to save you a strlen() call.
     42  */
     43 const char* lineInput_getLineAndSize( LineInput* input, size_t *pSize );
     44 
     45 /* Returns the number of the last line read by lineInput_getLine */
     46 int lineInput_getLineNumber( LineInput* input );
     47 
     48 /* Returns TRUE iff the end of file was reached */
     49 int lineInput_isEof( LineInput* input );
     50 
     51 /* Return the error condition of a LineInput object.
     52  * These are standard errno code for the last operation.
     53  * Note: EOF corresponds to 0 here.
     54  */
     55 int lineInput_getError( LineInput* input );
     56 
     57 /* Free a LineInput object. */
     58 void lineInput_free( LineInput* input );
     59 
     60 ANDROID_END_HEADER
     61 
     62 #endif /* _ANDROID_UTILS_LINEINPUT_H */
     63