aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/auth/factotum/util.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-13 05:59:29 +0000
committerrsc <devnull@localhost>2005-02-13 05:59:29 +0000
commit6e527fbc4d8f404a7eec934e5c9efaaaa92ffdff (patch)
tree4d9ed63c88e5a8dd8a4d5bd3582e7d5e6a24065f /src/cmd/auth/factotum/util.c
parent0f8ec41b0ae522b73085fa1662461e6351ba7e54 (diff)
downloadplan9port-6e527fbc4d8f404a7eec934e5c9efaaaa92ffdff.tar.gz
plan9port-6e527fbc4d8f404a7eec934e5c9efaaaa92ffdff.tar.bz2
plan9port-6e527fbc4d8f404a7eec934e5c9efaaaa92ffdff.zip
new auth
Diffstat (limited to 'src/cmd/auth/factotum/util.c')
-rw-r--r--src/cmd/auth/factotum/util.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/cmd/auth/factotum/util.c b/src/cmd/auth/factotum/util.c
new file mode 100644
index 00000000..accddddd
--- /dev/null
+++ b/src/cmd/auth/factotum/util.c
@@ -0,0 +1,54 @@
+#include "std.h"
+#include "dat.h"
+
+static int
+unhex(char c)
+{
+ if('0' <= c && c <= '9')
+ return c-'0';
+ if('a' <= c && c <= 'f')
+ return c-'a'+10;
+ if('A' <= c && c <= 'F')
+ return c-'A'+10;
+ abort();
+ return -1;
+}
+
+int
+hexparse(char *hex, uchar *dat, int ndat)
+{
+ int i, n;
+
+ n = strlen(hex);
+ if(n%2)
+ return -1;
+ n /= 2;
+ if(n > ndat)
+ return -1;
+ if(hex[strspn(hex, "0123456789abcdefABCDEF")] != '\0')
+ return -1;
+ for(i=0; i<n; i++)
+ dat[i] = (unhex(hex[2*i])<<4)|unhex(hex[2*i+1]);
+ return n;
+}
+
+char*
+estrappend(char *s, char *fmt, ...)
+{
+ char *t;
+ int l;
+ va_list arg;
+
+ va_start(arg, fmt);
+ t = vsmprint(fmt, arg);
+ if(t == nil)
+ sysfatal("out of memory");
+ va_end(arg);
+ l = s ? strlen(s) : 0;
+ s = erealloc(s, l+strlen(t)+1);
+ strcpy(s+l, t);
+ free(t);
+ return s;
+}
+
+