diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-08-27T18·34-0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-08-27T18·34-0400 |
commit | 15e1b2c223494ecb5efefc3ea0e3b926a6b1d7dc (patch) | |
tree | 49c0c914a6d3d02f54150bfaba3731aa9b98d720 /src/libutil | |
parent | a9e6752bbd888ab8fbc1cda6e4d539b2858c4cef (diff) | |
parent | 9e2fc6951ca049b15149a2c4b75d2f5bff7f07e1 (diff) |
Merge branch 'no-manifests'
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 9 | ||||
-rw-r--r-- | src/libutil/util.hh | 4 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index fe4fedfa597d..56bf5875deaa 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -253,7 +253,7 @@ string readLine(int fd) if (errno != EINTR) throw SysError("reading a line"); } else if (rd == 0) - throw Error("unexpected EOF reading a line"); + throw EndOfFile("unexpected EOF reading a line"); else { if (ch == '\n') return s; s += ch; @@ -1010,6 +1010,13 @@ string concatStringsSep(const string & sep, const Strings & ss) } +string chomp(const string & s) +{ + size_t i = s.find_last_not_of(" \n\r\t"); + return i == string::npos ? "" : string(s, 0, i + 1); +} + + string statusToString(int status) { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 22992bbafee7..0616288cd541 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -294,6 +294,10 @@ Strings tokenizeString(const string & s, const string & separators = " \t\n\r"); string concatStringsSep(const string & sep, const Strings & ss); +/* Remove trailing whitespace from a string. */ +string chomp(const string & s); + + /* Convert the exit status of a child as returned by wait() into an error string. */ string statusToString(int status); |