libbsd: Branch 'master' - 12 commits

Guillem Jover guillem at kemper.freedesktop.org
Tue Jul 8 23:15:14 PDT 2008


 Makefile              |   23 +-
 Versions              |    6 
 include/bsd/bsd.h     |    6 
 include/bsd/cdefs.h   |    4 
 include/bsd/err.h     |   26 ++
 include/bsd/getopt.h  |   26 ++
 include/bsd/ip_icmp.h |    2 
 include/bsd/queue.h   |    2 
 include/bsd/stdlib.h  |   36 ++++
 include/vis.h         |    2 
 man/fgetln.3          |    2 
 man/setmode.3         |  114 ++++++++++++
 src/fgetln.c          |   22 +-
 src/heapsort.c        |    2 
 src/setmode.c         |  444 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/unvis.c           |    2 
 src/vis.c             |    2 
 17 files changed, 692 insertions(+), 29 deletions(-)

New commits:
commit 84d311d03872a1c18305abe8218c0a3d3f5434d2
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 09:07:58 2008 +0300

    Remove link_addr and link_ntoa symbols from the version script

diff --git a/Versions b/Versions
index bb3e0a2..ba7606c 100644
--- a/Versions
+++ b/Versions
@@ -11,7 +11,7 @@ LIBBSD_0.0 {
     heapsort;
     humanize_number;
     inet_net_pton;
-    link_addr; link_ntoa;
+
     getprogname; setprogname;
     strlcpy;
     strlcat;
commit 38829bdc8b5dd17d8d10a2daf350605e7c6f70a4
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 09:07:03 2008 +0300

    Add new setmode and getmode functions from FreeBSD

diff --git a/Makefile b/Makefile
index f28a27c..74016bc 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ LIB_DIST := Makefile Versions libbsd.pc
 LIB_SRCS := arc4random.c bsd_getopt.c err.c fgetln.c heapsort.c \
 	    humanize_number.c inet_net_pton.c \
 	    hash/md5.c hash/md5hl.c \
+	    setmode.c \
 	    strlcat.c strlcpy.c fmtcheck.c progname.c vis.c unvis.c
 LIB_SRCS := $(patsubst %,src/%,$(LIB_SRCS))
 
@@ -23,7 +24,7 @@ LIB_GEN_SRCS := \
 LIB_INCLUDES := bsd/err.h bsd/getopt.h bsd/ip_icmp.h bsd/random.h bsd/queue.h bsd/md5.h bsd/string.h \
 		bsd/bsd.h bsd/cdefs.h bsd/stdlib.h vis.h libutil.h
 
-LIB_MANS := arc4random.3 strlcpy.3 fgetln.3 fmtcheck.3 md5.3
+LIB_MANS := arc4random.3 strlcpy.3 fgetln.3 fmtcheck.3 setmode.3 md5.3
 LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
 
 LIB_STATIC_OBJS = $(LIB_SRCS:%.c=%.o)
diff --git a/Versions b/Versions
index b4e8392..bb3e0a2 100644
--- a/Versions
+++ b/Versions
@@ -15,6 +15,10 @@ LIBBSD_0.0 {
     getprogname; setprogname;
     strlcpy;
     strlcat;
+
+    setmode;
+    getmode;
+
     vis; strvis; strvisx;
     unvis; strunvis; strunvisx;
     MD5Init;
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index f450e56..16376cb 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2005 Aurelien Jarno
  * Copyright (C) 2006 Robert Millan
+ * Copyright (C) 2008 Guillem Jover
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +29,7 @@
 #ifndef LIBBSD_STDLIB_H
 #define LIBBSD_STDLIB_H
 
+#include <sys/stat.h>
 #include <stdlib.h>
 
 const char *fmtcheck (const char *, const char *);
@@ -37,4 +39,11 @@ void setprogname (char *);
 
 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
 
+#ifndef S_ISTXT
+#define S_ISTXT S_ISVTX
+#endif
+
+mode_t getmode(const void *set, mode_t mode);
+void *setmode(const char *mode_str);
+
 #endif
diff --git a/man/setmode.3 b/man/setmode.3
new file mode 100644
index 0000000..94fd5d1
--- /dev/null
+++ b/man/setmode.3
@@ -0,0 +1,114 @@
+.\" Copyright (c) 1989, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)setmode.3	8.2 (Berkeley) 4/28/95
+.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
+.\"
+.Dd April 28, 1995
+.Dt SETMODE 3
+.Os
+.Sh NAME
+.Nm getmode ,
+.Nm setmode
+.Nd modify mode bits
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In unistd.h
+.Ft mode_t
+.Fn getmode "const void *set" "mode_t mode"
+.Ft void *
+.Fn setmode "const char *mode_str"
+.Sh DESCRIPTION
+The
+.Fn getmode
+function
+returns a copy of the file permission bits
+.Fa mode
+as altered by the values pointed to by
+.Fa set .
+While only the mode bits are altered, other parts of the file mode
+may be examined.
+.Pp
+The
+.Fn setmode
+function
+takes an absolute (octal) or symbolic value, as described in
+.Xr chmod 1 ,
+as an argument
+and returns a pointer to mode values to be supplied to
+.Fn getmode .
+Because some of the symbolic values are relative to the file
+creation mask,
+.Fn setmode
+may call
+.Xr umask 2 .
+If this occurs, the file creation mask will be restored before
+.Fn setmode
+returns.
+If the calling program changes the value of its file creation mask
+after calling
+.Fn setmode ,
+.Fn setmode
+must be called again if
+.Fn getmode
+is to modify future file modes correctly.
+.Pp
+If the mode passed to
+.Fn setmode
+is invalid or if memory cannot be allocated for the return value,
+.Fn setmode
+returns
+.Dv NULL .
+.Pp
+The value returned from
+.Fn setmode
+is obtained from
+.Fn malloc
+and should be returned to the system with
+.Fn free
+when the program is done with it, generally after a call to
+.Fn getmode .
+.Sh ERRORS
+The
+.Fn setmode
+function
+may fail and set errno for any of the errors specified for the library
+routine
+.Xr malloc 3 .
+.Sh SEE ALSO
+.Xr chmod 1 ,
+.Xr stat 2 ,
+.Xr umask 2 ,
+.Xr malloc 3
+.Sh HISTORY
+The
+.Fn getmode
+and
+.Fn setmode
+functions first appeared in
+.Bx 4.4 .
diff --git a/src/setmode.c b/src/setmode.c
new file mode 100644
index 0000000..66f2924
--- /dev/null
+++ b/src/setmode.c
@@ -0,0 +1,444 @@
+/*
+ * Copyright (c) 1989, 1993, 1994
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Dave Borman at Cray Research, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)setmode.c	8.2 (Berkeley) 3/25/94";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.11 2007/01/09 00:27:55 imp Exp $");
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef SETMODE_DEBUG
+#include <stdio.h>
+#endif
+
+#define	SET_LEN	6		/* initial # of bitcmd struct to malloc */
+#define	SET_LEN_INCR 4		/* # of bitcmd structs to add as needed */
+
+typedef struct bitcmd {
+	char	cmd;
+	char	cmd2;
+	mode_t	bits;
+} BITCMD;
+
+#define	CMD2_CLR	0x01
+#define	CMD2_SET	0x02
+#define	CMD2_GBITS	0x04
+#define	CMD2_OBITS	0x08
+#define	CMD2_UBITS	0x10
+
+static BITCMD	*addcmd(BITCMD *, int, int, int, u_int);
+static void	 compress_mode(BITCMD *);
+#ifdef SETMODE_DEBUG
+static void	 dumpmode(BITCMD *);
+#endif
+
+/*
+ * Given the old mode and an array of bitcmd structures, apply the operations
+ * described in the bitcmd structures to the old mode, and return the new mode.
+ * Note that there is no '=' command; a strict assignment is just a '-' (clear
+ * bits) followed by a '+' (set bits).
+ */
+mode_t
+getmode(const void *bbox, mode_t omode)
+{
+	const BITCMD *set;
+	mode_t clrval, newmode, value;
+
+	set = (const BITCMD *)bbox;
+	newmode = omode;
+	for (value = 0;; set++)
+		switch(set->cmd) {
+		/*
+		 * When copying the user, group or other bits around, we "know"
+		 * where the bits are in the mode so that we can do shifts to
+		 * copy them around.  If we don't use shifts, it gets real
+		 * grundgy with lots of single bit checks and bit sets.
+		 */
+		case 'u':
+			value = (newmode & S_IRWXU) >> 6;
+			goto common;
+
+		case 'g':
+			value = (newmode & S_IRWXG) >> 3;
+			goto common;
+
+		case 'o':
+			value = newmode & S_IRWXO;
+common:			if (set->cmd2 & CMD2_CLR) {
+				clrval =
+				    (set->cmd2 & CMD2_SET) ?  S_IRWXO : value;
+				if (set->cmd2 & CMD2_UBITS)
+					newmode &= ~((clrval<<6) & set->bits);
+				if (set->cmd2 & CMD2_GBITS)
+					newmode &= ~((clrval<<3) & set->bits);
+				if (set->cmd2 & CMD2_OBITS)
+					newmode &= ~(clrval & set->bits);
+			}
+			if (set->cmd2 & CMD2_SET) {
+				if (set->cmd2 & CMD2_UBITS)
+					newmode |= (value<<6) & set->bits;
+				if (set->cmd2 & CMD2_GBITS)
+					newmode |= (value<<3) & set->bits;
+				if (set->cmd2 & CMD2_OBITS)
+					newmode |= value & set->bits;
+			}
+			break;
+
+		case '+':
+			newmode |= set->bits;
+			break;
+
+		case '-':
+			newmode &= ~set->bits;
+			break;
+
+		case 'X':
+			if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH))
+				newmode |= set->bits;
+			break;
+
+		case '\0':
+		default:
+#ifdef SETMODE_DEBUG
+			(void)printf("getmode:%04o -> %04o\n", omode, newmode);
+#endif
+			return (newmode);
+		}
+}
+
+#define	ADDCMD(a, b, c, d)						\
+	if (set >= endset) {						\
+		BITCMD *newset;						\
+		setlen += SET_LEN_INCR;					\
+		newset = realloc(saveset, sizeof(BITCMD) * setlen);	\
+		if (!newset) {						\
+			if (saveset)					\
+				free(saveset);				\
+			saveset = NULL;					\
+			return (NULL);					\
+		}							\
+		set = newset + (set - saveset);				\
+		saveset = newset;					\
+		endset = newset + (setlen - 2);				\
+	}								\
+	set = addcmd(set, (a), (b), (c), (d))
+
+#define	STANDARD_BITS	(S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
+
+void *
+setmode(const char *p)
+{
+	int perm, who;
+	char op, *ep;
+	BITCMD *set, *saveset, *endset;
+	sigset_t sigset, sigoset;
+	mode_t mask;
+	int equalopdone=0, permXbits, setlen;
+	long perml;
+
+	if (!*p)
+		return (NULL);
+
+	/*
+	 * Get a copy of the mask for the permissions that are mask relative.
+	 * Flip the bits, we want what's not set.  Since it's possible that
+	 * the caller is opening files inside a signal handler, protect them
+	 * as best we can.
+	 */
+	sigfillset(&sigset);
+        (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset);
+	(void)umask(mask = umask(0));
+	mask = ~mask;
+        (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL);
+
+	setlen = SET_LEN + 2;
+
+	if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL)
+		return (NULL);
+	saveset = set;
+	endset = set + (setlen - 2);
+
+	/*
+	 * If an absolute number, get it and return; disallow non-octal digits
+	 * or illegal bits.
+	 */
+	if (isdigit((unsigned char)*p)) {
+		perml = strtol(p, &ep, 8);
+		if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) {
+			free(saveset);
+			return (NULL);
+		}
+		perm = (mode_t)perml;
+		ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
+		set->cmd = 0;
+		return (saveset);
+	}
+
+	/*
+	 * Build list of structures to set/clear/copy bits as described by
+	 * each clause of the symbolic mode.
+	 */
+	for (;;) {
+		/* First, find out which bits might be modified. */
+		for (who = 0;; ++p) {
+			switch (*p) {
+			case 'a':
+				who |= STANDARD_BITS;
+				break;
+			case 'u':
+				who |= S_ISUID|S_IRWXU;
+				break;
+			case 'g':
+				who |= S_ISGID|S_IRWXG;
+				break;
+			case 'o':
+				who |= S_IRWXO;
+				break;
+			default:
+				goto getop;
+			}
+		}
+
+getop:		if ((op = *p++) != '+' && op != '-' && op != '=') {
+			free(saveset);
+			return (NULL);
+		}
+		if (op == '=')
+			equalopdone = 0;
+
+		who &= ~S_ISTXT;
+		for (perm = 0, permXbits = 0;; ++p) {
+			switch (*p) {
+			case 'r':
+				perm |= S_IRUSR|S_IRGRP|S_IROTH;
+				break;
+			case 's':
+				/* If only "other" bits ignore set-id. */
+				if (!who || who & ~S_IRWXO)
+					perm |= S_ISUID|S_ISGID;
+				break;
+			case 't':
+				/* If only "other" bits ignore sticky. */
+				if (!who || who & ~S_IRWXO) {
+					who |= S_ISTXT;
+					perm |= S_ISTXT;
+				}
+				break;
+			case 'w':
+				perm |= S_IWUSR|S_IWGRP|S_IWOTH;
+				break;
+			case 'X':
+				permXbits = S_IXUSR|S_IXGRP|S_IXOTH;
+				break;
+			case 'x':
+				perm |= S_IXUSR|S_IXGRP|S_IXOTH;
+				break;
+			case 'u':
+			case 'g':
+			case 'o':
+				/*
+				 * When ever we hit 'u', 'g', or 'o', we have
+				 * to flush out any partial mode that we have,
+				 * and then do the copying of the mode bits.
+				 */
+				if (perm) {
+					ADDCMD(op, who, perm, mask);
+					perm = 0;
+				}
+				if (op == '=')
+					equalopdone = 1;
+				if (op == '+' && permXbits) {
+					ADDCMD('X', who, permXbits, mask);
+					permXbits = 0;
+				}
+				ADDCMD(*p, who, op, mask);
+				break;
+
+			default:
+				/*
+				 * Add any permissions that we haven't already
+				 * done.
+				 */
+				if (perm || (op == '=' && !equalopdone)) {
+					if (op == '=')
+						equalopdone = 1;
+					ADDCMD(op, who, perm, mask);
+					perm = 0;
+				}
+				if (permXbits) {
+					ADDCMD('X', who, permXbits, mask);
+					permXbits = 0;
+				}
+				goto apply;
+			}
+		}
+
+apply:		if (!*p)
+			break;
+		if (*p != ',')
+			goto getop;
+		++p;
+	}
+	set->cmd = 0;
+#ifdef SETMODE_DEBUG
+	(void)printf("Before compress_mode()\n");
+	dumpmode(saveset);
+#endif
+	compress_mode(saveset);
+#ifdef SETMODE_DEBUG
+	(void)printf("After compress_mode()\n");
+	dumpmode(saveset);
+#endif
+	return (saveset);
+}
+
+static BITCMD *
+addcmd(BITCMD *set, int op, int who, int oparg, u_int mask)
+{
+	switch (op) {
+	case '=':
+		set->cmd = '-';
+		set->bits = who ? who : STANDARD_BITS;
+		set++;
+
+		op = '+';
+		/* FALLTHROUGH */
+	case '+':
+	case '-':
+	case 'X':
+		set->cmd = op;
+		set->bits = (who ? who : mask) & oparg;
+		break;
+
+	case 'u':
+	case 'g':
+	case 'o':
+		set->cmd = op;
+		if (who) {
+			set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) |
+				    ((who & S_IRGRP) ? CMD2_GBITS : 0) |
+				    ((who & S_IROTH) ? CMD2_OBITS : 0);
+			set->bits = (mode_t)~0;
+		} else {
+			set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS;
+			set->bits = mask;
+		}
+
+		if (oparg == '+')
+			set->cmd2 |= CMD2_SET;
+		else if (oparg == '-')
+			set->cmd2 |= CMD2_CLR;
+		else if (oparg == '=')
+			set->cmd2 |= CMD2_SET|CMD2_CLR;
+		break;
+	}
+	return (set + 1);
+}
+
+#ifdef SETMODE_DEBUG
+static void
+dumpmode(BITCMD *set)
+{
+	for (; set->cmd; ++set)
+		(void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n",
+		    set->cmd, set->bits, set->cmd2 ? " cmd2:" : "",
+		    set->cmd2 & CMD2_CLR ? " CLR" : "",
+		    set->cmd2 & CMD2_SET ? " SET" : "",
+		    set->cmd2 & CMD2_UBITS ? " UBITS" : "",
+		    set->cmd2 & CMD2_GBITS ? " GBITS" : "",
+		    set->cmd2 & CMD2_OBITS ? " OBITS" : "");
+}
+#endif
+
+/*
+ * Given an array of bitcmd structures, compress by compacting consecutive
+ * '+', '-' and 'X' commands into at most 3 commands, one of each.  The 'u',
+ * 'g' and 'o' commands continue to be separate.  They could probably be
+ * compacted, but it's not worth the effort.
+ */
+static void
+compress_mode(BITCMD *set)
+{
+	BITCMD *nset;
+	int setbits, clrbits, Xbits, op;
+
+	for (nset = set;;) {
+		/* Copy over any 'u', 'g' and 'o' commands. */
+		while ((op = nset->cmd) != '+' && op != '-' && op != 'X') {
+			*set++ = *nset++;
+			if (!op)
+				return;
+		}
+
+		for (setbits = clrbits = Xbits = 0;; nset++) {
+			if ((op = nset->cmd) == '-') {
+				clrbits |= nset->bits;
+				setbits &= ~nset->bits;
+				Xbits &= ~nset->bits;
+			} else if (op == '+') {
+				setbits |= nset->bits;
+				clrbits &= ~nset->bits;
+				Xbits &= ~nset->bits;
+			} else if (op == 'X')
+				Xbits |= nset->bits & ~setbits;
+			else
+				break;
+		}
+		if (clrbits) {
+			set->cmd = '-';
+			set->cmd2 = 0;
+			set->bits = clrbits;
+			set++;
+		}
+		if (setbits) {
+			set->cmd = '+';
+			set->cmd2 = 0;
+			set->bits = setbits;
+			set++;
+		}
+		if (Xbits) {
+			set->cmd = 'X';
+			set->cmd2 = 0;
+			set->bits = Xbits;
+			set++;
+		}
+	}
+}
commit a5f7d1a8f12b0ce3b76a23dccb8a5ffdc31ebf39
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 09:04:51 2008 +0300

    Include the rest of the header files

diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h
index 5add995..0d81a3c 100644
--- a/include/bsd/bsd.h
+++ b/include/bsd/bsd.h
@@ -32,8 +32,12 @@
  */
 
 #include <bsd/cdefs.h>
-#include <bsd/random.h>
+#include <bsd/stdlib.h>
 #include <bsd/string.h>
+#include <bsd/err.h>
+#include <bsd/getopt.h>
+#include <bsd/random.h>
+#include <bsd/md5.h>
 #include <bsd/queue.h>
 #include <bsd/ip_icmp.h>
 #include <time.h>
commit 8b95dc5865f26d746651479fd893e77e1f594b56
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 09:04:27 2008 +0300

    Disable __bounded__ __attribute__

diff --git a/include/bsd/cdefs.h b/include/bsd/cdefs.h
index 7567144..3b6446e 100644
--- a/include/bsd/cdefs.h
+++ b/include/bsd/cdefs.h
@@ -57,6 +57,10 @@
 # endif
 #endif
 
+#ifndef __bounded__
+# define __bounded__(x, y, z)
+#endif
+
 #ifndef __FBSDID
 # define __FBSDID(x)
 #endif
commit 96358a2ad649ec2520357470abe3ae86837bf68b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 08:47:09 2008 +0300

    Add support for 'make dist'

