#include #include #include #include #include #include void usage(void); int main(int argc, char *argv[]) { int fd, rc; unsigned char buf; int col = 0; if(argc != 2) { usage(); } fd = open(argv[1], O_RDONLY); if(fd == -1) err(1, "Open of file `%s' failed", argv[1]); while(read(fd, &buf, sizeof(unsigned char)) != -1) { if(col + 6 >= 80) { printf("\n"); col = 0; } col += printf("0x%.2hhx, ", buf); } rc = close(fd); if(rc == -1) warn("Close of file `%s' failed", argv[1]); return 0; } void usage(void) { fprintf(stderr, "Usage: bin2c FILE\n" "Dumps a file in a format suitable for inclusion into a C source file.\n\n" "Send bug reports to Jason Spence \n" ); exit(1); }