summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-15 01:12:53 +0200
committerClifford Wolf <clifford@clifford.at>2014-10-15 01:12:53 +0200
commitc3e9922b5d871269bf4ee33da24318d3b5199ac3 (patch)
tree74d252566f1ab890069e3e37b5b0a5776c5a5e4a
parentcf85aab62f961c905e4691fde59af774053d3d58 (diff)
Replaced readsome() with read() and gcount()
-rw-r--r--frontends/verilog/preproc.cc8
-rw-r--r--kernel/yosys.cc16
-rw-r--r--kernel/yosys.h1
-rw-r--r--passes/cmds/write_file.cc9
4 files changed, 11 insertions, 23 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index b4e77c31..da658410 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -196,14 +196,16 @@ static std::string next_token(bool pass_newline = false)
static void input_file(std::istream &f, std::string filename)
{
char buffer[513];
- int rc;
insert_input("");
auto it = input_buffer.begin();
input_buffer.insert(it, "`file_push " + filename + "\n");
- while ((rc = readsome(f, buffer, sizeof(buffer)-1)) > 0) {
- buffer[rc] = 0;
+ while (1) {
+ f.read(buffer, sizeof(buffer)-1);
+ if (f.gcount() <= 0)
+ break;
+ buffer[f.gcount()] = 0;
input_buffer.insert(it, buffer);
}
input_buffer.insert(it, "\n`file_pop\n");
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index e50bfcbe..ba3049c5 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -172,22 +172,6 @@ bool patmatch(const char *pattern, const char *string)
return false;
}
-int readsome(std::istream &f, char *s, int n)
-{
- int rc = f.readsome(s, n);
-
- // win32 sometimes returns 0 on a non-empty stream..
- if (rc == 0) {
- int c = f.get();
- if (c != EOF) {
- *s = c;
- rc = 1;
- }
- }
-
- return rc;
-}
-
int run_command(const std::string &command, std::function<void(const std::string&)> process_line)
{
if (!process_line)
diff --git a/kernel/yosys.h b/kernel/yosys.h
index 37d3e52f..83230cbf 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -94,7 +94,6 @@ std::string stringf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))
std::string vstringf(const char *fmt, va_list ap);
std::string next_token(std::string &text, const char *sep);
bool patmatch(const char *pattern, const char *string);
-int readsome(std::istream &f, char *s, int n);
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
diff --git a/passes/cmds/write_file.cc b/passes/cmds/write_file.cc
index 3f441972..9bf1a75a 100644
--- a/passes/cmds/write_file.cc
+++ b/passes/cmds/write_file.cc
@@ -68,10 +68,13 @@ struct WriteFileFrontend : public Frontend {
FILE *of = fopen(output_filename.c_str(), append_mode ? "a" : "w");
char buffer[64 * 1024];
- size_t bytes;
- while (0 < (bytes = readsome(*f, buffer, sizeof(buffer))))
- fwrite(buffer, bytes, 1, of);
+ while (1) {
+ f->read(buffer, sizeof(buffer));
+ if (f->gcount() <= 0)
+ break;
+ fwrite(buffer, f->gcount(), 1, of);
+ }
fclose(of);
}