keyfile
This commit is contained in:
parent
ac8de4819c
commit
d34624e412
|
@ -0,0 +1,42 @@
|
|||
|
||||
#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);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
#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] )
|
||||
|
|
Loading…
Reference in New Issue