bin2c.c 743 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Unloved program to convert a binary on stdin to a C include on stdout
  3. *
  4. * Jan 1999 Matt Mackall <mpm@selenic.com>
  5. *
  6. * This software may be used and distributed according to the terms
  7. * of the GNU General Public License, incorporated herein by reference.
  8. */
  9. #include <stdio.h>
  10. int main(int argc, char *argv[])
  11. {
  12. int ch, total = 0;
  13. if (argc > 1)
  14. printf("const char %s[] %s=\n",
  15. argv[1], argc > 2 ? argv[2] : "");
  16. do {
  17. printf("\t\"");
  18. while ((ch = getchar()) != EOF) {
  19. total++;
  20. printf("\\x%02x", ch);
  21. if (total % 16 == 0)
  22. break;
  23. }
  24. printf("\"\n");
  25. } while (ch != EOF);
  26. if (argc > 1)
  27. printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
  28. argv[1], total);
  29. return 0;
  30. }