annotate src/unexenix.c @ 4407:4ee73bbe4f8e

Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings. 2007-12-26 Aidan Kehoe <kehoea@parhasard.net> * casetab.c: Extend and correct some case table documentation. * search.c (search_buffer): Correct a bug where only the first entry for a character in the case equivalence table was examined in determining if the Boyer-Moore search algorithm is appropriate. If there are case mappings outside of the charset and row of the characters specified in the search string, those case mappings can be safely ignored (and Boyer-Moore search can be used) if we know from the buffer statistics that the corresponding characters cannot occur. * search.c (boyer_moore): Assert that we haven't been passed a string with varying characters sets or rows within character sets. That's what simple_search is for. In the very rare event that a character in the search string has a canonical case mapping that is not in the same character set and row, don't try to search for the canonical character, search for some other character that is in the the desired character set and row. Assert that the case table isn't corrupt. Do not search for any character case mappings that cannot possibly occur in the buffer, given the buffer metadata about its contents.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 26 Dec 2007 17:30:16 +0100
parents 04bc9d2f42c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Unexec for Xenix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1988, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.31. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 On 80386 Xenix, segmentation screws prevent us from modifying the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 segment at all. We basically just plug a new value for "data segment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 size" into the countless headers and copy the other records straight
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 through. The data segment is ORG'ed at the xs_rbase value of the data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 segment's xseg record (always @ 0x1880000, thanks to the "sophisticated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 memory management hardware" of the chip) and extends to sbrk(0), exactly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 This code is afraid to malloc (should it be?), and alloca has to be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 wimpy, malloc-based version; consequently, data is usually copied in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 smallish chunks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 gb@entity.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include <sys/file.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include <varargs.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include <a.out.h>
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 0
diff changeset
47 #include "compiler.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 static void fatal_unexec ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 errno = EEOF; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 if (read(_fd, _buffer, _size) != _size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 fatal_unexec(_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 if (write(_fd, _buffer, _size) != _size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 fatal_unexec(_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #define SEEK(_fd, _position, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 errno = EEOF; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 if (lseek(_fd, _position, L_SET) != _position) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 fatal_unexec(_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 extern char *strerror ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #define EEOF -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 #ifndef L_SET
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #define L_SET 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 /* Should check the magic number of the old executable;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 not yet written. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 check_exec (x)
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 0
diff changeset
76 struct xexec *UNUSED (x);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 unexec (new_name, a_name, data_start, bss_start, entry_address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 char *new_name, *a_name;
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 0
diff changeset
83 unsigned UNUSED (data_start);
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 0
diff changeset
84 unsigned UNUSED (bss_start);
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 0
diff changeset
85 unsigned UNUSED (entry_address);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 char *sbrk (), *datalim = sbrk (0), *data_org;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 long segpos, textseen, textpos, textlen, datapos, datadiff, datalen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 struct xexec u_xexec, /* a.out header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 *u_xexecp = &u_xexec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 struct xext u_xext, /* extended header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 *u_xextp = &u_xext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 struct xseg u_xseg, /* segment table entry */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 *u_xsegp = &u_xseg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 int i, nsegs, isdata = 0, infd, outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 infd = open (a_name, O_RDONLY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 if (infd < 0) fatal_unexec ("opening %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 outfd = creat (new_name, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 if (outfd < 0) fatal_unexec ("creating %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 READ (infd, u_xexecp, sizeof (struct xexec),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "error reading %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 check_exec (u_xexecp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 READ (infd, u_xextp, sizeof (struct xext),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "error reading %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 segpos = u_xextp->xe_segpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 nsegs = u_xextp->xe_segsize / sizeof (struct xseg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 SEEK (infd, segpos, "seek error on %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 for (i = 0; i < nsegs; i ++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 READ (infd, u_xsegp, sizeof (struct xseg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "error reading %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 switch (u_xsegp->xs_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 case XS_TTEXT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 if (i == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 textpos = u_xsegp->xs_filpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 textlen = u_xsegp->xs_psize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 fatal_unexec ("invalid text segment in %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 case XS_TDATA:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 if (i == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 datapos = u_xsegp->xs_filpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 datalen = datalim - (data_org = (char *)(u_xsegp->xs_rbase));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 datadiff = datalen - u_xsegp->xs_psize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 fatal_unexec ("invalid data segment in %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 if (i > 1) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 fatal_unexec ("invalid segment record in %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 u_xexecp->x_data = datalen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 u_xexecp->x_bss = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 WRITE (outfd, u_xexecp, sizeof (struct xexec),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "error writing %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 WRITE (outfd, u_xextp, sizeof (struct xext),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "error writing %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 SEEK (infd, segpos, "seek error on %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 SEEK (outfd, segpos, "seek error on %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 /* Copy the text segment record verbatim. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 copyrec (infd, outfd, sizeof (struct xseg), a_name, new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* Read, modify, write the data segment record. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 READ (infd, u_xsegp, sizeof (struct xseg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "error reading %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 u_xsegp->xs_psize = u_xsegp->xs_vsize = datalen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 u_xsegp->xs_attr &= (~XS_AITER & ~XS_ABSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 WRITE (outfd, u_xsegp, sizeof (struct xseg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "error writing %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 /* Now copy any additional segment records, adjusting their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 file position field */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 for (i = 2; i < nsegs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 READ (infd, u_xsegp, sizeof (struct xseg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "error reading %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 u_xsegp->xs_filpos += datadiff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 WRITE (outfd, u_xsegp, sizeof (struct xseg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "error writing %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 SEEK (infd, textpos, "seek error on %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 SEEK (outfd, textpos, "seek error on %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 copyrec (infd, outfd, textlen, a_name, new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 SEEK (outfd, datapos, "seek error on %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 WRITE (outfd, data_org, datalen,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 "write error on %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 for (i = 2, segpos += (2 * sizeof (struct xseg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 i < nsegs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 i++, segpos += sizeof (struct xseg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 SEEK (infd, segpos, "seek error on %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 READ (infd, u_xsegp, sizeof (struct xseg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "read error on %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 SEEK (infd, u_xsegp->xs_filpos, "seek error on %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 /* We should be at eof in the output file here, but we must seek
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 because the xs_filpos and xs_psize fields in symbol table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 segments are inconsistent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 SEEK (outfd, u_xsegp->xs_filpos + datadiff, "seek error on %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 copyrec (infd, outfd, u_xsegp->xs_psize, a_name, new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 close (infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 close (outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 mark_x (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 copyrec (infd, outfd, len, in_name, out_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 int infd, outfd, len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 char *in_name, *out_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 char buf[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 int chunk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 while (len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 chunk = BUFSIZ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 if (chunk > len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 chunk = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 READ (infd, buf, chunk, "error reading %s", in_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 WRITE (outfd, buf, chunk, "error writing %s", out_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 len -= chunk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 * mark_x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 * After successfully building the new a.out, mark it executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 static
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 mark_x (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 struct stat sbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 int um = umask (777);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 umask (um);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 if (stat (name, &sbuf) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 fatal_unexec ("getting protection on %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 sbuf.st_mode |= 0111 & ~um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 if (chmod (name, sbuf.st_mode) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 fatal_unexec ("setting protection on %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 fatal_unexec (s, va_alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 va_dcl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 va_list ap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (errno == EEOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 fputs ("unexec: unexpected end of file, ", stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 fprintf (stderr, "unexec: %s, ", strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 va_start (ap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 _doprnt (s, ap, stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 fputs (".\n", stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }