Mercurial > libedl
comparison README.md @ 12:0cc2555db371
*: make our string functions not stupid
strncat() made everything slow!
new addition internally: an EDL_header structure to make things
not stupid. if we were using C++ it wouldn't really be necessary,
but alas :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 27 Mar 2024 13:38:30 -0400 |
parents | 0c98b46eaf73 |
children |
comparison
equal
deleted
inserted
replaced
11:a0bd92c4c0e8 | 12:0cc2555db371 |
---|---|
16 #include <stdio.h> | 16 #include <stdio.h> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 | 18 |
19 #include <edl.h> | 19 #include <edl.h> |
20 | 20 |
21 int file_get_contents(const char* file, char** contents, long* size) { | 21 int file_get_contents(const char* f, char** contents, long* size) { |
22 /* open the file */ | 22 /* open the file */ |
23 FILE* file = fopen(file, "rb"); | 23 FILE* file = fopen(f, "rb"); |
24 if (!file) | 24 if (!file) |
25 return 1; | 25 return 1; |
26 | 26 |
27 /* get filesize */ | 27 /* get filesize */ |
28 fseek(file, 0L, SEEK_END); | 28 fseek(file, 0L, SEEK_END); |
35 return 1; | 35 return 1; |
36 | 36 |
37 /* hope and pray that `char` is 8-bit */ | 37 /* hope and pray that `char` is 8-bit */ |
38 fread(*contents, *size, 1, file); | 38 fread(*contents, *size, 1, file); |
39 | 39 |
40 data[*size] = '\0'; | 40 (*contents)[*size] = '\0'; |
41 | 41 |
42 fclose(file); | 42 fclose(file); |
43 } | 43 } |
44 | 44 |
45 int main(int argc, char** argv) { | 45 int main(int argc, char** argv) { |
59 | 59 |
60 /* pass the file data to libedl | 60 /* pass the file data to libedl |
61 * | 61 * |
62 * it is also perfectly valid to use mmap() or | 62 * it is also perfectly valid to use mmap() or |
63 * variations of it (ex MapViewOfFile()) here... */ | 63 * variations of it (ex MapViewOfFile()) here... */ |
64 EDL_parse(&edl, data, fsize + 1); | 64 EDL_parse(&edl, data, size + 1); |
65 | 65 |
66 /* dump the data to a valid EDL string */ | 66 /* dump the data to a valid EDL string */ |
67 char* edl_str = EDL_dump(&edl); | 67 char* edl_str = EDL_dump(&edl); |
68 printf("%s\n", edl_str); | 68 printf("%s\n", edl_str); |
69 free(edl_str); | 69 free(edl_str); |