-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.c
49 lines (38 loc) · 1.05 KB
/
main.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
\file main.c
\author Eremin Dmitry (http://github.com/NeonMercury)
\date October, 2015
\brief Examples loader.
*/
#include "jfes.h"
#include "examples/examples.h"
/* Only for file functions. */
#include <stdio.h>
/** Entry point. */
int main(int argc, char **argv) {
return example_3_entry(argc, argv);
}
int set_file_content(const char *filename, const char *content, unsigned long content_size) {
if (!filename || !content || content_size == 0) {
return 0;
}
FILE *f = fopen(filename, "w");
if (!f) {
return 0;
}
int result = (int)fwrite(content, sizeof(char), content_size, f);
fclose(f);
return result;
}
int get_file_content(const char *filename, char *content, unsigned long *max_content_size) {
if (!filename || !content || !max_content_size || *max_content_size == 0) {
return 0;
}
FILE *f = fopen(filename, "r");
if (!f) {
return 0;
}
*max_content_size = fread(content, sizeof(char), *max_content_size, f);
fclose(f);
return 1;
}