diff --git a/Makefile b/Makefile
index db853d8..f28a27c 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,10 @@ LIB_NAME = libbsd
 LIB_VERSION_MAJOR = 0
 LIB_VERSION_MINOR = 0
 
+TAR_NAME = $(LIB_NAME)-$(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR)
+
+LIB_DIST := Makefile Versions libbsd.pc
+
 LIB_SRCS := arc4random.c bsd_getopt.c err.c fgetln.c heapsort.c \
 	    humanize_number.c inet_net_pton.c \
 	    hash/md5.c hash/md5hl.c \
@@ -64,6 +68,12 @@ $(LIB_SHARED): $(LIB_SHARED_OBJS)
 	  -Wl,--version-script=Versions \
 	  -o $@ $^
 
+dist: clean
+	mkdir $(TAR_NAME)
+	cp -a include src man $(LIB_DIST) $(TAR_NAME)
+	tar czf $(TAR_NAME).tar.gz $(TAR_NAME)
+	rm -rf $(TAR_NAME)
+
 install: libs man
 	mkdir -p $(DESTDIR)/usr/lib/ $(DESTDIR)/lib/
 	mkdir -p $(DESTDIR)/usr/include/bsd/
commit fafffd1f7eebdf73a5e3ceb343025272493ebf21
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 08:26:07 2008 +0300

    fgetln: Fix coding style

