summaryrefslogtreecommitdiff
path: root/pkg/syslinux/bin2c.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2017-03-02 19:19:53 -0800
committerMichael Forney <mforney@mforney.org>2017-03-02 19:21:41 -0800
commit05a28a284a7a8fac805b47ad787df84a612b9e6c (patch)
tree31e8c4ff158b4f7b2d50555960cb598f3fcad4fb /pkg/syslinux/bin2c.c
parent3270dbaa984ffad41caa210c59f90611e5d38cc6 (diff)
Add syslinux 6.03
For now just use the pre-compiled binaries, but build our own static extlinux.
Diffstat (limited to 'pkg/syslinux/bin2c.c')
-rw-r--r--pkg/syslinux/bin2c.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/pkg/syslinux/bin2c.c b/pkg/syslinux/bin2c.c
new file mode 100644
index 00000000..7dd6f1ec
--- /dev/null
+++ b/pkg/syslinux/bin2c.c
@@ -0,0 +1,64 @@
+#include <err.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+void
+usage(void)
+{
+ errx(2, "usage: bin2c tablename [align]");
+}
+
+int
+main(int argc, char *argv[])
+{
+ int fd;
+ char buf[4096], *s, *table_name;
+ ssize_t n;
+ size_t total = 0, pad, align = 0;
+ struct stat st;
+
+ switch (argc) {
+ case 3:
+ align = strtoul(argv[2], &s, 10);
+ if (*s)
+ usage();
+ case 2:
+ table_name = argv[1];
+ break;
+ default:
+ usage();
+ }
+
+ if (fstat(0, &st) < 0)
+ err(1, "fstat 0");
+
+ printf("unsigned char %s[] = {", table_name);
+
+ for (;;) {
+ n = read(0, buf, sizeof(buf));
+ if (n < 0)
+ err(1, "read");
+ if (n == 0)
+ break;
+ for (s = buf; s < buf + n; ++s) {
+ if (total++ % 8 == 0)
+ printf("\n\t");
+ printf("0x%02hhx,", *s);
+ }
+ }
+ if (align) {
+ for (pad = (total + (align - 1)) / align * align - total; pad; --pad) {
+ if (total++ % 8 == 0)
+ printf("\n\t");
+ printf("0x00,");
+ }
+ }
+
+ printf("\n};\n\nconst unsigned int %s_len = %zu;\n", table_name, total);
+ printf("\nconst int %s_mtime = %d;\n", table_name, st.st_mtime);
+
+ return 0;
+}