Commit d34624e4 authored by cRTrn13's avatar cRTrn13

keyfile

parent ac8de481
#include "keyfile.h"
#include "file.h"
#include "../util/macro.h"
uint8_t *_record(KEYFILE *kf, uint8_t type, size_t *rec_len);
uint8_t *_record(KEYFILE *kf, uint8_t type, size_t *rec_len)
{
return NULL;
}
KEYFILE *keyfile_open(const char *path)
{
FILE_H *fp = NULL;
KEYFILE *kf = malloc(sizeof(KEYFILE));
if ((fp = file_open(path, "rb"))) {
file_seek(fp, 0, SEEK_END);
kf->size = file_tell(fp);
file_seek(fp, 0, SEEK_SET);
kf->buf = malloc(kf->size);
file_read(fp, kf->buf, kf->size);
file_close(fp);
X_FREE(fp);
return kf;
}
return NULL;
}
void keyfile_close(KEYFILE *kf)
{
X_FREE(kf->buf);
X_FREE(kf);
}
#ifndef KEYFILE_H_
#define KEYFILE_H_
#include <stdint.h>
#include <unistd.h>
typedef struct keyfile KEYFILE;
struct keyfile {
size_t size;
uint8_t *buf;
};
KEYFILE *keyfile_open(const char *path);
void keyfile_close(KEYFILE *kf);
#endif /* KEYFILE_H_ */
......@@ -3,6 +3,7 @@
#define MACRO_H_
#include <stdio.h>
#include <malloc.h>
#define HEX_PRINT(X,Y) { int zz; for(zz = 0; zz < Y; zz++) fprintf(stderr, "%02X", X[zz]); fprintf(stderr, "\n"); }
#define MKINT_BE16(X) ( (X)[0] << 8 | (X)[1] )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment