source: asp3_tinet_ecnl_rx/trunk/musl-1.1.18/src/network/dn_expand.c@ 337

Last change on this file since 337 was 337, checked in by coas-nagasima, 6 years ago

ASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 893 bytes
Line 
1#include <resolv.h>
2#include "libc.h"
3
4int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space)
5{
6 const unsigned char *p = src;
7 char *dend, *dbegin = dest;
8 int len = -1, i, j;
9 if (p==end || space <= 0) return -1;
10 dend = dest + (space > 254 ? 254 : space);
11 /* detect reference loop using an iteration counter */
12 for (i=0; i < end-base; i+=2) {
13 /* loop invariants: p<end, dest<dend */
14 if (*p & 0xc0) {
15 if (p+1==end) return -1;
16 j = ((p[0] & 0x3f) << 8) | p[1];
17 if (len < 0) len = p+2-src;
18 if (j >= end-base) return -1;
19 p = base+j;
20 } else if (*p) {
21 if (dest != dbegin) *dest++ = '.';
22 j = *p++;
23 if (j >= end-p || j >= dend-dest) return -1;
24 while (j--) *dest++ = *p++;
25 } else {
26 *dest = 0;
27 if (len < 0) len = p+1-src;
28 return len;
29 }
30 }
31 return -1;
32}
33
34weak_alias(__dn_expand, dn_expand);
Note: See TracBrowser for help on using the repository browser.