Skip to content

Commit

Permalink
add vector_fread
Browse files Browse the repository at this point in the history
  • Loading branch information
salix5 committed Nov 29, 2024
1 parent c99159b commit 65bd779
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions buffer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CORE_BUFFER_H
#define CORE_BUFFER_H

#include <cstdio>
#include <cstring>
#include <vector>

Expand Down Expand Up @@ -34,4 +35,11 @@ inline void vector_write(std::vector<unsigned char>& buffer, T value) {
vector_write_block(buffer, &value, sizeof(T));
}

inline void vector_fread(std::vector<unsigned char>& buffer, FILE* fp) {
unsigned char temp[4096]{};
while (size_t len = std::fread(temp, 1, sizeof temp, fp))
vector_write_block(buffer, temp, len);
std::fclose(fp);
}

#endif // !CORE_BUFFER_H

0 comments on commit 65bd779

Please sign in to comment.