int sprintf(char *__s, const char *__format, ...);
int tolower(int c);
int strucmp(const char *Str1, const char *Str2);
+char *strchr(const char *__s, int __c);
int strpos(const char *Str, char Ch);
Uint8 ByteSum(void *Ptr, int Size);
size_t strlen(const char *__s);
int strpos8(const char *str, Uint32 Search);
int ReadUTF8(Uint8 *str, Uint32 *Val);
int WriteUTF8(Uint8 *str, Uint32 Val);
+
int DivUp(int num, int dem);
Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year);
-Uint rand(void);
+ int rand(void);
+
int CheckString(char *String);
int CheckMem(void *Mem, int NumBytes);
+
int ModUtil_LookupString(char **Array, char *Needle);
int ModUtil_SetIdent(char *Dest, char *Value);
+
+ int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
// === EXPORTS ===
EXPORT(atoi);
EXPORT(sprintf);
EXPORT(tolower);
EXPORT(strucmp);
+EXPORT(strchr);
EXPORT(strpos);
EXPORT(ByteSum);
EXPORT(strlen);
EXPORT(CheckMem);
EXPORT(ModUtil_LookupString);
EXPORT(ModUtil_SetIdent);
+EXPORT(UnHex);
// === CODE ===
/**
GETVAL();
itoa(p, val, 10, minSize, pad);
goto printString;
+ case 'X':
+ if(BITS == 64)
+ isLongLong = 1; // TODO: Handle non-x86 64-bit archs
+ GETVAL();
+ itoa(p, val, 16, minSize, pad);
+ goto printString;
+
case 'x':
GETVAL();
itoa(p, val, 16, minSize, pad);
// String - Null Terminated Array
case 's':
p = va_arg(args, char*); // Get Argument
+ if( !CheckString(p) ) continue; // Avoid #PFs
printString:
if(!p) p = "(null)";
len = strlen(p);
case 'C': // Non-Null Terminated Character Array
p = va_arg(args, char*);
+ if( !CheckMem(p, minSize) ) continue; // No #PFs please
if(!p) goto printString;
while(minSize--) PUTCH(*p++);
break;
return tolower(*Str1) - tolower(*Str2);
}
+/**
+ * \brief Locate a byte in a string
+ */
+char *strchr(const char *__s, int __c)
+{
+ for( ; *__s; __s ++ )
+ {
+ if( *__s == __c ) return (char*)__s;
+ }
+ return NULL;
+}
+
/**
* \fn int strpos(const char *Str, char Ch)
* \brief Search a string for an ascii character
}
/**
- * \fn Uint strlen(const char *__str)
+ * \fn size_t strlen(const char *__str)
* \brief Get the length of string
*/
-Uint strlen(const char *__str)
+size_t strlen(const char *__str)
{
- Uint ret = 0;
+ size_t ret = 0;
while(*__str++) ret++;
return ret;
}
strcpy(ret, Str);
return ret;
}
-#endif
+#else
/**
* \fn char *_strdup(const char *File, int Line, const char *Str)
strcpy(ret, Str);
return ret;
}
+#endif
/**
* \brief Split a string using the passed character
}
/**
- * \fn Uint rand()
+ * \fn int rand()
* \brief Pseudo random number generator
- * \note Unknown effectiveness (made up on the spot)
*/
-Uint rand(void)
+int rand(void)
{
#if 0
static Uint state = RANDOM_SEED;
strncpy(Dest, Value, 32);
return 1;
}
+
+/**
+ * \brief Convert a string of hexadecimal digits into a byte stream
+ */
+int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString)
+{
+ int i;
+
+ for( i = 0; i < DestSize*2; i += 2 )
+ {
+ Uint8 val = 0;
+
+ if(SourceString[i] == '\0') break;
+
+ if('0' <= SourceString[i] && SourceString[i] <= '9')
+ val |= (SourceString[i]-'0') << 4;
+ else if('A' <= SourceString[i] && SourceString[i] <= 'F')
+ val |= (SourceString[i]-'A'+10) << 4;
+ else if('a' <= SourceString[i] && SourceString[i] <= 'f')
+ val |= (SourceString[i]-'a'+10) << 4;
+
+ if(SourceString[i+1] == '\0') break;
+
+ if('0' <= SourceString[i+1] && SourceString[i+1] <= '9')
+ val |= (SourceString[i+1] - '0');
+ else if('A' <= SourceString[i+1] && SourceString[i+1] <= 'F')
+ val |= (SourceString[i+1] - 'A' + 10);
+ else if('a' <= SourceString[i+1] && SourceString[i+1] <= 'f')
+ val |= (SourceString[i+1] - 'a' + 10);
+
+ Dest[i/2] = val;
+ }
+ return i/2;
+}