Skip to content

Commit

Permalink
Apply patches to build on DragonFly BSD and (older) FreeBSD
Browse files Browse the repository at this point in the history
This now makes ksh build on DragonFly BSD.

bin/package, src/cmd/INIT/package.sh:
- DragonFly also needs the -lm hack for LDFLAGS.

src/cmd/ksh93/sh/main.c, src/cmd/ksh93/tests/basic.sh:
- fixargs() doesn't work on DragonFly either
  (re: 9b7c392, 159fb9e, cefe087).

The following are backported from:
att#26 (comment)
att#19

src/lib/libast/comp/setlocale.c:
- Add missing #include <errno.h> since errno is used.

src/lib/libast/features/standards:
- Do not set any standards macros (_POSIX_SOURCE etc) on FreeBSD or
  DragonflyBSD; they disable too much functionality on those.

src/lib/libast/features/wchar:
- Set _STDFILE_DECLARED on DragonFly, too.

src/lib/libast/include/sfio.h, src/lib/libast/include/sfio_t.h,
src/lib/libast/sfio/_sfopen.c, src/lib/libast/sfio/sfclrlock.c,
src/lib/libast/sfio/sfhdr.h, src/lib/libast/sfio/sfnew.c,
src/lib/libast/sfio/sfset.c:
- Rename SF_* macros to SFIO_* to avoid a conflict with system
  headers.

src/lib/libast/string/strexpr.c:
- Rename error() to err() to avoid a conflict.
  • Loading branch information
McDutchie committed Jan 18, 2021
1 parent 8633290 commit 978e495
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ esac

# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
NetBSD | SunOS | DragonFly)
case " $LDFLAGS " in
*" -m "*)
;;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/INIT/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ esac

# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
NetBSD | SunOS | DragonFly)
case " $LDFLAGS " in
*" -m "*)
;;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
/* These routines are referenced by this module */
static void exfile(Shell_t*, Sfio_t*,int);
static void chkmail(Shell_t *shp, char*);
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__FreeBSD__) && !defined(__sun)
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__sun)
static void fixargs(char**,int);
#else
# define fixargs(a,b)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ getPsOutput() {
while [[ $actual == [[:space:]]* ]]; do actual=${actual#?}; done
while [[ $actual == *[[:space:]] ]]; do actual=${actual%?}; done
}
if [[ ! $(uname -s) =~ ^(FreeBSD|SunOS)$ ]] &&
if [[ ! $(uname -s) =~ ^(FreeBSD|DragonFly|SunOS)$ ]] &&
getPsOutput "$$" &&
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
then expect='./atest 1 2'
Expand Down
1 change: 1 addition & 0 deletions src/lib/libast/comp/setlocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <ctype.h>
#include <mc.h>
#include <namval.h>
#include <errno.h>

#if ( _lib_wcwidth || _lib_wctomb ) && _hdr_wctype
#include <wctype.h>
Expand Down
16 changes: 15 additions & 1 deletion src/lib/libast/features/standards
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
set stdio
if tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
# In FreeBSD, definitions like _POSIX_SOURCE and such are used to *limit*
# functionality to known API; they don't enable anything. The general intent in
# BSD is to enable everything by default (effectively, providing the
# _KITCHEN_SINK_SOURCE mentioned below). So we look for that here, but stay
# careful that we don't get fooled by presence of FreeBSD that underpins some
# subsystems in Mac OS X; there are other Apple-specific portability hacks
# elsewhere we should not interfere with.
if tst note{ FreeBSD or DragonFly BSD }end compile{
#include <sys/param.h>
#if (!defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(APPLE)
#error not a FreeBSD or DragonFly BSD system
#endif
}end {
}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
#define _ALL_SOURCE 1
#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 21000101L
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/features/wchar
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set include .
cat{
#ifndef _AST_WCHAR_H
#define _AST_WCHAR_H 1
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__DragonFly__)
#define _STDFILE_DECLARED 1
#endif
}end
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libast/include/sfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct _sffmt_s
#define SF_IOINTR 0040000 /* return on interrupts */
#define SF_WCWIDTH 0100000 /* wcwidth display stream */

#define SF_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
#define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
#ifdef _typ_struct_sf_hdtr
#define _SF_HIDESFFLAGS 1
#endif
Expand Down Expand Up @@ -458,7 +458,7 @@ __INLINE__ ssize_t sfmaxr(ssize_t n, int s) { return __sf_maxr(n,s); }
#endif /* _SFSTR_H */

