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

Side by Side Diff: fusl/src/network/dn_expand.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 #include <resolv.h> 1 #include <resolv.h>
2 #include "libc.h" 2 #include "libc.h"
3 3
4 int __dn_expand(const unsigned char *base, const unsigned char *end, const unsig ned char *src, char *dest, int space) 4 int __dn_expand(const unsigned char* base,
5 { 5 const unsigned char* end,
6 » const unsigned char *p = src; 6 const unsigned char* src,
7 » char *dend, *dbegin = dest; 7 char* dest,
8 » int len = -1, i, j; 8 int space) {
9 » if (p==end || space <= 0) return -1; 9 const unsigned char* p = src;
10 » dend = dest + (space > 254 ? 254 : space); 10 char *dend, *dbegin = dest;
11 » /* detect reference loop using an iteration counter */ 11 int len = -1, i, j;
12 » for (i=0; i < end-base; i+=2) { 12 if (p == end || space <= 0)
13 » » /* loop invariants: p<end, dest<dend */ 13 return -1;
14 » » if (*p & 0xc0) { 14 dend = dest + (space > 254 ? 254 : space);
15 » » » if (p+1==end) return -1; 15 /* detect reference loop using an iteration counter */
16 » » » j = ((p[0] & 0x3f) << 8) | p[1]; 16 for (i = 0; i < end - base; i += 2) {
17 » » » if (len < 0) len = p+2-src; 17 /* loop invariants: p<end, dest<dend */
18 » » » if (j >= end-base) return -1; 18 if (*p & 0xc0) {
19 » » » p = base+j; 19 if (p + 1 == end)
20 » » } else if (*p) { 20 return -1;
21 » » » if (dest != dbegin) *dest++ = '.'; 21 j = ((p[0] & 0x3f) << 8) | p[1];
22 » » » j = *p++; 22 if (len < 0)
23 » » » if (j >= end-p || j >= dend-dest) return -1; 23 len = p + 2 - src;
24 » » » while (j--) *dest++ = *p++; 24 if (j >= end - base)
25 » » } else { 25 return -1;
26 » » » *dest = 0; 26 p = base + j;
27 » » » if (len < 0) len = p+1-src; 27 } else if (*p) {
28 » » » return len; 28 if (dest != dbegin)
29 » » } 29 *dest++ = '.';
30 » } 30 j = *p++;
31 » return -1; 31 if (j >= end - p || j >= dend - dest)
32 return -1;
33 while (j--)
34 *dest++ = *p++;
35 } else {
36 *dest = 0;
37 if (len < 0)
38 len = p + 1 - src;
39 return len;
40 }
41 }
42 return -1;
32 } 43 }
33 44
34 weak_alias(__dn_expand, dn_expand); 45 weak_alias(__dn_expand, dn_expand);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698