Commit 6dcfaf12 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] Remove various unused IO functions from utils.h

Removes the following functions:
Flush
AppendChars
WriteAsCFile (only from header since impl was already removed)

and moves local function AppendChars into anonymous namespace block.

Bug: v8:9810
Change-Id: Icc3ca8458eed4711f25514ac71aa0e6b413ed281
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1921797
Auto-Submit: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65292}
parent b8b60750
...@@ -133,8 +133,6 @@ void StrNCpy(Vector<char> dest, const char* src, size_t n) { ...@@ -133,8 +133,6 @@ void StrNCpy(Vector<char> dest, const char* src, size_t n) {
base::OS::StrNCpy(dest.begin(), dest.length(), src, n); base::OS::StrNCpy(dest.begin(), dest.length(), src, n);
} }
void Flush(FILE* out) { fflush(out); }
char* ReadLine(const char* prompt) { char* ReadLine(const char* prompt) {
char* result = nullptr; char* result = nullptr;
char line_buf[256]; char line_buf[256];
...@@ -229,18 +227,6 @@ std::string VectorToString(const std::vector<char>& chars) { ...@@ -229,18 +227,6 @@ std::string VectorToString(const std::vector<char>& chars) {
return std::string(chars.begin(), chars.end()); return std::string(chars.begin(), chars.end());
} }
} // namespace
std::string ReadFile(const char* filename, bool* exists, bool verbose) {
std::vector<char> result = ReadCharsFromFile(filename, exists, verbose);
return VectorToString(result);
}
std::string ReadFile(FILE* file, bool* exists, bool verbose) {
std::vector<char> result = ReadCharsFromFile(file, exists, verbose, "");
return VectorToString(result);
}
int WriteCharsToFile(const char* str, int size, FILE* f) { int WriteCharsToFile(const char* str, int size, FILE* f) {
int total = 0; int total = 0;
while (total < size) { while (total < size) {
...@@ -254,17 +240,16 @@ int WriteCharsToFile(const char* str, int size, FILE* f) { ...@@ -254,17 +240,16 @@ int WriteCharsToFile(const char* str, int size, FILE* f) {
return total; return total;
} }
int AppendChars(const char* filename, const char* str, int size, bool verbose) { } // namespace
FILE* f = base::OS::FOpen(filename, "ab");
if (f == nullptr) { std::string ReadFile(const char* filename, bool* exists, bool verbose) {
if (verbose) { std::vector<char> result = ReadCharsFromFile(filename, exists, verbose);
base::OS::PrintError("Cannot open file %s for writing.\n", filename); return VectorToString(result);
} }
return 0;
} std::string ReadFile(FILE* file, bool* exists, bool verbose) {
int written = WriteCharsToFile(str, size, f); std::vector<char> result = ReadCharsFromFile(file, exists, verbose, "");
fclose(f); return VectorToString(result);
return written;
} }
int WriteChars(const char* filename, const char* str, int size, bool verbose) { int WriteChars(const char* filename, const char* str, int size, bool verbose) {
......
...@@ -574,20 +574,10 @@ V8_EXPORT_PRIVATE int PRINTF_FORMAT(2, 0) ...@@ -574,20 +574,10 @@ V8_EXPORT_PRIVATE int PRINTF_FORMAT(2, 0)
void StrNCpy(Vector<char> dest, const char* src, size_t n); void StrNCpy(Vector<char> dest, const char* src, size_t n);
// Our version of fflush.
void Flush(FILE* out);
inline void Flush() { Flush(stdout); }
// Read a line of characters after printing the prompt to stdout. The resulting // Read a line of characters after printing the prompt to stdout. The resulting
// char* needs to be disposed off with DeleteArray by the caller. // char* needs to be disposed off with DeleteArray by the caller.
char* ReadLine(const char* prompt); char* ReadLine(const char* prompt);
// Append size chars from str to the file given by filename.
// The file is overwritten. Returns the number of chars written.
int AppendChars(const char* filename, const char* str, int size,
bool verbose = true);
// Write size chars from str to the file given by filename. // Write size chars from str to the file given by filename.
// The file is overwritten. Returns the number of chars written. // The file is overwritten. Returns the number of chars written.
int WriteChars(const char* filename, const char* str, int size, int WriteChars(const char* filename, const char* str, int size,
...@@ -598,13 +588,6 @@ int WriteChars(const char* filename, const char* str, int size, ...@@ -598,13 +588,6 @@ int WriteChars(const char* filename, const char* str, int size,
int WriteBytes(const char* filename, const byte* bytes, int size, int WriteBytes(const char* filename, const byte* bytes, int size,
bool verbose = true); bool verbose = true);
// Write the C code
// const char* <varname> = "<str>";
// const int <varname>_len = <len>;
// to the file given by filename. Only the first len chars are written.
int WriteAsCFile(const char* filename, const char* varname, const char* str,
int size, bool verbose = true);
// Simple support to read a file into std::string. // Simple support to read a file into std::string.
// On return, *exits tells whether the file existed. // On return, *exits tells whether the file existed.
V8_EXPORT_PRIVATE std::string ReadFile(const char* filename, bool* exists, V8_EXPORT_PRIVATE std::string ReadFile(const char* filename, bool* exists,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment