-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
36 lines (31 loc) · 698 Bytes
/
Copy pathutils.c
File metadata and controls
36 lines (31 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/random.h>
#include <errno.h>
#include "monocypher/monocypher.h"
void _free(void* buf, int bufsize)
{
if (buf != NULL) {
crypto_wipe(buf, bufsize);
free(buf);
}
}
int _fclose(FILE **fp)
{
int rv = fclose(*fp);
*fp = NULL;
return rv;
}
int _read(FILE* fp, uint8_t *buf, size_t bufsize)
{
return fread(buf, 1, bufsize, fp) == bufsize ? 0 : -1;
}
int _write(FILE* fp, const uint8_t *buf, size_t bufsize)
{
return (fwrite(buf, 1, bufsize, fp) == bufsize && errno == 0) ? 0 : -1;
}
int _random(uint8_t *buf, size_t bufsize)
{
return getrandom(buf, bufsize, 0) == -1 ? -1 : 0;
}