MCPcopy Create free account
hub / github.com/ElementsProject/elements / AddFile

Function AddFile

src/randomenv.cpp:135–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135void AddFile(CSHA512& hasher, const char *path)
136{
137 struct stat sb = {};
138 int f = open(path, O_RDONLY);
139 size_t total = 0;
140 if (f != -1) {
141 unsigned char fbuf[4096];
142 int n;
143 hasher.Write((const unsigned char*)&f, sizeof(f));
144 if (fstat(f, &sb) == 0) hasher << sb;
145 do {
146 n = read(f, fbuf, sizeof(fbuf));
147 if (n > 0) hasher.Write(fbuf, n);
148 total += n;
149 /* not bothering with EINTR handling. */
150 } while (n == sizeof(fbuf) && total < 1048576); // Read only the first 1 Mbyte
151 close(f);
152 }
153}
154
155void AddPath(CSHA512& hasher, const char *path)
156{

Callers 2

RandAddDynamicEnvFunction · 0.85
RandAddStaticEnvFunction · 0.85

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected