]> git.saurik.com Git - apple/boot.git/blobdiff - i386/util/machOconv.c
boot-132.tar.gz
[apple/boot.git] / i386 / util / machOconv.c
index 88464e3b1d0190984989b966507bcb4e9a6ba8be..f11469eaab5bf8acdd60243cbae6a48ac75bd140 100644 (file)
@@ -1,12 +1,12 @@
 /*
- * 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;
 
@@ -40,19 +42,18 @@ static unsigned long swap(
 )
 {
     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);
@@ -79,7 +80,7 @@ usage:
        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);
     }
@@ -88,7 +89,7 @@ usage:
     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);
     }
 
@@ -102,7 +103,7 @@ usage:
        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);
     }
@@ -129,18 +130,18 @@ usage:
            }
 
            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);
            }