diff options
Diffstat (limited to 'nacl/curvecp/nameparse.c')
-rw-r--r-- | nacl/curvecp/nameparse.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/nacl/curvecp/nameparse.c b/nacl/curvecp/nameparse.c new file mode 100644 index 00000000..f6386d73 --- /dev/null +++ b/nacl/curvecp/nameparse.c | |||
@@ -0,0 +1,19 @@ | |||
1 | #include "nameparse.h" | ||
2 | |||
3 | int nameparse(unsigned char *s,const char *x) | ||
4 | { | ||
5 | long long pos; | ||
6 | long long j; | ||
7 | if (!x) return 0; | ||
8 | for (pos = 0;pos < 256;++pos) s[pos] = 0; | ||
9 | pos = 0; | ||
10 | while (*x) { | ||
11 | if (*x == '.') { ++x; continue; } | ||
12 | for (j = 0;x[j];++j) if (x[j] == '.') break; | ||
13 | if (j > 63) return 0; | ||
14 | if (pos < 0 || pos >= 256) return 0; s[pos++] = j; | ||
15 | while (j > 0) { if (pos < 0 || pos >= 256) return 0; s[pos++] = *x++; --j; } | ||
16 | } | ||
17 | if (pos < 0 || pos >= 256) return 0; s[pos++] = 0; | ||
18 | return 1; | ||
19 | } | ||