#ifdef _SF_HIDESFFLAGS
#undef SF_FLAGS
#define SF_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
#undef SFIO_FLAGS
#define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
#endif
#endif /* _SFIO_H */
2 changes: 1 addition & 1 deletion src/lib/libast/include/sfio_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
(unsigned char*)(data), /* endr */ \
(unsigned char*)(data), /* endb */ \
(Sfio_t*)0, /* push */ \
(unsigned short)((type)&SF_FLAGS), /* flags */ \
(unsigned short)((type)&SFIO_FLAGS), /* flags */ \
(short)(file), /* file */ \
(unsigned char*)(data), /* data */ \
(ssize_t)(size), /* size */ \
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/sfio/_sfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ char* mode; /* mode of the stream */
{ SFMTXENTER(f, NIL(Sfio_t*));

if(f->mode&SF_INIT ) /* stream uninitialized, ok to set flags */
{ f->flags |= (sflags & (SF_FLAGS & ~SF_RDWR));
{ f->flags |= (sflags & (SFIO_FLAGS & ~SF_RDWR));

if((sflags &= SF_RDWR) != 0) /* reset read/write modes */
{ f->flags = (f->flags & ~SF_RDWR) | sflags;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/sfio/sfclrlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Sfio_t *f;
/* throw away all lock bits except for stacking state SF_PUSH */
f->mode &= (SF_RDWR|SF_INIT|SF_POOL|SF_PUSH|SF_SYNCED|SF_STDIO);

rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SF_FLAGS);
rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SFIO_FLAGS);

SFMTXRETURN(f, rv);
}
4 changes: 2 additions & 2 deletions src/lib/libast/sfio/sfhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,8 @@ extern int poll _ARG_((ulong, struct pollfd*, int));
_END_EXTERNS_

#ifdef _SF_HIDESFFLAGS
#undef SF_FLAGS
#define SF_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
#undef SFIO_FLAGS
#define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
#endif

#endif /*_SFHDR_H*/
2 changes: 1 addition & 1 deletion src/lib/libast/sfio/sfnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int flags; /* type of file stream */

/* stream type */
f->mode = (flags&SF_READ) ? SF_READ : SF_WRITE;
f->flags = (flags&SF_FLAGS) | (sflags&(SF_MALLOC|SF_STATIC));
f->flags = (flags&SFIO_FLAGS) | (sflags&(SF_MALLOC|SF_STATIC));
f->bits = (flags&SF_RDWR) == SF_RDWR ? SF_BOTH : 0;
f->file = file;
f->here = f->extent = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libast/sfio/sfset.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int set;
SFMTXENTER(f,0);

if(flags == 0 && set == 0)
SFMTXRETURN(f, (f->flags&SF_FLAGS));
SFMTXRETURN(f, (f->flags&SFIO_FLAGS));

if((oflags = (f->mode&SF_RDWR)) != (int)f->mode)
{ /* avoid sfsetbuf() isatty() call if user sets (SF_LINE|SF_WCWIDTH) */
Expand All @@ -57,7 +57,7 @@ int set;
SFMTXRETURN(f, 0);
}
if(flags == 0)
SFMTXRETURN(f, (f->flags&SF_FLAGS));
SFMTXRETURN(f, (f->flags&SFIO_FLAGS));

SFLOCK(f,0);

Expand Down Expand Up @@ -95,5 +95,5 @@ int set;
f->flags &= ~SF_PUBLIC;

SFOPEN(f,0);
SFMTXRETURN(f, (oflags&SF_FLAGS));
SFMTXRETURN(f, (oflags&SFIO_FLAGS));
}
22 changes: 11 additions & 11 deletions src/lib/libast/string/strexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define peekchr(ex) (*(ex)->nextchr)
#define ungetchr(ex) ((ex)->nextchr--)

#define error(ex,msg) return(seterror(ex,msg))
#define err(ex,msg) return(seterror(ex,msg))

typedef struct /* expression handle */
{
Expand Down Expand Up @@ -87,7 +87,7 @@ expr(register Expr_t* ex, register int precedence)
case 0:
ungetchr(ex);
if (!precedence) return(0);
error(ex, "more tokens expected");
err(ex, "more tokens expected");
case '-':
n = -expr(ex, 13);
break;
Expand All @@ -113,17 +113,17 @@ expr(register Expr_t* ex, register int precedence)
case 0:
goto done;
case ')':
if (!precedence) error(ex, "too many )'s");
if (!precedence) err(ex, "too many )'s");
goto done;
case '(':
n = expr(ex, 1);
if (getchr(ex) != ')')
{
ungetchr(ex);
error(ex, "closing ) expected");
err(ex, "closing ) expected");
}
gotoperand:
if (operand) error(ex, "operator expected");
if (operand) err(ex, "operator expected");
operand = 1;
continue;
case '?':
Expand All @@ -140,7 +140,7 @@ expr(register Expr_t* ex, register int precedence)
if (getchr(ex) != ':')
{
ungetchr(ex);
error(ex, ": expected for ? operator");
err(ex, ": expected for ? operator");
}
if (n)
{
Expand Down Expand Up @@ -189,7 +189,7 @@ expr(register Expr_t* ex, register int precedence)
break;
case '=':
case '!':
if (peekchr(ex) != '=') error(ex, "operator syntax error");
if (peekchr(ex) != '=') err(ex, "operator syntax error");
if (precedence > 7) goto done;
getchr(ex);
x = expr(ex, 8);
Expand Down Expand Up @@ -237,7 +237,7 @@ expr(register Expr_t* ex, register int precedence)
if (precedence > 11) goto done;
x = expr(ex, 12);
if (c == '*') n *= x;
else if (x == 0) error(ex, "divide by zero");
else if (x == 0) err(ex, "divide by zero");
else if (c == '/') n /= x;
else n %= x;
break;
Expand All @@ -246,15 +246,15 @@ expr(register Expr_t* ex, register int precedence)
pos = --ex->nextchr;
if (isdigit(c)) n = strton(ex->nextchr, &ex->nextchr, NiL, 0);
else if (ex->convert) n = (*ex->convert)(ex->nextchr, &ex->nextchr, ex->handle);
if (ex->nextchr == pos) error(ex, "syntax error");
if (ex->nextchr == pos) err(ex, "syntax error");
goto gotoperand;
}
if (ex->errmsg) return(0);
if (!operand) error(ex, "operand expected");
if (!operand) err(ex, "operand expected");
}
done:
ungetchr(ex);
if (!operand) error(ex, "operand expected");
if (!operand) err(ex, "operand expected");
return(n);
}

Expand Down

0 comments on commit 978e495

Please sign in to comment.