}
/**
- * \fn int tolower(int __c)
+ * \fn int tolower(int c)
* \brief Converts a character to lower case
*/
int tolower(int c)
}
/**
- * \fn int strpos(char *Str, char Ch)
+ * \fn int strpos(const char *Str, char Ch)
* \brief Search a string for an ascii character
*/
int strpos(const char *Str, char Ch)
}
/**
+ * \fn int ByteSum(void *Ptr, int Size)
+ * \brief Adds the bytes in a memory region and returns the sum
*/
int ByteSum(void *Ptr, int Size)
{
}
/**
- * \fn Uint strlen(char *__str)
+ * \fn Uint strlen(const char *__str)
* \brief Get the length of string
*/
Uint strlen(const char *__str)
}
/**
- * \fn char *strcpy(char *__str1, char *__str2)
+ * \fn char *strcpy(const char *__str1, const char *__str2)
* \brief Copy a string to a new location
*/
char *strcpy(char *__str1, const char *__str2)
}
/**
- * \fn int strcmp(char *str1, char *str2)
+ * \fn int strcmp(const char *str1, const char *str2)
* \brief Compare two strings return the difference between
* the first non-matching characters.
*/
}
/**
- * \fn int strncmp(char *Str1, char *Str2, size_t num)
+ * \fn int strncmp(const char *Str1, const char *Str2, size_t num)
* \brief Compare strings \a Str1 and \a Str2 to a maximum of \a num characters
*/
int strncmp(const char *Str1, const char *Str2, size_t num)
}
/**
- * \fn char *strdup(char *str)
+ * \fn char *strdup(const char *Str)
* \brief Duplicates a string
*/
-char *strdup(const char *str)
+char *strdup(const char *Str)
{
char *ret;
- ret = malloc(strlen(str)+1);
- strcpy(ret, str);
+ ret = malloc(strlen(Str)+1);
+ strcpy(ret, Str);
return ret;
}
return giRandomState;
}
+/// \name Memory Validation
+/// \{
+/**
+ * \brief Checks if a string resides fully in valid memory
+ */
+int CheckString(char *String)
+{
+ // Check 1st page
+ if( MM_IsUser( (tVAddr)String ) )
+ {
+ // Traverse String
+ while( *String )
+ {
+ if( !MM_IsUser( (tVAddr)String ) )
+ return 0;
+ // Increment string pointer
+ String ++;
+ }
+ return 1;
+ }
+ else if( MM_GetPhysAddr( (tVAddr)String ) )
+ {
+ // Traverse String
+ while( *String )
+ {
+ if( !MM_GetPhysAddr( (tVAddr)String ) )
+ return 0;
+ // Increment string pointer
+ String ++;
+ }
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * \brief Check if a sized memory region is valid memory
+ */
+int CheckMem(void *Mem, int NumBytes)
+{
+ tVAddr addr = (tVAddr)Mem;
+
+ if( MM_IsUser( addr ) )
+ {
+ while( NumBytes-- )
+ {
+ if( !MM_IsUser( addr ) )
+ return 0;
+ addr ++;
+ }
+ return 1;
+ }
+ else if( MM_GetPhysAddr( addr ) )
+ {
+ while( NumBytes-- )
+ {
+ if( !MM_GetPhysAddr( addr ) )
+ return 0;
+ addr ++;
+ }
+ return 1;
+ }
+ return 0;
+}
+/// \}
+
+/**
+ * \brief Search a string array for \a Needle
+ * \note Helper function for eTplDrv_IOCtl::DRV_IOCTL_LOOKUP
+ */
+int LookupString(char **Array, char *Needle)
+{
+ int i;
+ for( i = 0; Array[i]; i++ )
+ {
+ if(strcmp(Array[i], Needle) == 0) return i;
+ }
+ return -1;
+}
+
+EXPORT(strlen);
+EXPORT(strdup);
+EXPORT(strcmp);
+EXPORT(strncmp);
+EXPORT(strcpy);
+//EXPORT(strncpy);
+
EXPORT(timestamp);
EXPORT(ReadUTF8);
+EXPORT(CheckMem);
+EXPORT(CheckString);
+EXPORT(LookupString);