Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Unified Diff: third_party/android_crazy_linker/src/src/crazy_linker_line_reader.h

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/android_crazy_linker/src/src/crazy_linker_line_reader.h
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.h b/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..fda9053020130060382c23ced854275ce979bce0
--- /dev/null
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.h
@@ -0,0 +1,59 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CRAZY_LINKER_LINE_READER_H
+#define CRAZY_LINKER_LINE_READER_H
+
+#include <string.h>
+
+#include "crazy_linker_system.h"
+
+namespace crazy {
+
+// A class used to read text files line-by-line.
+// Usage:
+// LineReader reader("/path/to/file");
+// while (reader.GetNextLine()) {
+// const char* line = reader.line();
+// size_t line_len = reader.length();
+// ... line is not necessarily zero-terminated.
+// }
+
+class LineReader {
+ public:
+ LineReader();
+ explicit LineReader(const char* path);
+ ~LineReader();
+
+ // Open a new file for testing. Doesn't fail. If there was an error
+ // opening the file, GetNextLine() will simply return false.
+ void Open(const char* file_path);
+
+ // Grab next line. Returns true on success, or false otherwise.
+ bool GetNextLine();
+
+ // Return the start of the current line, this is _not_ zero-terminated
+ // and always contains a final newline (\n).
+ // Only call this after a successful GetNextLine().
+ const char* line() const;
+
+ // Return the line length, this includes the final \n.
+ // Only call this after a successful GetNextLine().
+ size_t length() const;
+
+ private:
+ void Reset(bool eof);
+
+ FileDescriptor fd_;
+ bool eof_;
+ size_t line_start_;
+ size_t line_len_;
+ size_t buff_size_;
+ size_t buff_capacity_;
+ char* buff_;
+};
+
+} // namespace crazy
+
+#endif // CRAZY_LINKER_LINE_READER_H

Powered by Google App Engine
This is Rietveld 408576698