summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-23 10:47:21 +0200
committerClifford Wolf <clifford@clifford.at>2014-10-23 10:58:36 +0200
commitc5eb5e56b8911bb520a987761739bbb9d9328380 (patch)
tree6a578b95c4bc007bb87928df299f90391abfcc07 /kernel
parent750c615e7f01d44db4a7d504024b3681a56d8a78 (diff)
Re-introduced Yosys::readsome() helper function
(f.read() + f.gcount() made problems with lines > 16kB)
Diffstat (limited to 'kernel')
-rw-r--r--kernel/yosys.cc16
-rw-r--r--kernel/yosys.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index ad0aa5a6..d4365ee0 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -97,6 +97,22 @@ std::string vstringf(const char *fmt, va_list ap)
return string;
}
+int readsome(std::istream &f, char *s, int n)
+{
+ int rc = f.readsome(s, n);
+
+ // f.readsome() sometimes returns 0 on a non-empty stream..
+ if (rc == 0) {
+ int c = f.get();
+ if (c != EOF) {
+ *s = c;
+ rc = 1;
+ }
+ }
+
+ return rc;
+}
+
std::string next_token(std::string &text, const char *sep)
{
size_t pos_begin = text.find_first_not_of(sep);
diff --git a/kernel/yosys.h b/kernel/yosys.h
index b9182c1d..11f356ad 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -127,6 +127,7 @@ namespace RTLIL {
std::string stringf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
std::string vstringf(const char *fmt, va_list ap);
+int readsome(std::istream &f, char *s, int n);
std::string next_token(std::string &text, const char *sep);
bool patmatch(const char *pattern, const char *string);
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());