Kernel/IPStack - (minor) TODO retransmit timer
[tpg/acess2.git] / Tools / nativelib / misc.c
1 /*
2  * Acess2 nativelib
3  * - By John Hodge (thePowersGang)
4  * 
5  * misc.c
6  * - Random functions
7  */
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>    // strcasecmp
13
14 // TODO: Move into a helper lib?
15 void itoa(char *buf, uint64_t num, int base, int minLength, char pad)
16 {
17         char fmt[] = "%0ll*x";
18         switch(base)
19         {
20         case  8:        fmt[5] = 'o';   break;
21         case 10:        fmt[5] = 'd';   break;
22         case 16:        fmt[5] = 'x';   break;
23         }
24         if(pad != '0') {
25                 fmt[1] = '%';
26                 sprintf(buf, fmt+1, minLength, num);
27         }
28         else {
29                 sprintf(buf, fmt, minLength, num);
30         }
31 }
32
33 int ParseInt(const char *string, int *value)
34 {
35         char *next;
36         *value = strtol(string, &next, 0);
37         return next - string;
38 }
39
40 int strpos(const char *Str, char Ch)
41 {
42         const char *r = strchr(Str, Ch);
43         if(!r)  return -1;
44         return r - Str;
45 }
46
47 int strucmp(const char *s1, const char *s2)
48 {
49         return strcasecmp(s1, s2);
50 }
51
52 uint64_t DivMod64U(uint64_t value, uint64_t divisor, uint64_t *remainder)
53 {
54         if(remainder)
55                 *remainder = value % divisor;
56         return value / divisor;
57 }

UCC git Repository :: git.ucc.asn.au