Add toollib files for oxfs tool

This commit is contained in:
2017-10-11 16:34:35 -05:00
parent 6ae08fe259
commit 9d563d2736
2 changed files with 47 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <iostream>
#include <string.h>
#include "toollib.hpp"
uint8_t *loadFileBuff(FILE *file, ::size_t *sizeOut) {
if (file) {
fseek(file, 0, SEEK_END);
const auto size = ftell(file);
rewind(file);
auto buff = new uint8_t[size];
auto itemsRead = fread(buff, size, 1, file);
fclose(file);
if (sizeOut) {
*sizeOut = itemsRead ? size : 0;
}
return buff;
} else {
return nullptr;
}
}
uint8_t *loadFileBuff(const char *path, ::size_t *sizeOut) {
return loadFileBuff(fopen(path, "rb"), sizeOut);
}
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <stdio.h>
#include <stdlib.h>
uint8_t *loadFileBuff(FILE *file, size_t *sizeOut = nullptr);
uint8_t *loadFileBuff(const char *path, size_t *sizeOut = nullptr);