Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: fusl/src/network/getservbyname_r.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #define _GNU_SOURCE 1 #define _GNU_SOURCE
2 #include <sys/socket.h> 2 #include <sys/socket.h>
3 #include <netinet/in.h> 3 #include <netinet/in.h>
4 #include <netdb.h> 4 #include <netdb.h>
5 #include <inttypes.h> 5 #include <inttypes.h>
6 #include <errno.h> 6 #include <errno.h>
7 #include <string.h> 7 #include <string.h>
8 #include "lookup.h" 8 #include "lookup.h"
9 9
10 #define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *)) 10 #define ALIGN \
11 (sizeof(struct { \
12 char a; \
13 char* b; \
14 }) - \
15 sizeof(char*))
11 16
12 int getservbyname_r(const char *name, const char *prots, 17 int getservbyname_r(const char* name,
13 » struct servent *se, char *buf, size_t buflen, struct servent **res) 18 const char* prots,
14 { 19 struct servent* se,
15 » struct service servs[MAXSERVS]; 20 char* buf,
16 » int cnt, proto, align; 21 size_t buflen,
22 struct servent** res) {
23 struct service servs[MAXSERVS];
24 int cnt, proto, align;
17 25
18 » /* Align buffer */ 26 /* Align buffer */
19 » align = -(uintptr_t)buf & ALIGN-1; 27 align = -(uintptr_t)buf & ALIGN - 1;
20 » if (buflen < 2*sizeof(char *)+align) 28 if (buflen < 2 * sizeof(char*) + align)
21 » » return ERANGE; 29 return ERANGE;
22 » buf += align; 30 buf += align;
23 31
24 » if (!prots) proto = 0; 32 if (!prots)
25 » else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP; 33 proto = 0;
26 » else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP; 34 else if (!strcmp(prots, "tcp"))
27 » else return EINVAL; 35 proto = IPPROTO_TCP;
36 else if (!strcmp(prots, "udp"))
37 proto = IPPROTO_UDP;
38 else
39 return EINVAL;
28 40
29 » cnt = __lookup_serv(servs, name, proto, 0, 0); 41 cnt = __lookup_serv(servs, name, proto, 0, 0);
30 » if (cnt<0) switch (cnt) { 42 if (cnt < 0)
31 » case EAI_MEMORY: 43 switch (cnt) {
32 » case EAI_SYSTEM: 44 case EAI_MEMORY:
33 » » return ENOMEM; 45 case EAI_SYSTEM:
34 » default: 46 return ENOMEM;
35 » » return ENOENT; 47 default:
36 » } 48 return ENOENT;
49 }
37 50
38 » se->s_name = (char *)name; 51 se->s_name = (char*)name;
39 » se->s_aliases = (void *)buf; 52 se->s_aliases = (void*)buf;
40 » se->s_aliases[0] = se->s_name; 53 se->s_aliases[0] = se->s_name;
41 » se->s_aliases[1] = 0; 54 se->s_aliases[1] = 0;
42 » se->s_port = htons(servs[0].port); 55 se->s_port = htons(servs[0].port);
43 » se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp"; 56 se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp";
44 57
45 » *res = se; 58 *res = se;
46 » return 0; 59 return 0;
47 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698