diff -Nur mtd/include/mtd/jffs2-user.h mtd.osx/include/mtd/jffs2-user.h --- mtd/include/mtd/jffs2-user.h Wed May 5 07:57:54 2004 +++ mtd.osx/include/mtd/jffs2-user.h Mon Sep 27 05:05:36 2004 @@ -9,8 +9,18 @@ /* This file is blessed for inclusion by userspace */ #include +#if defined(BSD) || (defined(__APPLE__) && defined(__MACH__)) +#include +#include +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define bswap_16 OSSwapInt16 +#define bswap_32 OSSwapInt32 +#else #include #include +#endif #undef cpu_to_je16 #undef cpu_to_je32 diff -Nur mtd/util/compr_zlib.c mtd.osx/util/compr_zlib.c --- mtd/util/compr_zlib.c Wed Jun 23 18:00:14 2004 +++ mtd.osx/util/compr_zlib.c Mon Sep 27 05:42:18 2004 @@ -38,7 +38,11 @@ #include #include #include +#if defined(BSD) || (defined(__APPLE__) && defined(__MACH__)) +#include +#else #include +#endif #include #include "compr.h" diff -Nur mtd/util/jffs2dump.c mtd.osx/util/jffs2dump.c --- mtd/util/jffs2dump.c Sat Jun 19 18:00:57 2004 +++ mtd.osx/util/jffs2dump.c Mon Sep 27 05:07:26 2004 @@ -27,11 +27,25 @@ #include #include #include +#if defined(BSD) || (defined(__APPLE__) && defined(__MACH__)) +#include +#else #include +#endif #include #include +#if defined(BSD) || (defined(__APPLE__) && defined(__MACH__)) +#include +#include +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define bswap_16 OSSwapInt16 +#define bswap_32 OSSwapInt32 +#else #include #include +#endif #include #include "crc32.h" diff -Nur mtd/util/mkfs.jffs2.c mtd.osx/util/mkfs.jffs2.c --- mtd/util/mkfs.jffs2.c Fri May 28 06:51:11 2004 +++ mtd.osx/util/mkfs.jffs2.c Mon Sep 27 06:06:27 2004 @@ -62,7 +62,11 @@ #include #include #include +#if !(defined(BSD) || (defined(__APPLE__) && defined(__MACH__))) #include +#else +#define __BYTE_ORDER BYTE_ORDER +#endif #define crc32 __complete_crap #include #undef crc32 @@ -429,7 +433,7 @@ the following macros use it if available or use a hacky workaround... */ -#ifdef __GNUC__ +#if defined(__GNUC__) && !(defined(BSD) || (defined(__APPLE__) && defined(__MACH__))) #define SCANF_PREFIX "a" #define SCANF_STRING(s) (&s) #define GETCWD_SIZE 0 @@ -572,6 +576,52 @@ return 0; } +#if defined(BSD) || (defined(__APPLE__) && defined(__MACH__)) +#include +#include + +static inline int getline(char** line, size_t* size, FILE* fp) +{ + size_t i; + static const size_t grow_rate = 80; + int c; + + if (line == NULL || size == NULL || fp == NULL) { + errno = EINVAL; + return -1; + } + if(feof(fp)) return -1; + if (*line == NULL ) { + *line = malloc(sizeof(char) * grow_rate); + *size = grow_rate; + } + + i = 0; + while (1) { + c = fgetc(fp); + if ((*size - i) <= 1) { + *size += grow_rate; + *line = (char*)realloc(*line, *size); + if (*line == NULL) { + errno = ENOMEM; + return -1; + } + } + if('\n' == c || '\r' == c || EOF == c) { + *(*line + i) = '\0'; + break; + } + *(*line + i++) = (char)c; + } + + if( ferror(fp) != 0 ){ + return -1; + }else{ + return i; + } +} +#endif + static int parse_device_table(struct filesystem_entry *root, FILE * file) { char *line; --- /home/dgs/patchin.sh 2005-03-09 21:50:02.000000000 +0000 +++ mtd/patches/patchin.sh 2005-03-09 21:57:03.883679352 +0000 @@ -42,7 +42,7 @@ # function find_lines () { # find the line number of the first and the last $2 entries - FIRSTLINE=`grep -m1 -n $2 $1 | sed -e 's/:.*//'`; + FIRSTLINE=`grep -n $2 $1 | head -n 1 | sed -e 's/:.*//'`; if [ "x$FIRSTLINE" = "x" ]; then FIRSTLINE=0; LASTLINE=0; @@ -50,7 +50,7 @@ fi; LASTLINE=`grep -n $2 $1 | sed -n -e '$s/:.*// p'`; let LASTLINE=$LASTLINE+1; - LASTLINEADD=`sed -n $1 -e "$LASTLINE,$ p" | sed -n -e '/^\(choice\)\|\(config\)\|\(menu\)\s*/{=; q}'`; + LASTLINEADD=`sed -n -e "$LASTLINE,$ p" $1 | sed -e '/^choice/q;/^config/q;/^menu/q' | wc -l | sed 's/^[ \t]*//'`; if [ "x$LASTLINEADD" = "x" ]; then let LASTLINEADD=`cat $1 | wc -l`-$LASTLINE+2; fi; @@ -80,27 +80,27 @@ local MENUNAME=$5; # read the entries from the input file - local ENTRIES=`sed -n "$INFILE" -e "$FIRSTLINE,$LASTLINE p"`; + local ENTRIES=`sed -n -e "$FIRSTLINE,$LASTLINE p" "$INFILE"`; # determine the menu line number local MENULINE=''; local TOTALOUT=`cat $OUTFILE | wc -l`; if [ "x$MENUNAME" != "x" ]; then - MENULINE=`grep menu $OUTFILE | grep -m1 -n "$MENUNAME" $OUTFILE | sed -e 's/:.*//'`; + MENULINE=`grep menu $OUTFILE | grep -n "$MENUNAME" $OUTFILE | head -n 1 | sed -e 's/:.*//'`; else let MENULINE=$TOTALOUT; fi; # copy lines 1-MENULINE from the target file to the temporary file TMPFILE="Kconfig.$$"; - sed -n "$OUTFILE" -e "1,$MENULINE p" > $TMPFILE; + sed -n -e "1,$MENULINE p" "$OUTFILE" > $TMPFILE; echo >> $TMPFILE; # append our lines - sed -n "$INFILE" -e "$FIRSTLINE,$LASTLINE p" >> $TMPFILE; + sed -n -e "$FIRSTLINE,$LASTLINE p" "$INFILE" >> $TMPFILE; # append lines MENULINE+1-TOTALOUT from the target files to the temporary file if [ $MENULINE -ne $TOTALOUT ]; then let MENULINE=$MENULINE+1; - sed -n "$OUTFILE" -e "$MENULINE,$TOTALOUT p" >> $TMPFILE; + sed -n -e "$MENULINE,$TOTALOUT p" "$OUTFILE" >> $TMPFILE; fi; # replace the target file by the temporary which now contains our entries mv $TMPFILE $OUTFILE; @@ -204,15 +204,15 @@ # determine the previous line number local LINENUM=''; - LINENUM=`grep -m1 -n "$PREVLINE" $INFILE | sed -e 's/:.*//'`; + LINENUM=`grep -n "$PREVLINE" $INFILE | head -n 1 | sed -e 's/:.*//'`; # copy lines 1-LINENUM from the target file to the temporary file TMPFILE="Makefile.$$"; - sed -n "$INFILE" -e "1,$LINENUM p" > $TMPFILE; + sed -n -e "1,$LINENUM p" "$INFILE" > $TMPFILE; echo "$NEWLINE" >> $TMPFILE; let LINENUM=$LINENUM+1; - sed -n "$INFILE" -e "$LINENUM,$TOTAL p" >> $TMPFILE; + sed -n -e "$LINENUM,$TOTAL p" "$INFILE" >> $TMPFILE; # replace the target file by the temporary which now contains our entries mv $TMPFILE $INFILE;