# HG changeset patch # User Daniele Nicolodi # Date 1342436641 -7200 # Node ID e45d6e9544f57992218ab490dce6dd38cba86581 # Parent e8cca955528039a9be09c4575f008880e86f3b49 Log file name and line number on error diff -r e8cca9555280 -r e45d6e9544f5 DDS_Fox.c --- a/DDS_Fox.c Mon Jul 16 13:00:10 2012 +0200 +++ b/DDS_Fox.c Mon Jul 16 13:04:01 2012 +0200 @@ -1,4 +1,3 @@ -#include #include #include #include "DDS_Fox.h" @@ -43,6 +42,18 @@ }*/ +#define error(...) _error(__FILE__, __LINE__, __func__, __VA_ARGS__) + +void _error(const char *file, int line, const char *func, const char *frmt, ...) +{ + va_list args; + va_start(args, line); + fprintf(stderr, "ERROR: %s:%d:%s: ", file, line, func); + vfprintf(stderr, frmt, args); + fprintf(stderr, "\n"); + va_end(args); +} + void DDS_Initialize (DDSParameter *Param) { char Request[255]; @@ -294,20 +305,20 @@ char Response[255]; char parsebuf[255]; if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) { - printf("Connect failed\n"); + error("Connect failed"); return -1; } if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) { - printf("Write failed\n"); + error("Write failed"); return -1; } sprintf(Response," "); if (ClientTCPRead (hConv, Response, 255, 0) < 0) { - printf("Read failed\n"); + error("Read failed"); return -1; } if (strncmp("OK",Response,2)) { - printf("Response failed %s %s\n", Buffer, Response); + error("Response failed %s %s", Buffer, Response); return -1; } return 0; @@ -319,21 +330,21 @@ char parsebuf[255]; char Response[255]; if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) { - printf("Connect failed\n"); + error("Connect failed"); return -1; } if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) { - printf("Write failed\n"); + error("Write failed"); return -1; } sprintf(Response," "); if (ClientTCPRead (hConv, Response, 255, 0) < 0) { - printf("Read failed\n"); + error("Read failed"); return -1; } if (strncmp(Buffer,Response,strlen(Buffer))) { - printf("Response failed %s %s\n", Buffer, Response); + error("Response failed %s %s", Buffer, Response); return -1; }