summaryrefslogtreecommitdiff
path: root/sys/src/libc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-09-26 14:32:17 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-09-26 14:32:17 +0200
commit311e3b51c6b1bde2f58968453de56a5ca2a6dbb4 (patch)
tree126a2f4067c6dae52ca0a39a946680c1dff42329 /sys/src/libc
parentf18e8dfde88d00a19a184604865aa4d6383b16f5 (diff)
libc: return number of bytes produced for idn2utf() and utf2idn()
Diffstat (limited to 'sys/src/libc')
-rw-r--r--sys/src/libc/9sys/idn.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/sys/src/libc/9sys/idn.c b/sys/src/libc/9sys/idn.c
index 94ff023a5..d3ad55dd8 100644
--- a/sys/src/libc/9sys/idn.c
+++ b/sys/src/libc/9sys/idn.c
@@ -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;
}