From: Roy Marples Date: Wed, 16 Jan 2008 14:32:35 +0000 (+0000) Subject: We now work with C90 compilers, so no need to enforce C99. X-Git-Tag: v3.2.3~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fe2d190cfa6a558e88d170e883654a52626c342;p=thirdparty%2Fdhcpcd.git We now work with C90 compilers, so no need to enforce C99. --- diff --git a/config.h b/config.h index d7e526ce..35fabe23 100644 --- a/config.h +++ b/config.h @@ -17,7 +17,7 @@ #define ENABLE_NIS #define ENABLE_INFO /* Define this to enable some compatability with 1.x and 2.x info files */ -// #define ENABLE_INFO_COMPAT +/* #define ENABLE_INFO_COMPAT */ /* IPV4LL, aka ZeroConf, aka APIPA, aka RFC 3927. * Needs ARP. */ @@ -35,7 +35,7 @@ /* Some systems do not have a working fork. * The Makefile will attempt to work it out, but if it fails to feel free to * define it here. */ -// #define THERE_IS_NO_FORK +/* #define THERE_IS_NO_FORK */ /* Packname name and pathname definitions. */ diff --git a/dhcp.c b/dhcp.c index 1550ce69..2060fe3e 100644 --- a/dhcp.c +++ b/dhcp.c @@ -51,18 +51,33 @@ #include "logger.h" #include "socket.h" -static const char *dhcp_message[] = { - [DHCP_DISCOVER] = "DHCP_DISCOVER", - [DHCP_OFFER] = "DHCP_OFFER", - [DHCP_REQUEST] = "DHCP_REQUEST", - [DHCP_DECLINE] = "DHCP_DECLINE", - [DHCP_ACK] = "DHCP_ACK", - [DHCP_NAK] = "DHCP_NAK", - [DHCP_RELEASE] = "DHCP_RELEASE", - [DHCP_INFORM] = "DHCP_INFORM", - [DHCP_INFORM + 1] = NULL +typedef struct message { + int value; + const char *name; +} dhcp_message_t; + +static dhcp_message_t dhcp_messages[] = { + { DHCP_DISCOVER, "DHCP_DISCOVER" }, + { DHCP_OFFER, "DHCP_OFFER" }, + { DHCP_REQUEST, "DHCP_REQUEST" }, + { DHCP_DECLINE, "DHCP_DECLINE" }, + { DHCP_ACK, "DHCP_ACK" }, + { DHCP_NAK, "DHCP_NAK" }, + { DHCP_RELEASE, "DHCP_RELEASE" }, + { DHCP_INFORM, "DHCP_INFORM" }, + { -1, NULL } }; +static const char *dhcp_message (int type) +{ + dhcp_message_t *d; + for (d = dhcp_messages; d->name; d++) + if (d->value == type) + return (d->name); + + return (NULL); +} + size_t send_message (const interface_t *iface, const dhcp_t *dhcp, unsigned long xid, char type, const options_t *options) @@ -328,7 +343,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp, free (message); logger (LOG_DEBUG, "sending %s with xid 0x%lx", - dhcp_message[(int) type], xid); + dhcp_message (type), xid); retval = send_packet (iface, ETHERTYPE_IP, (unsigned char *) packet, message_length + sizeof (struct ip) + sizeof (struct udphdr)); diff --git a/logger.c b/logger.c index 421793b8..341a31d4 100644 --- a/logger.c +++ b/logger.c @@ -25,6 +25,9 @@ * SUCH DAMAGE. */ +#define SYSLOG_NAMES + +#include #include #include #include @@ -37,39 +40,28 @@ static int loglevel = LOG_WARNING; static char logprefix[12] = {0}; -static const char *syslog_level_msg[] = { - [LOG_EMERG] = "EMERGENCY!", - [LOG_ALERT] = "ALERT!", - [LOG_CRIT] = "Critical!", - [LOG_WARNING] = "Warning", - [LOG_ERR] = "Error", - [LOG_INFO] = "Info", - [LOG_DEBUG] = "Debug", - [LOG_DEBUG + 1] = NULL -}; - -static const char *syslog_level[] = { - [LOG_EMERG] = "LOG_EMERG", - [LOG_ALERT] = "LOG_ALERT", - [LOG_CRIT] = "LOG_CRIT", - [LOG_ERR] = "LOG_ERR", - [LOG_WARNING] = "LOG_WARNING", - [LOG_NOTICE] = "LOG_NOTICE", - [LOG_INFO] = "LOG_INFO", - [LOG_DEBUG] = "LOG_DEBUG", - [LOG_DEBUG + 1] = NULL -}; - int logtolevel (const char *priority) { - int i = 0; + CODE *c; - while (syslog_level[i]) { - if (!strcmp (priority, syslog_level[i])) - return i; - i++; - } - return -1; + if (isdigit ((int) *priority)) + return (atoi (priority)); + + for (c = prioritynames; c->c_name; c++) + if (! strcasecmp (priority, c->c_name)) + return (c->c_val); + + return (-1); +} + +static const char *leveltolog (int level) { + CODE *c; + + for (c = prioritynames; c->c_name; c++) + if (c->c_val == level) + return (c->c_name); + + return (NULL); } void setloglevel (int level) @@ -82,7 +74,7 @@ void setlogprefix (const char *prefix) snprintf (logprefix, sizeof (logprefix), "%s", prefix); } -void logger(int level, const char *fmt, ...) +void logger (int level, const char *fmt, ...) { va_list p; va_list p2; @@ -94,7 +86,7 @@ void logger(int level, const char *fmt, ...) if (level <= LOG_ERR || level <= loglevel) { if (level == LOG_DEBUG || level == LOG_INFO) f = stdout; - fprintf (f, "%s, %s", syslog_level_msg[level], logprefix); + fprintf (f, "%s, %s", leveltolog (level), logprefix); vfprintf (f, fmt, p); fputc ('\n', f); diff --git a/mk/cc.mk b/mk/cc.mk index 18eae7ee..225b1104 100644 --- a/mk/cc.mk +++ b/mk/cc.mk @@ -3,7 +3,6 @@ # Setup some good default CFLAGS CFLAGS?= -O2 -pipe -CSTD?= c99 # GNU Make way of detecting gcc flags we can use check_gcc=$(shell if ${CC} $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ @@ -16,7 +15,7 @@ WEXTRA!= for x in -Wdeclaration-after-statement -Wsequence-point -Wextra; do \ done # Loads of nice flags to ensure our code is good -CFLAGS+= -pedantic -std=${CSTD} \ +CFLAGS+= -pedantic \ -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \ -Wbad-function-cast -Wnested-externs -Wcomment -Winline \ diff --git a/signal.c b/signal.c index 853b85d6..2cde258a 100644 --- a/signal.c +++ b/signal.c @@ -103,12 +103,11 @@ int signal_read (fd_set *rset) } if (rset && FD_ISSET (signal_pipe[0], rset)) { - int buflen = sizeof (sig) * 2; - char buf[buflen]; + char buf[16]; size_t bytes; - memset (buf, 0, buflen); - bytes = read (signal_pipe[0], buf, buflen); + memset (buf, 0, sizeof (buf)); + bytes = read (signal_pipe[0], buf, sizeof (buf)); if (bytes >= sizeof (sig)) memcpy (&sig, buf, sizeof (sig));