/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
- * Source License Version 1.1 (the "License"). You may not use this file
+ * Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
* @APPLE_LICENSE_HEADER_END@
*/
#include <stdio.h>
-
+#include <stdlib.h>
#include <mach/mach.h>
+#include <mach/mach_error.h>
#include <sys/file.h>
#include <mach-o/loader.h>
-#include <architecture/byte_order.h>
+#include <libkern/OSByteOrder.h>
+#include <unistd.h>
int infile, outfile;
struct mach_header mh;
-unsigned cmds;
+void * cmds;
boolean_t swap_ends;
)
{
if (swap_ends)
- return NXSwapLong(x);
+ return OSSwapInt32(x);
else
return x;
}
-main(argc, argv)
-int argc;
-char *argv[];
+int
+main(int argc, char *argv[])
{
kern_return_t result;
vm_address_t data;
int nc, ncmds;
- unsigned cp;
+ char * cp;
if (argc == 2) {
infile = open(argv[1], O_RDONLY);
perror("read mach header");
exit(1);
}
- if (nc < sizeof (mh)) {
+ if (nc < (int)sizeof (mh)) {
fprintf(stderr, "read mach header: premature EOF %d\n", nc);
exit(1);
}
else if (mh.magic == MH_CIGAM)
swap_ends = TRUE;
else {
- fprintf(stderr, "bad magic number %x\n", mh.magic);
+ fprintf(stderr, "bad magic number %lx\n", (unsigned long)mh.magic);
exit(1);
}
perror("read load commands");
exit(1);
}
- if (nc < swap(mh.sizeofcmds)) {
+ if (nc < (int)swap(mh.sizeofcmds)) {
fprintf(stderr, "read load commands: premature EOF %d\n", nc);
exit(1);
}
}
lseek(infile, swap(scp->fileoff), L_SET);
- nc = read(infile, data, swap(scp->filesize));
+ nc = read(infile, (void *)data, swap(scp->filesize));
if (nc < 0) {
perror("read segment data");
exit(1);
}
- if (nc < swap(scp->filesize)) {
+ if (nc < (int)swap(scp->filesize)) {
fprintf(stderr, "read segment data: premature EOF %d\n", nc);
exit(1);
}
- nc = write(outfile, data, vmsize);
- if (nc < vmsize) {
+ nc = write(outfile, (void *)data, vmsize);
+ if (nc < (int)vmsize) {
perror("write segment data");
exit(1);
}