BitLab
0.1.0
BitLab: A Browser for the Bitcoin P2P Network and Blockchain
Loading...
Searching...
No Matches
file.c
Go to the documentation of this file.
1
#include "
file.h
"
2
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
7
#include "
utils.h
"
8
9
void
read_file
(
const
char
* filename,
char
** buffer,
size_t
* size)
10
{
11
FILE* file = fopen(filename,
"r"
);
12
if
(file == NULL)
13
{
14
*buffer = NULL;
15
*size = 0;
16
return
;
17
}
18
19
fseek(file, 0, SEEK_END);
20
*size = ftell(file);
21
rewind(file);
22
23
*buffer = (
char
*)malloc(*size + 1);
24
if
(*buffer == NULL)
25
{
26
*size = 0;
27
fclose(file);
28
return
;
29
}
30
31
fread(*buffer, 1, *size, file);
32
(*buffer)[*size] =
'\0'
;
33
34
fclose(file);
35
}
36
37
void
write_file
(
const
char
* filename,
const
char
* buffer,
size_t
size)
38
{
39
FILE* file = fopen(filename,
"w"
);
40
if
(file == NULL)
41
return
;
42
43
fwrite(buffer, 1, size, file);
44
45
fclose(file);
46
}
47
48
void
append_file
(
const
char
* filename,
const
char
* buffer,
size_t
size)
49
{
50
FILE* file = fopen(filename,
"a"
);
51
if
(file == NULL)
52
return
;
53
54
fwrite(buffer, 1, size, file);
55
56
fclose(file);
57
}
read_file
void read_file(const char *filename, char **buffer, size_t *size)
Read the file.
Definition
file.c:9
append_file
void append_file(const char *filename, const char *buffer, size_t size)
Append the file.
Definition
file.c:48
write_file
void write_file(const char *filename, const char *buffer, size_t size)
Write the file.
Definition
file.c:37
file.h
utils.h
bitlab
src
file.c
Generated by
1.9.8