1*e7f34be0Stsutsui /* $NetBSD: exec_ecoff.c,v 1.7 2009/04/18 11:30:30 tsutsui Exp $ */
2b78496eeScgd
3b78496eeScgd /*
4db755e7cScgd * Copyright (c) 1997 Christopher G. Demetriou
5db755e7cScgd * All rights reserved.
6b78496eeScgd *
7b78496eeScgd * Redistribution and use in source and binary forms, with or without
8b78496eeScgd * modification, are permitted provided that the following conditions
9b78496eeScgd * are met:
10b78496eeScgd * 1. Redistributions of source code must retain the above copyright
11b78496eeScgd * notice, this list of conditions and the following disclaimer.
12b78496eeScgd * 2. Redistributions in binary form must reproduce the above copyright
13b78496eeScgd * notice, this list of conditions and the following disclaimer in the
14b78496eeScgd * documentation and/or other materials provided with the distribution.
15b78496eeScgd * 3. All advertising materials mentioning features or use of this software
16b78496eeScgd * must display the following acknowledgement:
17db755e7cScgd * This product includes software developed for the
180f5a0c15Ssalo * NetBSD Project. See http://www.NetBSD.org/ for
19db755e7cScgd * information about NetBSD.
20b78496eeScgd * 4. The name of the author may not be used to endorse or promote products
21db755e7cScgd * derived from this software without specific prior written permission.
22b78496eeScgd *
23b78496eeScgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24b78496eeScgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25b78496eeScgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26b78496eeScgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27b78496eeScgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28b78496eeScgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29b78496eeScgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30b78496eeScgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31b78496eeScgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32b78496eeScgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33db755e7cScgd *
34db755e7cScgd * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
35b78496eeScgd */
36b78496eeScgd
3788a54d8aSperry #include <sys/cdefs.h>
38b78496eeScgd #ifndef lint
39*e7f34be0Stsutsui __RCSID("$NetBSD: exec_ecoff.c,v 1.7 2009/04/18 11:30:30 tsutsui Exp $");
4088a54d8aSperry #endif
41b78496eeScgd
42b78496eeScgd #include <sys/types.h>
43b78496eeScgd #include <sys/stat.h>
447b941789Smikel
45b78496eeScgd #include <stdio.h>
46b78496eeScgd #include <string.h>
477b941789Smikel #include <unistd.h>
487b941789Smikel
49b78496eeScgd #include "extern.h"
50b78496eeScgd
51b78496eeScgd #if defined(NLIST_ECOFF)
52b78496eeScgd
53b78496eeScgd #include <sys/exec_ecoff.h>
54b78496eeScgd
55b78496eeScgd int
check_ecoff(int fd,const char * filename)56b78496eeScgd check_ecoff(int fd, const char *filename)
57b78496eeScgd {
58b78496eeScgd struct ecoff_exechdr eh;
59b78496eeScgd struct stat sb;
60b78496eeScgd
61b78496eeScgd /*
627b941789Smikel * Check the header to make sure it's an ECOFF file (of the
63b78496eeScgd * appropriate size).
64b78496eeScgd */
65b78496eeScgd if (fstat(fd, &sb) == -1)
66b78496eeScgd return 0;
67*e7f34be0Stsutsui if (sb.st_size < (off_t)sizeof eh)
68b78496eeScgd return 0;
69b78496eeScgd if (read(fd, &eh, sizeof eh) != sizeof eh)
70b78496eeScgd return 0;
71b78496eeScgd
72b78496eeScgd if (ECOFF_BADMAG(&eh))
73b78496eeScgd return 0;
74b78496eeScgd
75b78496eeScgd return 1;
76b78496eeScgd }
77b78496eeScgd
78b78496eeScgd int
hide_ecoff(int fd,const char * filename)79b78496eeScgd hide_ecoff(int fd, const char *filename)
80b78496eeScgd {
81b78496eeScgd
82b78496eeScgd fprintf(stderr, "%s: ECOFF executables not currently supported\n",
83b78496eeScgd filename);
84b78496eeScgd return 1;
85b78496eeScgd }
86b78496eeScgd
87b78496eeScgd #endif /* defined(NLIST_ECOFF) */
88