genksyms: close ref_file after use
[safe/jmp/linux-2.6] / scripts / extract-ikconfig
index d9f9f34..de233ff 100755 (executable)
@@ -4,11 +4,12 @@
 # $arg1 is [b]zImage filename
 
 binoffset="./scripts/binoffset"
+test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1
 
 IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
 IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
-function dump_config {
-    typeset file="$1"
+dump_config() {
+    file="$1"
 
     start=`$binoffset $file $IKCFG_ST 2>/dev/null`
     [ "$?" != "0" ] && start="-1"
@@ -16,11 +17,15 @@ function dump_config {
        return
     fi
     end=`$binoffset $file $IKCFG_ED 2>/dev/null`
+    [ "$?" != "0" ] && end="-1"
+    if [ "$end" -eq "-1" ]; then
+       return
+    fi
 
-    let start="$start + 8"
-    let size="$end - $start"
+    start=`expr $start + 8`
+    size=`expr $end - $start`
 
-    head --bytes="$end" "$file" | tail --bytes="$size" | zcat
+    dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat
 
     clean_up
     exit 0
@@ -45,7 +50,7 @@ then
        exit 1
 fi
 
-TMPFILE="/tmp/ikconfig-$$"
+TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1
 image="$1"
 
 # vmlinux: Attempt to dump the configuration from the file directly
@@ -54,6 +59,8 @@ dump_config "$image"
 GZHDR1="0x1f 0x8b 0x08 0x00"
 GZHDR2="0x1f 0x8b 0x08 0x08"
 
+ELFHDR="0x7f 0x45 0x4c 0x46"
+
 # vmlinux.gz: Check for a compressed images
 off=`$binoffset "$image" $GZHDR1 2>/dev/null`
 [ "$?" != "0" ] && off="-1"
@@ -68,6 +75,14 @@ elif [ "$off" -ne "-1" ]; then
        (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \
                zcat >"$TMPFILE"
        dump_config "$TMPFILE"
+
+# check if this is simply an ELF file
+else
+       off=`$binoffset "$image" $ELFHDR 2>/dev/null`
+       [ "$?" != "0" ] && off="-1"
+       if [ "$off" -eq "0" ]; then
+               dump_config "$image"
+       fi
 fi
 
 echo "ERROR: Unable to extract kernel configuration information."