/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
#ident "$Header: mips1.c,v 2.1.1.1 92/06/24 14:10:12 marker Exp $"

#include <stdio.h>
#include <unistd.h>
#include <filehdr.h>
#include <sys/types.h>
#include <sys/fcntl.h>

main (c,v)
char **v;
int c;
{
	struct filehdr fh;
	int fd;

	if (c != 2)
		printf ("usage: mips1 <object-file>\n"), exit(1);

	if ((fd = open (v[1], O_RDWR)) == -1) 
		perror("open"), exit(1);

	if (read (fd, &fh.f_magic, sizeof (fh.f_magic)) == -1)
		perror ("read"), exit(1);

	switch (fh.f_magic) {

		case MIPSEBMAGIC_2:	fh.f_magic = MIPSEBMAGIC;
					break;

		case MIPSELMAGIC_2:	fh.f_magic = MIPSELMAGIC;
					break;

		default:		break;
	}

	if (lseek (fd, 0, SEEK_SET) == -1)
		perror ("seek"), exit(1);

	if (write (fd, &fh.f_magic, sizeof (fh.f_magic)) == -1)
		perror ("write"), exit(1);

	if (close (fd) == -1)
		perror ("close"), exit(1);
	
	exit (0);
		
}
