MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / createFile

Function createFile

test/other/test_truncate_from_0.cpp:59–83  ·  view source on GitHub ↗

Helper to create a file with the given content.

Source from the content-addressed store, hash-verified

57
58 // Helper to create a file with the given content.
59 void createFile(const std::string& path, const std::string& content)
60 {
61 std::cout
62 << "Creating file: " << path << " with content=" << content << endl;
63
64 const int fd = ::open(path.c_str(), O_CREAT | O_WRONLY, 0644);
65 if (fd == -1) {
66 const int error = errno;
67 std::cout
68 << "Failed to open file for writing: " << path << "; errno=" << error
69 << "; " << std::strerror(error) << endl;
70 return;
71 }
72
73 if (::write(fd, content.c_str(), content.size()) != content.size()) {
74 const int error = errno;
75 std::cout
76 << "Failed to write content=" << content << " to file=" << path
77 << "; errno=" << error << "; " << std::strerror(error) << endl;
78
79 // Fall through to close FD.
80 }
81
82 ::close(fd);
83 }
84}
85
86//============================================================================

Callers 2

mainFunction · 0.70
libfs.jsFile · 0.50

Calls 6

strerrorFunction · 0.85
sizeMethod · 0.65
openFunction · 0.50
writeFunction · 0.50
closeFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected