--- sa_test.c 2001/10/08 10:03:54 1.6
+++ sa_test.c 2001/10/08 15:08:46 1.7
@@ -37,12 +37,15 @@
#include "sa.h"
-static void die(char *fmt, ...)
+#define DIE_MARK \
+ __FILE__, __LINE__
+
+static void die(const char *file, int line, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- fprintf(stderr, "test:ERROR: ");
+ fprintf(stderr, "%s:%d:ERROR: ", file, line);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
@@ -67,32 +70,32 @@
/* create remote address */
if (sa_addr_create(&ra) != SA_OK)
- die("sa_addr_create (ra)");
+ die(DIE_MARK, "sa_addr_create (ra)");
if (sa_addr_u2a(ra, "inet://141.1.129.1:514") != SA_OK)
- die("sa_addr_u2a (ra)");
+ die(DIE_MARK, "sa_addr_u2a (ra)");
/* create local address */
if (sa_addr_create(&la) != SA_OK)
- die("sa_addr_create (la)");
+ die(DIE_MARK, "sa_addr_create (la)");
if (sa_addr_u2a(la, "inet://0.0.0.0:0") != SA_OK)
- die("sa_addr_u2a (la)");
+ die(DIE_MARK, "sa_addr_u2a (la)");
/* create datagram socket */
if (sa_create(&sa) != SA_OK)
- die("sa_create");
+ die(DIE_MARK, "sa_create");
if (sa_type(sa, SA_TYPE_DATAGRAM) != SA_OK)
- die("sa_type");
+ die(DIE_MARK, "sa_type");
/* bind socket to local address */
if (sa_bind(sa, la) != SA_OK)
- die("sa_bind");
+ die(DIE_MARK, "sa_bind");
/* RFC3164: The BSD syslog Protocol; C. Lonvick; August 2001. */
now = time(NULL);
tm = localtime(&now);
strftime(caTime, sizeof(caTime), "%b %e %H:%M:%S", tm);
if (uname(&uts) == -1)
- die("uname");
+ die(DIE_MARK, "uname");
cpHost = strdup(uts.nodename);
if ((cp = strchr(cpHost, '.')) != NULL)
*cp = '\0';
@@ -106,15 +109,15 @@
/* send message to syslogd(8) */
nBuf = strlen(caBuf);
if (sa_send(sa, caBuf, nBuf, (size_t *)&n, ra) != SA_OK)
- die("sa_writeto");
+ die(DIE_MARK, "sa_writeto");
/* destroy socket and address objects */
if (sa_destroy(sa) != SA_OK)
- die("sa_destroy");
+ die(DIE_MARK, "sa_destroy");
if (sa_addr_destroy(la) != SA_OK)
- die("sa_addr_destroy (la)");
+ die(DIE_MARK, "sa_addr_destroy (la)");
if (sa_addr_destroy(ra) != SA_OK)
- die("sa_addr_destroy (ra)");
+ die(DIE_MARK, "sa_addr_destroy (ra)");
return 0;
}
|