porting dash (the shell)

Boris Kochergin spawk at acm.poly.edu
Sun Jun 7 19:34:38 UTC 2009


Eitan Adler wrote:
> Boris Kochergin wrote:
>   
>> Eitan Adler wrote:
>>     
>>> if gcc -DBSD=1 -DSMALL -DSHELL -DGLOB_BROKEN -DFNMATCH_BROKEN
>>> -DIFS_BROKEN -D__COPYRIGHT\(x\)= -D__RCSID\(x\)= -D_DIAGASSERT\(x\)= -I.
>>> -I. -I..  -include ../config.h   -g -O2 -Wall -MT exec.o -MD -MP -MF
>>> ".deps/exec.Tpo" \
>>>           -c -o exec.o `test -f 'exec.c' || echo './'`exec.c; \
>>>         then mv -f ".deps/exec.Tpo" ".deps/exec.Po"; \
>>>         else rm -f ".deps/exec.Tpo"; exit 1; \
>>>         fi
>>> exec.c: In function 'find_command':
>>> exec.c:317: error: storage size of 'statb' isn't known
>>> exec.c:326: warning: implicit declaration of function 'stat64'
>>> exec.c:317: warning: unused eitan 'statb'
>>> gmake[3]: *** [exec.o] Error 1
>>> gmake[3]: Leaving directory `/home/eitan/dash-0.5.1/src'
>>> gmake[2]: *** [all] Error 2
>>> gmake[2]: Leaving directory `/home/eitan/dash-0.5.1/src'
>>> gmake[1]: *** [all-recursive] Error 1
>>> gmake[1]: Leaving directory `/home/eitan/dash-0.5.1'
>>> gmake: *** [all] Error 2
>>>
>>>   
>>>       
>> stat64() and the statb structure appear to be some kind of Linuxisms.
>> FreeBSD's stat() doesn't have any trouble with file sizes of over 2 GiB,
>> so try replacing the stat64() call with stat() and the statb structure
>> with a stat structure.
>>
>> -Boris
>>
>>     
>
> After doing a global search and replace of stat64 to stat I get:
>
> mystring.c: In function 'single_quote':
> mystring.c:164: warning: implicit declaration of function 'strchrnul'
> mystring.c:164: error: invalid operands to binary -
> mystring.c:169: warning: implicit declaration of function 'mempcpy'
> mystring.c:169: warning: incompatible implicit declaration of built-in
> function 'mempcpy'
>
>
>   
strchrnul() and mempcpy() are GNU extensions to libc. Here they are, 
implemented in ISO C:

char *strchrnul(const char *s, int c) {
  char *i;
  for (i = (char*)s; *i != '\0'; ++i) {
    if (*i == c) {
      return i;
    }
  }
  return i;
}

void *mempcpy(void *dst, const void *src, size_t len) {
  return (void*)(((char*)memcpy(dst, src, len)) + len);
}

You can Google around (or read the Linux man page) for what a GNU 
extension is supposed to do and implement it pretty easily. It's also a 
good idea to test your resulting code against the actual glibc 
implementation (I tested these on a friend's Linux machine).

-Boris


More information about the freebsd-ports mailing list