diff options
| author | 2026-02-11 03:47:31 +0000 | |
|---|---|---|
| committer | 2026-02-11 03:47:31 +0000 | |
| commit | 4a355deb54b48eee5432ee617d6d3916121b0816 (patch) | |
| tree | 84678b21428af2089e359bc95b28ebc8a7fe19f6 /src/bake.c | |
| parent | add .gitignore (diff) | |
| download | spotlight-4a355deb54b48eee5432ee617d6d3916121b0816.tar.gz | |
add sources
Diffstat (limited to 'src/bake.c')
| -rw-r--r-- | src/bake.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/bake.c b/src/bake.c new file mode 100644 index 0000000..435d612 --- /dev/null +++ b/src/bake.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <sys/mman.h> | ||
| 5 | #include <sys/stat.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include <raylib.h> | ||
| 8 | |||
| 9 | #define FILENAME_INPUT "./res/spotlight.frag" | ||
| 10 | #define FILENAME_OUTPUT "./build/spotlight.frag.c" | ||
| 11 | |||
| 12 | int | ||
| 13 | main (int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | remove (FILENAME_OUTPUT); | ||
| 16 | |||
| 17 | int fd = open (FILENAME_INPUT, O_RDONLY); | ||
| 18 | if (fd == -1) { | ||
| 19 | perror ("open"); | ||
| 20 | return EXIT_FAILURE; | ||
| 21 | } | ||
| 22 | |||
| 23 | struct stat sb; | ||
| 24 | if (fstat (fd, &sb) == -1) { | ||
| 25 | perror ("fstat"); | ||
| 26 | close (fd); | ||
| 27 | return EXIT_FAILURE; | ||
| 28 | } | ||
| 29 | |||
| 30 | void *mapped = mmap (NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | ||
| 31 | if (mapped == MAP_FAILED) { | ||
| 32 | perror ("mmap"); | ||
| 33 | close (fd); | ||
| 34 | return EXIT_FAILURE; | ||
| 35 | } | ||
| 36 | |||
| 37 | if (!ExportDataAsCode (mapped, sb.st_size, FILENAME_OUTPUT)) { | ||
| 38 | perror ("raylib"); | ||
| 39 | close (fd); | ||
| 40 | return EXIT_FAILURE; | ||
| 41 | } | ||
| 42 | |||
| 43 | if (munmap (mapped, sb.st_size) == -1) | ||
| 44 | perror ("munmap"); | ||
| 45 | close (fd); | ||
| 46 | |||
| 47 | if (chmod (FILENAME_OUTPUT, S_IRUSR | S_IRGRP | S_IROTH) == -1) { | ||
| 48 | perror ("chmod"); | ||
| 49 | return EXIT_FAILURE; | ||
| 50 | } | ||
| 51 | |||
| 52 | return EXIT_SUCCESS; | ||
| 53 | } | ||
