Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
This makes things a bit more consistent!
  • Loading branch information
agoode committed Feb 10, 2018
1 parent 1bd4895 commit 547c04c
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 209 deletions.
2 changes: 1 addition & 1 deletion src/avahi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "avahi.h"

int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
query_address_result_t result;
char t[256];
int r;
Expand Down
48 changes: 24 additions & 24 deletions src/avahi.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@

#define WHITESPACE " \t"

static FILE *open_socket(void) {
static FILE* open_socket(void) {
int fd = -1;
struct sockaddr_un sa;
FILE *f = NULL;
FILE* f = NULL;

if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
goto fail;

set_cloexec(fd);

memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, AVAHI_SOCKET, sizeof(sa.sun_path)-1);
sa.sun_path[sizeof(sa.sun_path)-1] = 0;
strncpy(sa.sun_path, AVAHI_SOCKET, sizeof(sa.sun_path) - 1);
sa.sun_path[sizeof(sa.sun_path) - 1] = 0;

if (connect(fd, (struct sockaddr*) &sa, sizeof(sa)) < 0)
if (connect(fd, (struct sockaddr*)&sa, sizeof(sa)) < 0)
goto fail;

if (!(f = fdopen(fd, "r+")))
goto fail;

return f;

fail:
if (fd >= 0)
close(fd);
Expand All @@ -66,14 +66,14 @@ static FILE *open_socket(void) {
}

int avahi_resolve_name(int af, const char* name, query_address_result_t* result) {
FILE *f = NULL;
char *p;
FILE* f = NULL;
char* p;
int ret = -1;
char ln[256];

if (af != AF_INET && af != AF_INET6)
goto finish;

if (!(f = open_socket()))
goto finish;

Expand All @@ -87,14 +87,14 @@ int avahi_resolve_name(int af, const char* name, query_address_result_t* result)
ret = 1;
goto finish;
}

result->af = af;

p = ln+1;
p = ln + 1;
p += strspn(p, WHITESPACE);

/* Store interface number */
result->scopeid = (uint32_t) strtol(p, NULL, 0);
result->scopeid = (uint32_t)strtol(p, NULL, 0);
p += strcspn(p, WHITESPACE);
p += strspn(p, WHITESPACE);

Expand All @@ -113,7 +113,7 @@ int avahi_resolve_name(int af, const char* name, query_address_result_t* result)
goto finish;

ret = 0;

finish:

if (f)
Expand All @@ -122,20 +122,20 @@ int avahi_resolve_name(int af, const char* name, query_address_result_t* result)
return ret;
}

int avahi_resolve_address(int af, const void *data, char* name, size_t name_len) {
FILE *f = NULL;
char *p;
int avahi_resolve_address(int af, const void* data, char* name, size_t name_len) {
FILE* f = NULL;
char* p;
int ret = -1;
char a[256], ln[256];

if (af != AF_INET && af != AF_INET6)
goto finish;

if (!(f = open_socket()))
goto finish;

fprintf(f, "RESOLVE-ADDRESS %s\n", inet_ntop(af, data, a, sizeof(a)));

if (!(fgets(ln, sizeof(ln), f)))
goto finish;

Expand All @@ -144,7 +144,7 @@ int avahi_resolve_address(int af, const void *data, char* name, size_t name_len)
goto finish;
}

p = ln+1;
p = ln + 1;
p += strspn(p, WHITESPACE);

/* Skip interface */
Expand All @@ -154,15 +154,15 @@ int avahi_resolve_address(int af, const void *data, char* name, size_t name_len)
/* Skip protocol */
p += strcspn(p, WHITESPACE);
p += strspn(p, WHITESPACE);

/* Cut off end of line */
*(p + strcspn(p, "\n\r\t ")) = 0;

strncpy(name, p, name_len-1);
name[name_len-1] = 0;
strncpy(name, p, name_len - 1);
name[name_len - 1] = 0;

ret = 0;

finish:

if (f)
Expand Down
2 changes: 1 addition & 1 deletion src/avahi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ typedef struct {

int avahi_resolve_name(int af, const char* name, query_address_result_t* result);

int avahi_resolve_address(int af, const void *data, char* name, size_t name_len);
int avahi_resolve_address(int af, const void* data, char* name, size_t name_len);

#endif
18 changes: 9 additions & 9 deletions src/nss-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
#include <sys/socket.h>
#include <arpa/inet.h>

int main(int argc, char *argv[]) {
struct hostent *he;
in_addr_t **a;
const char *arg= argc > 1 ? argv[1] : "cocaine.local";
int main(int argc, char* argv[]) {
struct hostent* he;
in_addr_t** a;
const char* arg = argc > 1 ? argv[1] : "cocaine.local";
uint8_t t[256];
if (inet_pton(AF_INET, arg, &t) > 0)

if (inet_pton(AF_INET, arg, &t) > 0)
he = gethostbyaddr(t, 4, AF_INET);
else if (inet_pton(AF_INET6, arg, &t) > 0)
he = gethostbyaddr(t, 16, AF_INET6);
Expand All @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) {
if (!he->h_aliases || !he->h_aliases[0])
fprintf(stderr, "no aliases\n");
else {
char **h;
char** h;
fprintf(stderr, "aliases:");
for (h = he->h_aliases; *h; h++)
fprintf(stderr, " %s", *h);
Expand All @@ -60,11 +60,11 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "addr length: %i\n", he->h_length);

fprintf(stderr, "addresses:");
for (a = (in_addr_t**) he->h_addr_list; *a; a++) {
for (a = (in_addr_t**)he->h_addr_list; *a; a++) {
char txt[256];
fprintf(stderr, " %s", inet_ntop(he->h_addrtype, *a, txt, sizeof(txt)));
}
fprintf(stderr, "\n");

return 0;
}
Loading

0 comments on commit 547c04c

Please sign in to comment.