1 /* temp.c - Temporary file registry
3 * Copyright 1992-1998 Werner Almesberger
4 * Copyright 1999-2006 John Coffman
5 * Copyright 2009-2011 Joachim Wiedorn
8 * Licensed under the terms contained in the file 'COPYING'
9 * in the source directory.
25 typedef struct _temp {
31 static TEMP *list = NULL;
34 void temp_register(char *name)
39 new->name = stralloc(name);
45 void temp_unregister(char *name)
49 for (walk = &list; *walk; walk = &(*walk)->next)
50 if (!strcmp(name,(*walk)->name)) {
57 die("Internal error: temp_unregister %s",name);
61 void temp_remove(void)
67 if (remove(list->name) < 0)
68 warn("(temp) %s: %s",list->name,strerror(errno));
69 else if (verbose>=2) printf("Removed temporary file %s\n",list->name);
78 #include <sys/types.h>
84 void process(char *file, char *name)
90 unsigned char data[NBUF];
92 if ((fd = open(file, O_RDONLY)) < 0) exit(1);
93 if (fstat(fd, &buf)) exit(1);
96 printf("struct { int size; unsigned char data[%d]; } %s = { %d, {",
99 nrd = (nchar>NBUF ? NBUF : nchar);
100 if (read(fd, data, nrd) != nrd) exit(1);
101 for (i=0; i<nrd; i++) {
102 printf("%c%3d", i?',':'\n', (int)data[i]);
105 if (nchar>0) printf(",");
115 printf("/* begin loader ***/\n");
117 process("first.b", "First");
118 process("second.b", "Second");
119 process("third.b", "Third");
120 process("bitmap.b", "Bitmap");
121 process("mbr.b", "Mbr");
122 process("mbr2.b", "Mbr2");
123 process("chain.b", "Chain");
125 printf("/*** end loader ***/\n");