General Cleanup, Implemented DMA Allocation
[tpg/acess2.git] / Kernel / lib.c
index c106351..3d91c71 100644 (file)
@@ -56,7 +56,7 @@ void itoa(char *buf, Uint num, int base, int minLength, char pad)
 }
 
 /**
- * \fn int tolower(int __c)
+ * \fn int tolower(int c)
  * \brief Converts a character to lower case
  */
 int tolower(int c)
@@ -70,7 +70,7 @@ int tolower(int c)
  * \fn int strucmp(char *Str1, char *Str2)
  * \brief Compare \a Str1 and \a Str2 case-insensitively
  */
-int strucmp(char *Str1, char *Str2)
+int strucmp(const char *Str1, const char *Str2)
 {
        while(*Str1 && tolower(*Str1) == tolower(*Str2))
                Str1++, Str2++;
@@ -78,10 +78,10 @@ int strucmp(char *Str1, char *Str2)
 }
 
 /**
- * \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(char *Str, char Ch)
+int strpos(const char *Str, char Ch)
 {
         int    pos;
        for(pos=0;Str[pos];pos++)
@@ -92,6 +92,8 @@ int strpos(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)
 {
@@ -101,10 +103,10 @@ 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(char *__str)
+Uint strlen(const char *__str)
 {
        Uint    ret = 0;
        while(*__str++) ret++;
@@ -112,10 +114,10 @@ Uint strlen(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, char *__str2)
+char *strcpy(char *__str1, const char *__str2)
 {
        while(*__str2)
                *__str1++ = *__str2++;
@@ -124,11 +126,11 @@ char *strcpy(char *__str1, 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.
  */
-int strcmp(char *str1, char *str2)
+int strcmp(const char *str1, const char *str2)
 {
        while(*str1 && *str1 == *str2)
                str1++, str2++;
@@ -136,33 +138,45 @@ int strcmp(char *str1, char *str2)
 }
 
 /**
- * \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(char *Str1, char *Str2, size_t num)
+int strncmp(const char *Str1, const char *Str2, size_t num)
 {
-       while(num-- && *Str1 && *Str1 == *Str2)
+       if(num == 0)    return 0;       // TODO: Check what should officially happen here
+       while(--num && *Str1 && *Str1 == *Str2)
                Str1++, Str2++;
        return *Str1-*Str2;
 }
 
 /**
- * \fn char *strdup(char *str)
+ * \fn char *strdup(const char *Str)
  * \brief Duplicates a string
  */
-char *strdup(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;
 }
 
 /**
- * \fn int strpos8(char *str, Uint32 search)
+ * \fn int DivUp(int num, int dem)
+ * \brief Divide two numbers, rounding up
+ * \param num  Numerator
+ * \param dem  Denominator
+ */
+int DivUp(int num, int dem)
+{
+       return (num+dem-1)/dem;
+}
+
+/**
+ * \fn int strpos8(const char *str, Uint32 search)
  * \brief Search a string for a UTF-8 character
  */
-int strpos8(char *str, Uint32 Search)
+int strpos8(const char *str, Uint32 Search)
 {
         int    pos;
        Uint32  val = 0;

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