bin/69010: [2] Portability fixes for FreeBSD build utils
Robert Millan
rmh at debian.org
Tue Jul 13 10:50:03 PDT 2004
>Number: 69010
>Category: bin
>Synopsis: [2] Portability fixes for FreeBSD build utils
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Jul 13 17:50:00 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator: Robert Millan
>Release: 5.2.1
>Organization:
Debian
>Environment:
System: GNU/Linux aragorn 2.4.26-1-k7 #1 Sat May 1 21:40:09 EST 2004 i686
Architecture: i686
>Description:
Some portability fixes for using the FreeBSD build utilities on
non-FreeBSD systems.
>How-To-Repeat:
>Fix:
Patch follows. These changes are non-intrusive but if you have
any questions let me know.
diff -ur src.old/contrib/one-true-awk/b.c src/contrib/one-true-awk/b.c
--- src.old/contrib/one-true-awk/b.c Tue Jul 6 21:06:03 2004
+++ src/contrib/one-true-awk/b.c Tue Jul 6 21:10:06 2004
@@ -25,6 +25,7 @@
/* lasciate ogne speranza, voi ch'entrate. */
#define DEBUG
+#define _ISOC99_SOURCE /* isblank */
#include <ctype.h>
#include <stdio.h>
diff -ur src.old/usr.bin/cksum/cksum.c src/usr.bin/cksum/cksum.c
--- src.old/usr.bin/cksum/cksum.c Tue Jul 6 21:06:03 2004
+++ src/usr.bin/cksum/cksum.c Tue Jul 6 21:10:06 2004
@@ -65,11 +65,11 @@
int
main(int argc, char **argv)
{
- uint32_t val;
+ u_int32_t val;
int ch, fd, rval;
off_t len;
char *fn, *p;
- int (*cfncn)(int, uint32_t *, off_t *);
+ int (*cfncn)(int, u_int32_t *, off_t *);
void (*pfncn)(char *, u_int32_t, off_t);
if ((p = rindex(argv[0], '/')) == NULL)
diff -ur src.old/usr.bin/cksum/extern.h src/usr.bin/cksum/extern.h
--- src.old/usr.bin/cksum/extern.h Tue Jul 6 21:06:03 2004
+++ src/usr.bin/cksum/extern.h Tue Jul 6 21:10:06 2004
@@ -37,11 +37,11 @@
#include <sys/cdefs.h>
__BEGIN_DECLS
-int crc(int, uint32_t *, off_t *);
-void pcrc(char *, uint32_t, off_t);
-void psum1(char *, uint32_t, off_t);
-void psum2(char *, uint32_t, off_t);
-int csum1(int, uint32_t *, off_t *);
-int csum2(int, uint32_t *, off_t *);
-int crc32(int, uint32_t *, off_t *);
+int crc(int, u_int32_t *, off_t *);
+void pcrc(char *, u_int32_t, off_t);
+void psum1(char *, u_int32_t, off_t);
+void psum2(char *, u_int32_t, off_t);
+int csum1(int, u_int32_t *, off_t *);
+int csum2(int, u_int32_t *, off_t *);
+int crc32(int, u_int32_t *, off_t *);
__END_DECLS
diff -ur src.old/usr.bin/make/main.c src/usr.bin/make/main.c
--- src.old/usr.bin/make/main.c Tue Jul 6 21:06:04 2004
+++ src/usr.bin/make/main.c Tue Jul 6 21:10:06 2004
@@ -61,18 +61,18 @@
*/
#include <sys/types.h>
-#include <sys/time.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/signal.h>
#include <sys/stat.h>
-#if defined(__i386__)
+#if defined(__FreeBSD__) && defined(__i386__)
#include <sys/sysctl.h>
#endif
#ifndef MACHINE
#include <sys/utsname.h>
#endif
#include <sys/wait.h>
+#include <time.h>
#include <err.h>
#include <stdlib.h>
#include <errno.h>
@@ -477,8 +477,8 @@
iMkLvl = 0;
}
if (iMkLvl++ > MKLVL_MAXVAL) {
- errc(2, EAGAIN,
- "Max recursion level (%d) exceeded.", MKLVL_MAXVAL);
+ errno = EAGAIN;
+ err (2, "Max recursion level (%d) exceeded.", MKLVL_MAXVAL);
}
bzero(szMkLvl = emalloc(32), 32);
sprintf(szMkLvl, "%d", iMkLvl);
@@ -506,6 +506,7 @@
}
#endif
+#ifdef __FreeBSD__
/*
* PC-98 kernel sets the `i386' string to the utsname.machine and
* it cannot be distinguished from IBM-PC by uname(3). Therefore,
@@ -525,6 +526,7 @@
machine = "pc98";
}
}
+#endif
/*
* Get the name of this type of MACHINE from utsname
diff -ur src.old/usr.bin/yacc/main.c src/usr.bin/yacc/main.c
--- src.old/usr.bin/yacc/main.c Tue Jul 6 21:06:04 2004
+++ src/usr.bin/yacc/main.c Tue Jul 6 21:10:06 2004
@@ -114,7 +114,10 @@
volatile sig_atomic_t sigdie;
-__dead2 void
+#ifdef __dead2
+__dead2
+#endif
+void
done(k)
int k;
{
diff -ur src.old/usr.sbin/btxld/btx.h src/usr.sbin/btxld/btx.h
--- src.old/usr.sbin/btxld/btx.h Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/btxld/btx.h Tue Jul 6 21:10:06 2004
@@ -30,6 +30,7 @@
#define _BTX_H_
#include <sys/types.h>
+#include <stdint.h>
#define BTX_PGSIZE 0x1000 /* Page size */
#define BTX_PGBASE 0x5000 /* Start of page tables */
diff -ur src.old/usr.sbin/btxld/elfh.c src/usr.sbin/btxld/elfh.c
--- src.old/usr.sbin/btxld/elfh.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/btxld/elfh.c Tue Jul 6 21:10:06 2004
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <stddef.h>
+#include <stdint.h>
#include "elfh.h"
#include "endian.h"
diff -ur src.old/usr.sbin/config/main.c src/usr.sbin/config/main.c
--- src.old/usr.sbin/config/main.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/config/main.c Tue Jul 6 21:10:06 2004
@@ -56,6 +56,9 @@
#include <sysexits.h>
#include <unistd.h>
#include <dirent.h>
+#ifndef _DIRENT_HAVE_D_NAMLEN
+# include <string.h> /* strlen */
+#endif
#include "y.tab.h"
#include "config.h"
@@ -431,7 +434,11 @@
if ((dirp = opendir(p)) == NULL)
err(EX_OSERR, "opendir %s", p);
while ((dp = readdir(dirp)) != NULL) {
+#ifdef _DIRENT_HAVE_D_NAMLEN
i = dp->d_namlen - 2;
+#else
+ i = strlen (dp->d_name) - 2;
+#endif
/* Skip non-headers */
if (dp->d_name[i] != '.' || dp->d_name[i + 1] != 'h')
continue;
diff -ur src.old/usr.sbin/kgzip/endian.h src/usr.sbin/kgzip/endian.h
--- src.old/usr.sbin/kgzip/endian.h Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/kgzip/endian.h Tue Jul 6 21:10:06 2004
@@ -3,7 +3,9 @@
*/
#include <sys/types.h>
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <machine/endian.h>
+#endif
#define bswap16(x) (uint16_t) \
((x >> 8) | (x << 8))
diff -ur src.old/usr.sbin/mtree/compare.c src/usr.sbin/mtree/compare.c
--- src.old/usr.sbin/mtree/compare.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/compare.c Tue Jul 6 21:10:06 2004
@@ -77,7 +77,9 @@
off_t len;
char *cp;
const char *tab = "";
+#ifdef __FreeBSD__
char *fflags;
+#endif
label = 0;
switch(s->type) {
@@ -173,21 +175,22 @@
(intmax_t)s->st_size, (intmax_t)p->fts_statp->st_size);
tab = "\t";
}
+#ifdef ST_MTIM
/*
* XXX
* Catches nano-second differences, but doesn't display them.
*/
if ((s->flags & F_TIME) &&
- ((s->st_mtimespec.tv_sec != p->fts_statp->st_mtimespec.tv_sec) ||
- (s->st_mtimespec.tv_nsec != p->fts_statp->st_mtimespec.tv_nsec))) {
+ ((s->ST_MTIM.tv_sec != p->fts_statp->ST_MTIM.tv_sec) ||
+ (s->ST_MTIM.tv_nsec != p->fts_statp->ST_MTIM.tv_nsec))) {
LABEL;
(void)printf("%smodification time expected %.24s ",
- tab, ctime(&s->st_mtimespec.tv_sec));
+ tab, ctime(&s->ST_MTIM.tv_sec));
(void)printf("found %.24s",
- ctime(&p->fts_statp->st_mtimespec.tv_sec));
+ ctime(&p->fts_statp->ST_MTIM.tv_sec));
if (uflag) {
- tv[0].tv_sec = s->st_mtimespec.tv_sec;
- tv[0].tv_usec = s->st_mtimespec.tv_nsec / 1000;
+ tv[0].tv_sec = s->ST_MTIM.tv_sec;
+ tv[0].tv_usec = s->ST_MTIM.tv_nsec / 1000;
tv[1] = tv[0];
if (utimes(p->fts_accpath, tv))
(void)printf(" not modified: %s\n",
@@ -198,6 +201,7 @@
(void)printf("\n");
tab = "\t";
}
+#endif
if (s->flags & F_CKSUM) {
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
LABEL;
@@ -220,6 +224,7 @@
}
}
}
+#ifdef __FreeBSD__
if ((s->flags & F_FLAGS) && s->st_flags != p->fts_statp->st_flags) {
LABEL;
fflags = flags_to_string(s->st_flags);
@@ -240,6 +245,7 @@
(void)printf("\n");
tab = "\t";
}
+#endif
#ifdef MD5
if (s->flags & F_MD5) {
char *new_digest, buf[33];
diff -ur src.old/usr.sbin/mtree/create.c src/usr.sbin/mtree/create.c
--- src.old/usr.sbin/mtree/create.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/create.c Tue Jul 6 21:10:06 2004
@@ -70,7 +70,11 @@
static u_long flags = 0xffffffff;
static int dsort(const FTSENT * const *, const FTSENT * const *);
-static void output(int, int *, const char *, ...) __printflike(3, 4);
+static void output(int, int *, const char *, ...)
+#ifdef __printflike
+__printflike(3, 4)
+#endif
+;
static int statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *);
static void statf(int, FTSENT *);
@@ -147,12 +151,15 @@
uint32_t val;
off_t len;
int fd, offset;
+#ifdef __FreeBSD__
char *fflags;
+#endif
char *escaped_name;
escaped_name = calloc(1, p->fts_namelen * 4 + 1);
if (escaped_name == NULL)
errx(1, "statf(): calloc() failed");
+
strvis(escaped_name, p->fts_name, VIS_WHITE | VIS_OCTAL | VIS_GLOB);
if (iflag || S_ISDIR(p->fts_statp->st_mode))
@@ -208,10 +215,12 @@
if (keys & F_SIZE)
output(indent, &offset, "size=%jd",
(intmax_t)p->fts_statp->st_size);
+#ifdef ST_MTIM
if (keys & F_TIME)
output(indent, &offset, "time=%ld.%ld",
- (long)p->fts_statp->st_mtimespec.tv_sec,
- p->fts_statp->st_mtimespec.tv_nsec);
+ (long)p->fts_statp->ST_MTIM.tv_sec,
+ p->fts_statp->ST_MTIM.tv_nsec);
+#endif
if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 ||
crc(fd, &val, &len))
@@ -252,11 +261,13 @@
if (keys & F_SLINK &&
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
output(indent, &offset, "link=%s", rlink(p->fts_accpath));
+#ifdef __FreeBSD__
if (keys & F_FLAGS && p->fts_statp->st_flags != flags) {
fflags = flags_to_string(p->fts_statp->st_flags);
output(indent, &offset, "flags=%s", fflags);
free(fflags);
}
+#endif
(void)putchar('\n');
}
@@ -282,7 +293,9 @@
u_long saveflags = *pflags;
u_short maxgid, maxuid, maxmode, maxflags;
u_short g[MAXGID], u[MAXUID], m[MAXMODE], f[MAXFLAGS];
+#ifdef __FreeBSD__
char *fflags;
+#endif
static int first = 1;
if ((p = fts_children(t, 0)) == NULL) {
@@ -315,6 +328,7 @@
maxuid = u[suid];
}
+#ifdef __FreeBSD__
/*
* XXX
* note that the below will break when file flags
@@ -328,6 +342,7 @@
saveflags = sflags;
maxflags = f[FLAGS2IDX(sflags)];
}
+#endif
}
}
/*
@@ -371,11 +386,13 @@
(void)printf(" mode=%#o", savemode);
if (keys & F_NLINK)
(void)printf(" nlink=1");
+#ifdef __FreeBSD__
if (keys & F_FLAGS) {
fflags = flags_to_string(saveflags);
(void)printf(" flags=%s", fflags);
free(fflags);
}
+#endif
(void)printf("\n");
*puid = saveuid;
*pgid = savegid;
diff -ur src.old/usr.sbin/mtree/extern.h src/usr.sbin/mtree/extern.h
--- src.old/usr.sbin/mtree/extern.h Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/extern.h Tue Jul 6 21:10:06 2004
@@ -29,12 +29,12 @@
* @(#)extern.h 8.1 (Berkeley) 6/6/93
* $FreeBSD: src/usr.sbin/mtree/extern.h,v 1.13 2004/01/11 19:38:48 phk Exp $
*/
-extern uint32_t crc_total;
+extern u_int32_t crc_total;
#ifdef _FTS_H_
int compare(char *, NODE *, FTSENT *);
#endif
-int crc(int, uint32_t *, off_t *);
+int crc(int, u_int32_t *, off_t *);
void cwalk(void);
char *flags_to_string(u_long);
diff -ur src.old/usr.sbin/mtree/misc.c src/usr.sbin/mtree/misc.c
--- src.old/usr.sbin/mtree/misc.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/misc.c Tue Jul 6 21:10:06 2004
@@ -103,6 +103,7 @@
return (strcmp(((const KEY *)a)->name, ((const KEY *)b)->name));
}
+#ifdef __FreeBSD__
char *
flags_to_string(u_long fflags)
{
@@ -118,3 +119,4 @@
return string;
}
+#endif
diff -ur src.old/usr.sbin/mtree/mtree.c src/usr.sbin/mtree/mtree.c
--- src.old/usr.sbin/mtree/mtree.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/mtree.c Tue Jul 6 21:10:06 2004
@@ -164,7 +164,7 @@
if (dir && chdir(dir))
err(1, "%s", dir);
- if ((cflag || sflag) && !getwd(fullpath))
+ if ((cflag || sflag) && !getcwd(fullpath, PATH_MAX))
errx(1, "%s", fullpath);
if (cflag) {
diff -ur src.old/usr.sbin/mtree/mtree.h src/usr.sbin/mtree/mtree.h
--- src.old/usr.sbin/mtree/mtree.h Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/mtree.h Tue Jul 6 21:10:06 2004
@@ -42,7 +42,16 @@
struct _node *parent, *child; /* up, down */
struct _node *prev, *next; /* left, right */
off_t st_size; /* size */
- struct timespec st_mtimespec; /* last modification time */
+#ifdef __GLIBC__
+# ifdef _STATBUF_ST_NSEC
+# define ST_MTIM st_mtim
+# endif
+#else
+# define ST_MTIM st_mtimespec
+#endif
+#ifdef ST_MTIM
+ struct timespec ST_MTIM; /* last modification time */
+#endif
u_long cksum; /* check sum */
char *md5digest; /* MD5 digest */
char *sha1digest; /* SHA-1 digest */
@@ -50,6 +59,9 @@
char *slink; /* symbolic link reference */
uid_t st_uid; /* uid */
gid_t st_gid; /* gid */
+#ifndef S_ISTXT
+#define S_ISTXT S_ISVTX
+#endif
#define MBITS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
mode_t st_mode; /* mode */
u_long st_flags; /* flags */
diff -ur src.old/usr.sbin/mtree/spec.c src/usr.sbin/mtree/spec.c
--- src.old/usr.sbin/mtree/spec.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/spec.c Tue Jul 6 21:10:13 2004
@@ -169,7 +169,9 @@
char *kw, *val = NULL;
struct group *gr;
struct passwd *pw;
+#ifdef __FreeBSD__
mode_t *m;
+#endif
int value;
char *ep;
@@ -199,12 +201,14 @@
if(!ip->rmd160digest)
errx(1, "strdup");
break;
+#ifdef __FreeBSD__
case F_FLAGS:
if (strcmp("none", val) == 0)
ip->st_flags = 0;
else if (strtofflags(&val, &ip->st_flags, NULL) != 0)
errx(1, "line %d: invalid flag %s",lineno, val);
break;
+#endif
case F_GID:
ip->st_gid = strtoul(val, &ep, 10);
if (*ep)
@@ -218,6 +222,7 @@
case F_IGN:
/* just set flag bit */
break;
+#ifdef __FreeBSD__
case F_MODE:
if ((m = setmode(val)) == NULL)
errx(1, "line %d: invalid file mode %s",
@@ -225,6 +230,7 @@
ip->st_mode = getmode(m, 0);
free(m);
break;
+#endif
case F_NLINK:
ip->st_nlink = strtoul(val, &ep, 10);
if (*ep)
@@ -244,17 +250,19 @@
if (strunvis(ip->slink, val) == -1)
errx(1, "symlink %s is ill-encoded", val);
break;
+#ifdef ST_MTIM
case F_TIME:
- ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10);
+ ip->ST_MTIM.tv_sec = strtoul(val, &ep, 10);
if (*ep != '.')
errx(1, "line %d: invalid time %s",
lineno, val);
val = ep + 1;
- ip->st_mtimespec.tv_nsec = strtoul(val, &ep, 10);
+ ip->ST_MTIM.tv_nsec = strtoul(val, &ep, 10);
if (*ep)
errx(1, "line %d: invalid time %s",
lineno, val);
break;
+#endif
case F_TYPE:
switch(*val) {
case 'b':
diff -ur src.old/usr.sbin/mtree/specspec.c src/usr.sbin/mtree/specspec.c
--- src.old/usr.sbin/mtree/specspec.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/specspec.c Tue Jul 6 21:10:06 2004
@@ -63,8 +63,10 @@
printf(" sha1digest=%s", n->sha1digest);
if (f & F_RMD160)
printf(" rmd160digest=%s", n->rmd160digest);
+#ifdef __FreeBSD__
if (f & F_FLAGS)
printf(" flags=%s", flags_to_string(n->st_flags));
+#endif
printf("\n");
}
@@ -123,8 +125,10 @@
differs |= F_SIZE;
if (FS(n1, n2, F_SLINK, slink))
differs |= F_SLINK;
- if (FM(n1, n2, F_TIME, st_mtimespec))
+#ifdef ST_MTIM
+ if (FM(n1, n2, F_TIME, ST_MTIM))
differs |= F_TIME;
+#endif
if (FF(n1, n2, F_UID, st_uid))
differs |= F_UID;
if (FF(n1, n2, F_UNAME, st_uid))
diff -ur src.old/usr.sbin/mtree/verify.c src/usr.sbin/mtree/verify.c
--- src.old/usr.sbin/mtree/verify.c Tue Jul 6 21:06:04 2004
+++ src/usr.sbin/mtree/verify.c Tue Jul 6 21:10:06 2004
@@ -225,9 +225,11 @@
if (chmod(path, p->st_mode))
(void)printf("%s: permissions not set: %s\n",
path, strerror(errno));
+#ifdef __FreeBSD__
if ((p->flags & F_FLAGS) && p->st_flags &&
chflags(path, p->st_flags))
(void)printf("%s: file flags not set: %s\n",
path, strerror(errno));
+#endif
}
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list