This is an archive of the discontinued LLVM Phabricator instance.

Replace std::ofstream with llvm::raw_fd_ostream
ClosedPublic

Authored by labath on Mar 17 2017, 7:35 AM.

Details

Summary

ofstream does not handle paths with non-ascii characters correctly on
windows, so I am switching these to llvm streams to fix that.

Ideally I'd like to replace the two occurences of ifstream as well, but
it's not clear to me what is the right replacement, as llvm interfaces
seem to be based around reading the full file, which seems wasteful, if
all I'm going to do is to stream it to a socket.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Mar 17 2017, 7:35 AM
zturner accepted this revision.Mar 17 2017, 9:49 AM

In the places where you want to read from an ifstream and write to a socket, you might consider using llvm::sys::fs::copy_file, declared in Support/FileSystem.h. Currently it takes two paths, but all it does is call openFileForRead() on the first one and openFileForWrite() on the second one to get FDs. So you could probably add an overload that takes two FDs, and have the path version just call the FD version. Then you could call the FD version directly with an FD for your file and an FD for your socket.

This revision is now accepted and ready to land.Mar 17 2017, 9:49 AM
eugene accepted this revision.Mar 17 2017, 11:16 AM

In the places where you want to read from an ifstream and write to a socket, you might consider using llvm::sys::fs::copy_file, declared in Support/FileSystem.h. Currently it takes two paths, but all it does is call openFileForRead() on the first one and openFileForWrite() on the second one to get FDs. So you could probably add an overload that takes two FDs, and have the path version just call the FD version. Then you could call the FD version directly with an FD for your file and an FD for your socket.

Unfortunately, that won't be enough. I need to split the data into chunks and add a header before each chunk. I guess I'll just stick with LLDB's File class for now (?)

This revision was automatically updated to reflect the committed changes.