TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / include / internal / stack_line_reader.h
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Reads a file line by line and stores the data on the stack. This allows
16 // parsing files in one go without allocating.
17 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_
18 #define CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_
19
20 #include <stdbool.h>
21
22 #include "cpu_features_macros.h"
23 #include "internal/string_view.h"
24
25 CPU_FEATURES_START_CPP_NAMESPACE
26
27 typedef struct {
28   char buffer[STACK_LINE_READER_BUFFER_SIZE];
29   StringView view;
30   int fd;
31   bool skip_mode;
32 } StackLineReader;
33
34 // Initializes a StackLineReader.
35 void StackLineReader_Initialize(StackLineReader* reader, int fd);
36
37 typedef struct {
38   StringView line;  // A view of the line.
39   bool eof;         // Nothing more to read, we reached EOF.
40   bool full_line;   // If false the line was truncated to
41                     // STACK_LINE_READER_BUFFER_SIZE.
42 } LineResult;
43
44 // Reads the file pointed to by fd and tries to read a full line.
45 LineResult StackLineReader_NextLine(StackLineReader* reader);
46
47 CPU_FEATURES_END_CPP_NAMESPACE
48
49 #endif  // CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_