Permalink
Browse files

uclibc: add err macros

  • Loading branch information...
1 parent 04782b8 commit da495f73ce9a7817202f51caa57bc00224434ca2 @msantos committed Jul 15, 2011
Showing with 99 additions and 5 deletions.
  1. +3 −3 sods/configure
  2. +17 −2 sods/sods.h
  3. +79 −0 sods/sods_err.c
View
@@ -4,11 +4,11 @@ OS=`uname -s`
case $OS in
'Linux')
- DEF="-DHAVE_SEND"
+ DEF="-DHAVE_ERR -DHAVE_SEND"
LIB="-lresolv"
;;
'Darwin'|'NetBSD')
- DEF="-DHAVE_SETSOCKOPT -Wno-deprecated-declarations"
+ DEF="-DHAVE_ERR -DHAVE_SETSOCKOPT -Wno-deprecated-declarations"
LIB="-lresolv"
;;
'SunOS')
@@ -31,7 +31,7 @@ LIB=${LIB}
all:
\$(CC) \$(DEF) \$(LIB) -g -Wall -o sods sods.c sods_handler.c sods_dns.c sods_io.c \
- sods_q.c sods_sock.c sods_priv.c base32.c base64.c
+ sods_q.c sods_sock.c sods_priv.c sods_err.c base32.c base64.c
clean:
-@\$(RM) sods *.o
View
@@ -21,7 +21,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <err.h>
#include <sys/errno.h>
#include <netinet/in.h>
@@ -47,7 +46,17 @@
#include <syslog.h>
-#define SDS_VERSION "0.03"
+#define SDS_VERSION "0.04"
+#define SDS_PROGNAME "sods"
+
+#ifdef HAVE_ERRX
+#include <err.h>
+#else
+#define err sds_err
+#define errx sds_errx
+#define warn sds_warn
+#define warnx sds_warnx
+#endif /* HAVE_ERRX */
#define IS_ERR(x) do { \
if ((x) == -1) { \
@@ -234,3 +243,9 @@ void sds_dns_packet(SDS_PKT *pkt, void *data, size_t len);
int sds_priv_init(SDS_STATE *ss);
+#ifndef HAVE_ERRX
+void sds_err(int rv, char *fmt, ...);
+void sds_errx(int rv, char *fmt, ...);
+void sds_warn(char *fmt, ...);
+void sds_warnx(char *fmt, ...);
+#endif /* HAVE_ERRX */
View
@@ -0,0 +1,79 @@
+/*
+ * Socket over DNS client.
+ *
+ * Copyright (c) 2009-2011 Michael Santos <michael.santos@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef HAVE_ERRX
+#include <stdarg.h>
+#include <errno.h>
+
+#include "sods.h"
+
+//extern char *__progname;
+
+ void
+sds_err(int rv, char *fmt, ...)
+{
+ va_list ap;
+
+ (void)fprintf(stderr, "sods: ");
+ va_start(ap, fmt);
+ (void)vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ (void)fprintf(stderr, ": %s\n", strerror(errno));
+
+ exit (rv);
+}
+
+ void
+sds_errx(int rv, char *fmt, ...)
+{
+ va_list ap;
+
+ (void)fprintf(stderr, "sods: ");
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ (void)fprintf(stderr, "\n");
+
+ exit (rv);
+}
+
+ void
+sds_warn(char *fmt, ...)
+{
+ va_list ap;
+
+ (void)fprintf(stderr, "sods: ");
+ va_start(ap, fmt);
+ (void)vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ (void)fprintf(stderr, ": %s\n", strerror(errno));
+}
+
+ void
+sds_warnx(char *fmt, ...)
+{
+ va_list ap;
+
+ (void)fprintf(stderr, "sods: ");
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ (void)fprintf(stderr, "\n");
+}
+#endif /* ! HAVE_ERRX */

0 comments on commit da495f7

Please sign in to comment.