diff --git a/src/fgetln.c b/src/fgetln.c
index 9f2a584..e59028b 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -34,15 +34,15 @@
 char *
 fgetln (FILE *stream, size_t *len)
 {
-	char *line=NULL;
+	char *line = NULL;
 	ssize_t nread;
 
 	nread = getline (&line, len, stream);
 	if (nread == -1)
 		return NULL;
 
-	(*len)--; /* get rid of the trailing \0, fgetln
-		     does not have it */
+	/* Get rid of the trailing \0, fgetln does not have it. */
+	(*len)--;
 
 	return line;
 }
commit 47109e39d5995c7addaa932625fb0ea1e0e8200a
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 08:22:30 2008 +0300

    fgetln: Fix function to make it actually work
    
    Reported by Thorsten Glaser.

diff --git a/src/fgetln.c b/src/fgetln.c
index c92aa82..9f2a584 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -35,13 +35,11 @@ char *
 fgetln (FILE *stream, size_t *len)
 {
 	char *line=NULL;
-	size_t nread = 0;
+	ssize_t nread;
 
-	while (nread == 1) {
-		nread = getline (&line, len, stream);
-		if (nread == -1)
-			return NULL;
-	}
+	nread = getline (&line, len, stream);
+	if (nread == -1)
+		return NULL;
 
 	(*len)--; /* get rid of the trailing \0, fgetln
 		     does not have it */
commit da92787d48723ef900d3976072f37960d7a96d8b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 07:46:23 2008 +0300

    Ansify function arguments

diff --git a/src/fgetln.c b/src/fgetln.c
index e7499bc..c92aa82 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2005 Hector Garcia Alvarez
- * Copyright (C) 2005 Guillem Jover
+ * Copyright (C) 2005, 2008 Guillem Jover
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,9 +32,7 @@
 
 #ifdef __GLIBC__
 char *
-fgetln (stream, len)
-	FILE *stream;
-	size_t *len;
+fgetln (FILE *stream, size_t *len)
 {
 	char *line=NULL;
 	size_t nread = 0;
commit fc163cee2fd148ef121e2481dfc08065b36b6b2b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 07:23:49 2008 +0300

    Move version and library name to the beginning of the file

diff --git a/Makefile b/Makefile
index e869dd4..db853d8 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,10 @@
 # libbsd
 #
 
+LIB_NAME = libbsd
+LIB_VERSION_MAJOR = 0
+LIB_VERSION_MINOR = 0
+
 LIB_SRCS := arc4random.c bsd_getopt.c err.c fgetln.c heapsort.c \
 	    humanize_number.c inet_net_pton.c \
 	    hash/md5.c hash/md5hl.c \
@@ -21,10 +25,6 @@ LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
 LIB_STATIC_OBJS = $(LIB_SRCS:%.c=%.o)
 LIB_SHARED_OBJS = $(LIB_SRCS:%.c=%.lo)
 
-LIB_NAME = libbsd
-LIB_VERSION_MAJOR = 0
-LIB_VERSION_MINOR = 0
-
 LIB_STATIC = $(LIB_NAME).a
 
 LIB_SHARED_SO = $(LIB_NAME).so
commit 1512d0d4ab508d47aff2d301d90317c11dd50846
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 07:22:30 2008 +0300

    Renumber 4th clause from BSD license to 3rd
    
    Those files have only three clauses.

diff --git a/include/bsd/ip_icmp.h b/include/bsd/ip_icmp.h
index 130fbc6..0742aa6 100644
--- a/include/bsd/ip_icmp.h
+++ b/include/bsd/ip_icmp.h
@@ -10,7 +10,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
diff --git a/include/bsd/queue.h b/include/bsd/queue.h
index 47e6673..e2dc909 100644
--- a/include/bsd/queue.h
+++ b/include/bsd/queue.h
@@ -10,7 +10,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
diff --git a/include/vis.h b/include/vis.h
index ced5fd9..84de6fc 100644
--- a/include/vis.h
+++ b/include/vis.h
@@ -10,7 +10,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
diff --git a/man/fgetln.3 b/man/fgetln.3
index 0c3520c..d483c09 100644
--- a/man/fgetln.3
+++ b/man/fgetln.3
@@ -9,7 +9,7 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
 .\"
diff --git a/src/heapsort.c b/src/heapsort.c
index 3a060fa..79f98d4 100644
--- a/src/heapsort.c
+++ b/src/heapsort.c
@@ -13,7 +13,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
diff --git a/src/unvis.c b/src/unvis.c
index 573e71a..66d74a5 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -10,7 +10,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
diff --git a/src/vis.c b/src/vis.c
index 348562d..4ad31d5 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -10,7 +10,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
commit 7b1c361f4d09522b5af9398814f2e809f42d7b9b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 07:17:20 2008 +0300

    Remove RCS tag

diff --git a/Makefile b/Makefile
index e7c97da..e869dd4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,6 @@
 #
 # libbsd
 #
-# $Id$
-#
 
 LIB_SRCS := arc4random.c bsd_getopt.c err.c fgetln.c heapsort.c \
 	    humanize_number.c inet_net_pton.c \
commit b0f64624bb41ccc00d80f218acb0d2758dd8d5d3
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 9 07:16:20 2008 +0300

    Add missing license headers
    
    With permission from Robert Millan and Aurelien Jarno.

diff --git a/include/bsd/err.h b/include/bsd/err.h
index ab9ac90..fd23bfa 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -1,3 +1,29 @@
+/*
+ * Copyright (C) 2006 Robert Millan
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #ifndef LIBBSD_ERR_H
 #define LIBBSD_ERR_H
 
diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index 0df89da..2f772f0 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -1,3 +1,29 @@
+/*
+ * Copyright (C) 2006 Robert Millan
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #ifndef LIBBSD_GETOPT_H
 #define LIBBSD_GETOPT_H
 
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 659d30e..f450e56 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -1,3 +1,30 @@
+/*
+ * Copyright (C) 2005 Aurelien Jarno
+ * Copyright (C) 2006 Robert Millan
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #ifndef LIBBSD_STDLIB_H
 #define LIBBSD_STDLIB_H
 


More information about the libbsd mailing list