| 15 | #include "CommonLib.h" |
| 16 | |
| 17 | CHAR8 * |
| 18 | ReadLine ( |
| 19 | IN MEMORY_FILE *InputFile, |
| 20 | IN OUT CHAR8 *InputBuffer, |
| 21 | IN UINTN MaxLength |
| 22 | ) |
| 23 | /*++ |
| 24 | |
| 25 | Routine Description: |
| 26 | |
| 27 | This function reads a line, stripping any comments. |
| 28 | The function reads a string from the input stream argument and stores it in |
| 29 | the input string. ReadLine reads characters from the current file position |
| 30 | to and including the first newline character, to the end of the stream, or |
| 31 | until the number of characters read is equal to MaxLength - 1, whichever |
| 32 | comes first. The newline character, if read, is replaced with a \0. |
| 33 | |
| 34 | Arguments: |
| 35 | |
| 36 | InputFile Memory file image. |
| 37 | InputBuffer Buffer to read into, must be MaxLength size. |
| 38 | MaxLength The maximum size of the input buffer. |
| 39 | |
| 40 | Returns: |
| 41 | |
| 42 | NULL if error or EOF |
| 43 | InputBuffer otherwise |
| 44 | |
| 45 | --*/ |
| 46 | { |
| 47 | CHAR8 *CharPtr; |
| 48 | CHAR8 *EndOfLine; |
| 49 | UINTN CharsToCopy; |
| 50 | |
| 51 | // |
| 52 | // Verify input parameters are not null |
| 53 | // |
| 54 | assert (InputBuffer); |
| 55 | assert (InputFile->FileImage); |
| 56 | assert (InputFile->Eof); |
| 57 | assert (InputFile->CurrentFilePointer); |
| 58 | |
| 59 | // |
| 60 | // Check for end of file condition |
| 61 | // |
| 62 | if (InputFile->CurrentFilePointer >= InputFile->Eof) { |
| 63 | return NULL; |
| 64 | } |
| 65 | // |
| 66 | // Find the next newline char |
| 67 | // |
| 68 | EndOfLine = strchr (InputFile->CurrentFilePointer, '\n'); |
| 69 | |
| 70 | // |
| 71 | // Determine the number of characters to copy. |
| 72 | // |
| 73 | if (EndOfLine == 0) { |
| 74 | // |
no test coverage detected