diff options
author | Chris Lattner <sabre@nondot.org> | 2001-12-13 00:44:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-12-13 00:44:09 +0000 |
commit | 75ad704490f402406e0e59ebb9173245d785710a (patch) | |
tree | bbd863166aaa150f3db26b1bf42871a9d63a2ea7 /tools | |
parent | e7c6f726c8d18ff8803d9b3dc3a8443496002044 (diff) | |
download | external_llvm-75ad704490f402406e0e59ebb9173245d785710a.zip external_llvm-75ad704490f402406e0e59ebb9173245d785710a.tar.gz external_llvm-75ad704490f402406e0e59ebb9173245d785710a.tar.bz2 |
Implement strlen strdup strcmp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1446 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lli/RuntimeLib.lc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/lli/RuntimeLib.lc b/tools/lli/RuntimeLib.lc index 6a02c23..24922c6 100644 --- a/tools/lli/RuntimeLib.lc +++ b/tools/lli/RuntimeLib.lc @@ -141,6 +141,41 @@ long int atol(const char *nptr) { } +unsigned strlen(const char *Str) { + int Count = 0; + while (*Str) { ++Count; ++Str; } + return Count; +} + +char *strdup(const char *str) { + int Len = strlen(str); + char *Result = (char*)malloc((Len+1)*sizeof(char)); + memcpy(Result, str, Len+1); + return Result; +} + + +/* Compare S1 and S2, returning less than, equal to or + greater than zero if S1 is lexicographically less than, + equal to or greater than S2. */ +int strcmp (const char *p1, const char *p2) { + register const unsigned char *s1 = (const unsigned char *) p1; + register const unsigned char *s2 = (const unsigned char *) p2; + unsigned char c1, c2; + + do + { + c1 = (unsigned char) *s1++; + c2 = (unsigned char) *s2++; + if (c1 == '\0') + return c1 - c2; + } + while (c1 == c2); + + return c1 - c2; +} + + //===----------------------------------------------------------------------===// // memory stuff... //===----------------------------------------------------------------------===// |