X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fclient.c;h=69f9764056969c92e9078e9d98db2aca00247dea;hb=711f5b6c86f51061c21bedcaa46214a01de0125c;hp=c3cd414f202e9878d15a7768ea830c634e87b34f;hpb=267bbc64779f9c7b32e063aac0df22be61bda6ae;p=collectd.git diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index c3cd414f..69f97640 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -24,10 +24,13 @@ * Florian octo Forster **/ -#if HAVE_CONFIG_H -#include "config.h" +#ifdef WIN32 +#include "gnulib_config.h" +#include #endif +#include "config.h" + #if !defined(__GNUC__) || !__GNUC__ #define __attribute__(x) /**/ #endif @@ -42,11 +45,14 @@ #include #include #include -#include #include -#include #include +#ifndef WIN32 +#include +#include +#endif + #include "collectd/client.h" /* NI_MAXHOST has been obsoleted by RFC 3493 which is a reason for SunOS 5.11 @@ -64,35 +70,38 @@ #endif #endif +#ifdef WIN32 +#define AI_ADDRCONFIG 0 +#endif + /* Secure/static macros. They work like `strcpy' and `strcat', but assure null * termination. They work for static buffers only, because they use `sizeof'. * The `SSTRCATF' combines the functionality of `snprintf' and `strcat' which * is very useful to add formatted stuff to the end of a buffer. */ #define SSTRCPY(d, s) \ do { \ - strncpy((d), (s), sizeof(d)); \ - (d)[sizeof(d) - 1] = 0; \ + strncpy((d), (s), sizeof(d) - 1); \ + (d)[sizeof(d) - 1] = '\0'; \ } while (0) #define SSTRCAT(d, s) \ do { \ size_t _l = strlen(d); \ strncpy((d) + _l, (s), sizeof(d) - _l); \ - (d)[sizeof(d) - 1] = 0; \ + (d)[sizeof(d) - 1] = '\0'; \ } while (0) #define SSTRCATF(d, ...) \ do { \ char _b[sizeof(d)]; \ snprintf(_b, sizeof(_b), __VA_ARGS__); \ - _b[sizeof(_b) - 1] = 0; \ + _b[sizeof(_b) - 1] = '\0'; \ SSTRCAT((d), _b); \ } while (0) #define LCC_SET_ERRSTR(c, ...) \ do { \ snprintf((c)->errbuf, sizeof((c)->errbuf), __VA_ARGS__); \ - (c)->errbuf[sizeof((c)->errbuf) - 1] = 0; \ } while (0) /* @@ -100,7 +109,7 @@ */ struct lcc_connection_s { FILE *fh; - char errbuf[1024]; + char errbuf[2048]; }; struct lcc_response_s { @@ -163,7 +172,7 @@ static char *sstrerror(int errnum, char *buf, size_t buflen) { } #endif /* STRERROR_R_CHAR_P */ - buf[buflen - 1] = 0; + buf[buflen - 1] = '\0'; return buf; } /* char *sstrerror */ @@ -174,7 +183,7 @@ static int lcc_set_errno(lcc_connection_t *c, int err) /* {{{ */ return -1; sstrerror(err, c->errbuf, sizeof(c->errbuf)); - c->errbuf[sizeof(c->errbuf) - 1] = 0; + c->errbuf[sizeof(c->errbuf) - 1] = '\0'; return 0; } /* }}} int lcc_set_errno */ @@ -235,7 +244,7 @@ static void lcc_chomp(char *str) /* {{{ */ while (str_len > 0) { if (str[str_len - 1] >= 32) break; - str[str_len - 1] = 0; + str[str_len - 1] = '\0'; str_len--; } } /* }}} void lcc_chomp */ @@ -299,7 +308,7 @@ static int lcc_receive(lcc_connection_t *c, /* {{{ */ /* Now copy the message. */ strncpy(res.message, ptr, sizeof(res.message)); - res.message[sizeof(res.message) - 1] = 0; + res.message[sizeof(res.message) - 1] = '\0'; /* Error or no lines follow: We're done. */ if (res.status <= 0) { @@ -370,6 +379,10 @@ static int lcc_sendreceive(lcc_connection_t *c, /* {{{ */ static int lcc_open_unixsocket(lcc_connection_t *c, const char *path) /* {{{ */ { +#ifdef WIN32 + lcc_set_errno(c, ENOTSUP); + return -1; +#else struct sockaddr_un sa = {0}; int fd; int status; @@ -404,6 +417,7 @@ static int lcc_open_unixsocket(lcc_connection_t *c, const char *path) /* {{{ */ } return 0; +#endif /* WIN32 */ } /* }}} int lcc_open_unixsocket */ static int lcc_open_netsocket(lcc_connection_t *c, /* {{{ */ @@ -610,7 +624,7 @@ int lcc_getval(lcc_connection_t *c, lcc_identifier_t *ident, /* {{{ */ snprintf(command, sizeof(command), "GETVAL %s", lcc_strescape(ident_esc, ident_str, sizeof(ident_esc))); - command[sizeof(command) - 1] = 0; + command[sizeof(command) - 1] = '\0'; /* Send talk to the daemon.. */ status = lcc_sendreceive(c, command, &res); @@ -916,7 +930,7 @@ int lcc_identifier_to_string(lcc_connection_t *c, /* {{{ */ ident->type_instance); } - string[string_size - 1] = 0; + string[string_size - 1] = '\0'; return 0; } /* }}} int lcc_identifier_to_string */