libc: return number of bytes produced for idn2utf() and utf2idn()

This commit is contained in:
cinap_lenrek 2018-09-26 14:32:17 +02:00
parent f18e8dfde8
commit 311e3b51c6
10 changed files with 24 additions and 24 deletions

View file

@ -184,7 +184,7 @@ punydecode(uint input_length, char input[], uint max_out, Rune output[])
* convert punycode encoded internationalized
* domain name to unicode string
*/
char*
int
idn2utf(char *name, char *buf, int nbuf)
{
char *dp, *de, *cp;
@ -205,24 +205,24 @@ idn2utf(char *name, char *buf, int nbuf)
}
if(cistrncmp(cp, "xn--", 4) == 0)
if((nr = punydecode(nc-4, cp+4, nelem(rb), rb)) < 0)
return nil;
return -1;
dp = seprint(dp, de, "%.*S", nr, rb);
if(dp >= de)
return nil;
return -1;
if(cp[nc] == 0)
break;
*dp++ = '.';
cp += nc+1;
}
*dp = 0;
return buf;
return dp - buf;
}
/*
* convert unicode string to punycode
* encoded internationalized domain name
*/
char*
int
utf2idn(char *name, char *buf, int nbuf)
{
char *dp, *de, *cp;
@ -246,17 +246,17 @@ utf2idn(char *name, char *buf, int nbuf)
else {
dp = seprint(dp, de, "xn--");
if((n = punyencode(nr, rb, de - dp, dp)) < 0)
return nil;
return -1;
dp += n;
}
if(dp >= de)
return nil;
return -1;
if(cp[nc] == 0)
break;
*dp++ = '.';
cp += nc+1;
}
*dp = 0;
return buf;
return dp - buf;
}