9 int aimutil_put8(u_char *buf, u_char data)
11 buf[0] = (u_char)data&0xff;
16 * Endian-ness issues here?
18 int aimutil_put16(u_char *buf, u_short data)
20 buf[0] = (u_char)(data>>8)&0xff;
21 buf[1] = (u_char)(data)&0xff;
25 u_short aimutil_get16(u_char *buf)
28 val = (buf[0] << 8) & 0xff00;
29 val+= (buf[1]) & 0xff;
33 int aimutil_put32(u_char *buf, u_long data)
35 buf[0] = (u_char)(data>>24)&0xff;
36 buf[1] = (u_char)(data>>16)&0xff;
37 buf[2] = (u_char)(data>>8)&0xff;
38 buf[3] = (u_char)(data)&0xff;
42 u_long aimutil_get32(u_char *buf)
45 val = (buf[0] << 24) & 0xff000000;
46 val+= (buf[1] << 16) & 0x00ff0000;
47 val+= (buf[2] << 8) & 0x0000ff00;
48 val+= (buf[3] ) & 0x000000ff;
52 int aimutil_putstr(u_char *dest, const u_char *src, int len)
54 memcpy(dest, src, len);
59 * Tokenizing functions. Used to portably replace strtok/sep.
63 int aimutil_tokslen(char *toSearch, int index, char dl)
71 next = strchr(toSearch, dl);
73 while(curCount < index && next != NULL)
77 next = strchr(last, dl);
80 if ((curCount < index) || (next == NULL))
81 toReturn = strlen(toSearch) - (curCount - 1);
83 toReturn = next - toSearch - (curCount - 1);
88 int aimutil_itemcnt(char *toSearch, char dl)
95 next = strchr(toSearch, dl);
100 next = strchr(next + 1, dl);
106 char *aimutil_itemidx(char *toSearch, int index, char dl)
116 next = strchr(toSearch, dl);
118 while(curCount < index && next != NULL)
122 next = strchr(last, dl);
125 if (curCount < index)
127 toReturn = malloc(sizeof(char));
130 next = strchr(last, dl);
132 if (curCount < index)
134 toReturn = malloc(sizeof(char));
141 toReturn = malloc((strlen(last) + 1) * sizeof(char));
142 strcpy(toReturn, last);
146 toReturn = malloc((next - last + 1) * sizeof(char));
147 memcpy(toReturn, last, (next - last));
148 toReturn[next - last] = '\0';