diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-13 09:44:19 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-13 09:44:19 +0000 |
commit | 35c9206be7f1b2e26b0db6599f072fb717811828 (patch) | |
tree | a7b9ed93861518887fe43e421dba1b57fb60f064 /crawl-ref/source/files.cc | |
parent | a7ec8acdf62d1f02f1b16587ea8cdd67517f4451 (diff) | |
download | crawl-ref-35c9206be7f1b2e26b0db6599f072fb717811828.tar.gz crawl-ref-35c9206be7f1b2e26b0db6599f072fb717811828.zip |
Stash-tracker now also keeps track of inscriptions and item origins (finally).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@625 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/files.cc')
-rw-r--r-- | crawl-ref/source/files.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index fe39797abf..5653948834 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -2127,22 +2127,33 @@ unsigned char readByte(FILE *file) return byte; } -void writeString(FILE* file, const std::string &s) +void writeString(FILE* file, const std::string &s, int cap) { int length = s.length(); - if (length > STR_CAP) length = STR_CAP; + if (length > cap) + length = cap; writeShort(file, length); write2(file, s.c_str(), length); } std::string readString(FILE *file) { - char buf[STR_CAP + 1]; short length = readShort(file); - if (length) - read2(file, buf, length); - buf[length] = 0; - return std::string(buf); + if (length > 0) + { + if (length <= STR_CAP) + { + char buf[STR_CAP + 1]; + read2(file, buf, length); + buf[length] = 0; + return (buf); + } + + fprintf(stderr, "String too long: %d bytes\n", length); + end(1); + } + + return (""); } void writeLong(FILE* file, long num) |