git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of
[email protected]
:acess2
[tpg/acess2.git]
/
Kernel
/
lib.c
diff --git
a/Kernel/lib.c
b/Kernel/lib.c
index
b9e9734
..
27995b0
100644
(file)
--- a/
Kernel/lib.c
+++ b/
Kernel/lib.c
@@
-14,11
+14,14
@@
const short DAYS_BEFORE[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 3
#define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years
// === PROTOTYPES ===
#define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years
// === PROTOTYPES ===
+#if 0
int atoi(const char *string);
int atoi(const char *string);
-void itoa(char *buf, Uint num, int base, int minLength, char pad);
+void itoa(char *buf, Uint
64
num, int base, int minLength, char pad);
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args);
int sprintf(char *__s, const char *__format, ...);
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args);
int sprintf(char *__s, const char *__format, ...);
+#endif
int tolower(int c);
int tolower(int c);
+#if 0
int strucmp(const char *Str1, const char *Str2);
char *strchr(const char *__s, int __c);
int strpos(const char *Str, char Ch);
int strucmp(const char *Str1, const char *Str2);
char *strchr(const char *__s, int __c);
int strpos(const char *Str, char Ch);
@@
-33,10
+36,9
@@
char **str_split(const char *__str, char __ch);
int strpos8(const char *str, Uint32 Search);
int ReadUTF8(Uint8 *str, Uint32 *Val);
int WriteUTF8(Uint8 *str, Uint32 Val);
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);
int DivUp(int num, int dem);
Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year);
-
U
int rand(void);
+
int rand(void);
int CheckString(char *String);
int CheckMem(void *Mem, int NumBytes);
int CheckString(char *String);
int CheckMem(void *Mem, int NumBytes);
@@
-45,6
+47,7
@@
Uint rand(void);
int ModUtil_SetIdent(char *Dest, char *Value);
int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
int ModUtil_SetIdent(char *Dest, char *Value);
int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
+#endif
// === EXPORTS ===
EXPORT(atoi);
// === EXPORTS ===
EXPORT(atoi);
@@
-145,12
+148,12
@@
int atoi(const char *string)
static const char cUCDIGITS[] = "0123456789ABCDEF";
/**
static const char cUCDIGITS[] = "0123456789ABCDEF";
/**
- * \fn void itoa(char *buf, Uint num, int base, int minLength, char pad)
+ * \fn void itoa(char *buf, Uint
64
num, int base, int minLength, char pad)
* \brief Convert an integer into a character string
*/
* \brief Convert an integer into a character string
*/
-void itoa(char *buf, Uint num, int base, int minLength, char pad)
+void itoa(char *buf, Uint
64
num, int base, int minLength, char pad)
{
{
- char tmpBuf[
BITS
];
+ char tmpBuf[
64+1
];
int pos=0, i;
// Sanity check
int pos=0, i;
// Sanity check
@@
-196,9
+199,9
@@
void itoa(char *buf, Uint num, int base, int minLength, char pad)
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
{
char c, pad = ' ';
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
{
char c, pad = ' ';
- int minSize = 0, len;
+ int minSize = 0,
precision = -1,
len;
char tmpBuf[34]; // For Integers
char tmpBuf[34]; // For Integers
- c
har
*p = NULL;
+ c
onst char
*p = NULL;
int isLongLong = 0;
Uint64 val;
size_t pos = 0;
int isLongLong = 0;
Uint64 val;
size_t pos = 0;
@@
-222,13
+225,13
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
if(c == 'p') {
Uint ptr = va_arg(args, Uint);
PUTCH('*'); PUTCH('0'); PUTCH('x');
if(c == 'p') {
Uint ptr = va_arg(args, Uint);
PUTCH('*'); PUTCH('0'); PUTCH('x');
+ itoa(tmpBuf, ptr, 16, BITS/4, '0');
p = tmpBuf;
p = tmpBuf;
- itoa(p, ptr, 16, BITS/4, '0');
goto printString;
}
// - Padding Side Flag
goto printString;
}
// - Padding Side Flag
- if(c == '
+
') {
+ if(c == '
-
') {
bPadLeft = 1;
c = *__format++;
}
bPadLeft = 1;
c = *__format++;
}
@@
-257,7
+260,28
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
}
}
else
}
}
else
- minSize = 1;
+ minSize = 0;
+
+ // - Precision
+ precision = -1;
+ if( c == '.' ) {
+ c = *__format++;
+
+ if(c == '*') { // Dynamic length
+ precision = va_arg(args, unsigned int);
+ c = *__format++;
+ }
+ else if('1' <= c && c <= '9')
+ {
+ precision = 0;
+ while('0' <= c && c <= '9')
+ {
+ precision *= 10;
+ precision += c - '0';
+ c = *__format++;
+ }
+ }
+ }
// - Default, Long or LongLong?
isLongLong = 0;
// - Default, Long or LongLong?
isLongLong = 0;
@@
-285,31
+309,30
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
PUTCH('-');
val = -(Sint32)val;
}
PUTCH('-');
val = -(Sint32)val;
}
- itoa(
p
, val, 10, minSize, pad);
+ itoa(
tmpBuf
, val, 10, minSize, pad);
goto printString;
case 'u':
GETVAL();
goto printString;
case 'u':
GETVAL();
- itoa(
p
, val, 10, minSize, pad);
+ itoa(
tmpBuf
, val, 10, minSize, pad);
goto printString;
case 'X':
goto printString;
case 'X':
- #if BITS == 64
- isLongLong = 1; // TODO: Handle non-x86 64-bit archs
- #endif
+ if(BITS == 64)
+ isLongLong = 1; // TODO: Handle non-x86 64-bit archs
GETVAL();
GETVAL();
- itoa(
p
, val, 16, minSize, pad);
+ itoa(
tmpBuf
, val, 16, minSize, pad);
goto printString;
case 'x':
GETVAL();
goto printString;
case 'x':
GETVAL();
- itoa(
p
, val, 16, minSize, pad);
+ itoa(
tmpBuf
, val, 16, minSize, pad);
goto printString;
case 'o':
GETVAL();
goto printString;
case 'o':
GETVAL();
- itoa(
p
, val, 8, minSize, pad);
+ itoa(
tmpBuf
, val, 8, minSize, pad);
goto printString;
case 'b':
GETVAL();
goto printString;
case 'b':
GETVAL();
- itoa(
p
, val, 2, minSize, pad);
+ itoa(
tmpBuf
, val, 2, minSize, pad);
goto printString;
case 'B': //Boolean
goto printString;
case 'B': //Boolean
@@
-321,12
+344,12
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
// String - Null Terminated Array
case 's':
p = va_arg(args, char*); // Get Argument
// String - Null Terminated Array
case 's':
p = va_arg(args, char*); // Get Argument
- if( !CheckString(p) )
continue;
// Avoid #PFs
+ if( !CheckString(p) )
p = "(inval)";
// Avoid #PFs
printString:
if(!p) p = "(null)";
len = strlen(p);
if( !bPadLeft ) while(len++ < minSize) PUTCH(pad);
printString:
if(!p) p = "(null)";
len = strlen(p);
if( !bPadLeft ) while(len++ < minSize) PUTCH(pad);
- while(*p
)
PUTCH(*p++);
+ while(*p
&& precision--)
PUTCH(*p++);
if( bPadLeft ) while(len++ < minSize) PUTCH(pad);
break;
if( bPadLeft ) while(len++ < minSize) PUTCH(pad);
break;
@@
-419,20
+442,21
@@
int strpos(const char *Str, char Ch)
* \fn Uint8 ByteSum(void *Ptr, int Size)
* \brief Adds the bytes in a memory region and returns the sum
*/
* \fn Uint8 ByteSum(void *Ptr, int Size)
* \brief Adds the bytes in a memory region and returns the sum
*/
-Uint8 ByteSum(void *Ptr, int Size)
+Uint8 ByteSum(
const
void *Ptr, int Size)
{
Uint8 sum = 0;
{
Uint8 sum = 0;
- while(Size--) sum += *(Uint8*)Ptr++;
+ const Uint8 *data = Ptr;
+ while(Size--) sum += *(data++);
return sum;
}
/**
return sum;
}
/**
- * \fn
Uin
t strlen(const char *__str)
+ * \fn
size_
t strlen(const char *__str)
* \brief Get the length of string
*/
* \brief Get the length of string
*/
-
Uin
t strlen(const char *__str)
+
size_
t strlen(const char *__str)
{
{
-
Uint
ret = 0;
+
size_t
ret = 0;
while(*__str++) ret++;
return ret;
}
while(*__str++) ret++;
return ret;
}
@@
-594,7
+618,7
@@
int strpos8(const char *str, Uint32 Search)
* \fn int ReadUTF8(Uint8 *str, Uint32 *Val)
* \brief Read a UTF-8 character from a string
*/
* \fn int ReadUTF8(Uint8 *str, Uint32 *Val)
* \brief Read a UTF-8 character from a string
*/
-int ReadUTF8(Uint8 *str, Uint32 *Val)
+int ReadUTF8(
const
Uint8 *str, Uint32 *Val)
{
*Val = 0xFFFD; // Assume invalid character
{
*Val = 0xFFFD; // Assume invalid character
@@
-722,11
+746,10
@@
Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year)
}
/**
}
/**
- * \fn
U
int rand()
+ * \fn int rand()
* \brief Pseudo random number generator
* \brief Pseudo random number generator
- * \note Unknown effectiveness (made up on the spot)
*/
*/
-
U
int rand(void)
+int rand(void)
{
#if 0
static Uint state = RANDOM_SEED;
{
#if 0
static Uint state = RANDOM_SEED;
@@
-758,7
+781,7
@@
Uint rand(void)
/**
* \brief Checks if a string resides fully in valid memory
*/
/**
* \brief Checks if a string resides fully in valid memory
*/
-int CheckString(char *String)
+int CheckString(c
onst c
har *String)
{
if( !MM_GetPhysAddr( (tVAddr)String ) )
return 0;
{
if( !MM_GetPhysAddr( (tVAddr)String ) )
return 0;
@@
-794,7
+817,7
@@
int CheckString(char *String)
/**
* \brief Check if a sized memory region is valid memory
*/
/**
* \brief Check if a sized memory region is valid memory
*/
-int CheckMem(void *Mem, int NumBytes)
+int CheckMem(
const
void *Mem, int NumBytes)
{
tVAddr addr = (tVAddr)Mem;
{
tVAddr addr = (tVAddr)Mem;
@@
-828,7
+851,7
@@
int CheckMem(void *Mem, int NumBytes)
* \brief Search a string array for \a Needle
* \note Helper function for eTplDrv_IOCtl::DRV_IOCTL_LOOKUP
*/
* \brief Search a string array for \a Needle
* \note Helper function for eTplDrv_IOCtl::DRV_IOCTL_LOOKUP
*/
-int ModUtil_LookupString(c
har **Array,
char *Needle)
+int ModUtil_LookupString(c
onst char **Array, const
char *Needle)
{
int i;
if( !CheckString(Needle) ) return -1;
{
int i;
if( !CheckString(Needle) ) return -1;
@@
-839,7
+862,7
@@
int ModUtil_LookupString(char **Array, char *Needle)
return -1;
}
return -1;
}
-int ModUtil_SetIdent(char *Dest, char *Value)
+int ModUtil_SetIdent(char *Dest, c
onst c
har *Value)
{
if( !CheckMem(Dest, 32) ) return -1;
strncpy(Dest, Value, 32);
{
if( !CheckMem(Dest, 32) ) return -1;
strncpy(Dest, Value, 32);
UCC
git Repository :: git.ucc.asn.au