forked from FFmpeg/FFmpeg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecret_enc.c
51 lines (42 loc) · 998 Bytes
/
secret_enc.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
50
51
#ifndef __SECRET_ENC_H__
#define __SECRET_ENC_H__
#include <stdlib.h>
#include <stdio.h>
struct secret
{
unsigned int size;
char* data;
};
struct secret* copy_secret (const char*);
struct secret* copy_secret (const char *name)
{
FILE *file;
unsigned int file_len;
struct secret* ret = NULL;
//open file
file = fopen (name, "rb");
if (!file)
{
av_log (NULL, AV_LOG_ERROR, "Unable to open file %s", name);
return NULL;
}
//Get file length
fseek (file, 0, SEEK_END);
file_len = ftell (file);
fseek (file, 0, SEEK_SET);
//Allocate memory
ret = (struct secret *) av_malloc (sizeof (struct secret));
ret->data = (char*) av_malloc (file_len + 1);
if (!ret)
{
av_log (NULL, AV_LOG_ERROR, "Memory error!");
fclose (file);
return NULL;
}
//Read file contents into buffer
fread (ret->data, file_len, 1, file);
ret->size = file_len;
fclose (file);
return ret;
}
#endif /* __SECRET_ENC_H__ */