annotate lib-src/insert-data-in-exec.c @ 4601:7c7262c47538

Remove any reference to mocklisp as an active technology. lisp/ChangeLog addition: 2009-02-04 Aidan Kehoe <kehoea@parhasard.net> * help.el: (describe-function-1): * byte-optimize.el: Remove any reference to mocklisp as an active technology. man/ChangeLog addition: 2009-02-04 Aidan Kehoe <kehoea@parhasard.net> * xemacs/xemacs.texi (Top): * xemacs/misc.texi (Emulation): * xemacs/building.texi (Lisp Libraries): (Compiling Libraries): Remove any reference to mocklisp as an active technology. Also remove documentation of the related #'set-gosmacs-bindings, which is no longer available.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 04 Feb 2009 20:52:24 +0000
parents 261c5cd19207
children dfc9fe46c294
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
1 /* Copies the dump file inside the xemacs executable */
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
2
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
3 #include <stdio.h>
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
4 #include <stdlib.h>
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
5 #include <string.h>
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
6
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
7 static const unsigned char key[] = {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
8 255,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
9 6,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
10 1,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
11 2,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
12 3,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
13 4,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
14 255,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
15 3,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
16 9,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
17 62,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
18 255,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
19 10,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
20 4,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
21 61,
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
22 255
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
23 };
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
24
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
25 int main(int argc, char **argv)
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
26 {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
27 FILE *te, *xe, *dump;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
28 unsigned char *xed, *p;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
29 long size, size_dump, size1, i;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
30 long max_size, offset;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
31
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
32 char msg[65536];
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
33
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
34 if(argc != 6 && (argc != 3 || strcmp(argv[1], "-s"))) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
35 fprintf(stderr, "Usage:\n%s temacs xemacs.dmp xemacs size offset\n%s -s xemacs.dmp\n", argv[0], argv[0]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
36 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
37 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
38
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
39 if(argc == 3) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
40 sprintf(msg, "Opening %s failed", argv[2]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
41 dump = fopen(argv[2], "rb+");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
42 if(!dump) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
43 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
44 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
45 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
46
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
47 if(fseek(dump, 0, SEEK_END)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
48 perror("fseek end dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
49 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
50 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
51
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
52 size = ftell(dump);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
53 if(size == -1) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
54 perror("ftell dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
55 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
56 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
57
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
58 printf("%ld\n", size);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
59 exit(0);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
60 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
61
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
62
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
63 max_size = strtol(argv[4], 0, 10);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
64 offset = strtol(argv[5], 0, 10);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
65
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
66 sprintf(msg, "Opening %s failed", argv[1]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
67 te = fopen(argv[1], "rb");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
68 if(!te) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
69 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
70 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
71 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
72
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
73 if(fseek(te, 0, SEEK_END)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
74 perror("fseek end");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
75 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
76 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
77
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
78 size = ftell(te);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
79 if(size == -1) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
80 perror("ftell");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
81 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
82 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
83
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
84 if(fseek(te, 0, SEEK_SET)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
85 perror("fseek beginning");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
86 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
87 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
88
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
89 xed = malloc(size);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
90 if(!xed) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
91 perror("malloc");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
92 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
93 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
94
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
95 size1 = fread(xed, 1, size, te);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
96 if(size1 != size) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
97 if(ferror(te)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
98 perror("fread temacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
99 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
100 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
101 fprintf(stderr, "Fread returned %ld, expected %ld ?\n", size1, size);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
102 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
103 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
104
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
105 if(fclose(te)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
106 perror("fclose temacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
107 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
108 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
109
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
110 p = xed;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
111 for(i=0; i<size-(long)sizeof(key); i++) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
112 if(!memcmp(p, key, sizeof(key)))
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
113 goto found;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
114 p++;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
115 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
116
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
117 fprintf(stderr, "dumped_data key not found in executable.\n");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
118 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
119
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
120 found:
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
121 fprintf(stderr, "dumped_data found at offset 0x%lx, patching.\n", i);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
122
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
123 sprintf(msg, "Opening %s failed", argv[2]);
2502
261c5cd19207 [xemacs-hg @ 2005-01-26 03:40:10 by ben]
ben
parents: 2022
diff changeset
124 dump = fopen(argv[2], "rb");
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
125 if(!dump) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
126 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
127 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
128 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
129
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
130 if(fseek(dump, 0, SEEK_END)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
131 perror("fseek end dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
132 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
133 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
134
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
135 size_dump = ftell(dump);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
136 if(size_dump == -1) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
137 perror("ftell dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
138 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
139 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
140
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
141 if(size_dump > max_size) {
2022
d31a2df82ddb [xemacs-hg @ 2004-04-17 13:29:19 by olivierg]
olivierg
parents: 2015
diff changeset
142 fprintf(stderr, "Dump file too big for available space (max=%ld, dump=%ld)\n", max_size, size_dump);
2015
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
143 exit(2);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
144 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
145
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
146 if(fseek(dump, 0, SEEK_SET)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
147 perror("fseek beginning dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
148 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
149 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
150
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
151 size1 = fread(xed+i+offset, 1, size_dump, dump);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
152 if(size1 != size_dump) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
153 if(ferror(dump)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
154 perror("fread dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
155 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
156 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
157 fprintf(stderr, "Fread dump returned %ld, expected %ld ?\n", size1, size_dump);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
158 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
159 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
160
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
161 if(fclose(dump)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
162 perror("fclose dump");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
163 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
164 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
165
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
166 memset(xed+i, 0, offset);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
167
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
168 xed[i ] = size_dump;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
169 xed[i+1] = size_dump >> 8;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
170 xed[i+2] = size_dump >> 16;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
171 xed[i+3] = size_dump >> 24;
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
172
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
173 fprintf(stderr, "dumped_data found at offset 0x%lx, patching.\n", i);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
174
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
175 sprintf(msg, "Opening %s failed", argv[3]);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
176 xe = fopen(argv[3], "wb");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
177 if(!xe) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
178 perror(msg);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
179 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
180 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
181
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
182 size1 = fwrite(xed, 1, size, xe);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
183 if(size1 != size) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
184 if(ferror(xe)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
185 perror("fwrite xemacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
186 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
187 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
188 fprintf(stderr, "Fwrite xemacs returned %ld, expected %ld ?\n", size1, size);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
189 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
190 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
191
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
192 if(fclose(xe)) {
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
193 perror("fclose xemacs");
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
194 exit(1);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
195 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
196
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
197 exit(0);
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
198 }
2364237fbc0f [xemacs-hg @ 2004-04-15 20:56:17 by olivierg]
olivierg
parents:
diff changeset
199