diff options
author | Kenneth Heafield <github@kheafield.com> | 2014-06-02 21:28:02 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2014-06-02 21:29:40 +0400 |
commit | dd03f9fb69da82a37f1846d25dcc8d8781956e96 (patch) | |
tree | 12df06240d6149f110982d1f76c9addf40acbce1 /util/file.hh | |
parent | 31a583b0bc322626356a42965f02534249070525 (diff) |
KenLM 5a7efd8fe1db88ee0a9f7e9479b24ac3ca348221 with Hieu's patch to exception.hh
Diffstat (limited to 'util/file.hh')
-rw-r--r-- | util/file.hh | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/util/file.hh b/util/file.hh index be88431dd..f2bb319d5 100644 --- a/util/file.hh +++ b/util/file.hh @@ -1,7 +1,8 @@ -#ifndef UTIL_FILE__ -#define UTIL_FILE__ +#ifndef UTIL_FILE_H +#define UTIL_FILE_H #include "util/exception.hh" +#include "util/string_piece.hh" #include <cstddef> #include <cstdio> @@ -106,12 +107,20 @@ void ResizeOrThrow(int fd, uint64_t to); std::size_t PartialRead(int fd, void *to, std::size_t size); void ReadOrThrow(int fd, void *to, std::size_t size); std::size_t ReadOrEOF(int fd, void *to_void, std::size_t size); -// Positioned: unix only for now. -void PReadOrThrow(int fd, void *to, std::size_t size, uint64_t off); void WriteOrThrow(int fd, const void *data_void, std::size_t size); void WriteOrThrow(FILE *to, const void *data, std::size_t size); +/* These call pread/pwrite in a loop. However, on Windows they call ReadFile/ + * WriteFile which changes the file pointer. So it's safe to call ErsatzPRead + * and ErsatzPWrite concurrently (or any combination thereof). But it changes + * the file pointer on windows, so it's not safe to call concurrently with + * anything that uses the implicit file pointer e.g. the Read/Write functions + * above. + */ +void ErsatzPRead(int fd, void *to, std::size_t size, uint64_t off); +void ErsatzPWrite(int fd, const void *data_void, std::size_t size, uint64_t off); + void FSyncOrThrow(int fd); // Seeking @@ -125,8 +134,8 @@ std::FILE *FDOpenReadOrThrow(scoped_fd &file); // Temporary files // Append a / if base is a directory. void NormalizeTempPrefix(std::string &base); -int MakeTemp(const std::string &prefix); -std::FILE *FMakeTemp(const std::string &prefix); +int MakeTemp(const StringPiece &prefix); +std::FILE *FMakeTemp(const StringPiece &prefix); // dup an fd. int DupOrThrow(int fd); @@ -139,4 +148,4 @@ std::string NameFromFD(int fd); } // namespace util -#endif // UTIL_FILE__ +#endif // UTIL_FILE_H |