string.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2004 The UbixOS Project
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are
00006  permitted provided that the following conditions are met:
00007 
00008  Redistributions of source code must retain the above copyright notice, this list of
00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010  form must reproduce the above copyright notice, this list of conditions, the following
00011  disclaimer and the list of authors in the documentation and/or other materials provided
00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
00013  contributors may be used to endorse or promote products derived from this software
00014  without specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Id$
00027 
00028 *****************************************************************************************/
00029 
00030 #include <lib/string.h>
00031 
00032 char *
00033 strcpy(char * dst, const char * src) {
00034   char * tmp = dst;
00035   do {
00036     *dst = *src;
00037     dst++;
00038   } while (*src++ != '\0');
00039   return tmp;
00040 } /* strcpy */
00041 
00042 int strcmp(const char *str1,const char *str2) {
00043   while ((*str1 == *str2) && (*str1 != 0x0) && (*str2 != 0x0)) {
00044     str1++;
00045     str2++;
00046     }
00047   if (*str1 == *str2) {
00048     return(0);
00049     }
00050   else if (*str1 > *str2) {
00051     return(1);
00052     }
00053   else {
00054     return(-1);
00055     }
00056   }
00057 
00058 int strncmp(const char * a, const char * b, size_t c) {
00059   int i = 0;
00060   while (i < c) {
00061     if ((a[i] != b[i]) || (a[i] == '\0') || (b[i] == '\0'))
00062       return a[i] - b[i];
00063     i++;
00064     }
00065   return 0;
00066   }
00067 
00068 
00069 
00070 void *memcpy(const void *dst, const void * src, size_t length) {
00071   size_t x = length >> 2;
00072   size_t y = length & 0xf;
00073   size_t i;
00074 
00075   for (i = 0; i < x; i++) {
00076     ((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
00077     }
00078 
00079   for (i = 0; i < y; i++) {
00080     ((char *) dst)[length-y+i] = ((char *) src)[length-y+i];
00081     }
00082 
00083   return((void *)dst);
00084   }
00085 
00086 
00087 int strlen(const char * string) {
00088   int i = 0;
00089 
00090   while (1) {
00091     if (string[i] == '\0')
00092       return i;
00093     i++;
00094     }
00095   return 0;
00096   }  
00097 
00098 int memcmp(const void * dst, const void * src, size_t length)
00099 {
00100     size_t x = length >> 2;
00101     size_t y = length & 0xf;
00102     size_t i;
00103 
00104     for (i = 0; i < x; i++)
00105     {
00106         if (((unsigned long *)dst)[i] > ((unsigned long *)src)[i])
00107             return 1;
00108         if (((unsigned long *)dst)[i] < ((unsigned long *)src)[i])
00109             return -1;
00110     }
00111 
00112     for (i = 0; i < y; i++)
00113     {
00114         if (((char *) dst)[length-y+i] > ((char *) src)[length-y+i])
00115             return 1;
00116         if (((char *) dst)[length-y+i] < ((char *) src)[length-y+i])
00117             return -1;
00118     }
00119 
00120     return 0;
00121 }
00122 
00123 void strncpy(char * dest, const char * src, size_t size)
00124 {
00125     if (size == 0)
00126         return;
00127     do
00128     {
00129         *dest = *src;
00130         dest++; src++;
00131         size--;
00132     }
00133     while(('\0' != *(src-1)) && (size));
00134 }
00135 
00136 char *strstr(const char *s,char *find) {
00137   char c, sc;
00138   size_t len;
00139 
00140   if ((c = *find++) != 0) {
00141     len = strlen(find);
00142     do {
00143       do {
00144         if ((sc = *s++) == 0)
00145           return (NULL);
00146         } while (sc != c);
00147       } while (strncmp(s, find, len) != 0);
00148     s--;
00149     }
00150   return ((char *)s);
00151   }
00152 
00153 
00154 /***
00155  $Log$
00156  Revision 1.1.1.1  2006/06/01 12:46:16  reddawg
00157  ubix2
00158 
00159  Revision 1.2  2005/10/12 00:13:37  reddawg
00160  Removed
00161 
00162  Revision 1.1.1.1  2005/09/26 17:24:13  reddawg
00163  no message
00164 
00165  Revision 1.6  2004/07/28 15:05:43  reddawg
00166  Major:
00167    Pages now have strict security enforcement.
00168    Many null dereferences have been resolved.
00169    When apps loaded permissions set for pages rw and ro
00170 
00171  Revision 1.5  2004/07/20 18:42:41  flameshadow
00172  add: strcpy()
00173  chg: modified dirCache.c to use strcpy()
00174 
00175  Revision 1.4  2004/07/05 23:06:32  reddawg
00176  Fixens
00177 
00178  Revision 1.3  2004/06/28 23:12:58  reddawg
00179  file format now container:/path/to/file
00180 
00181  Revision 1.2  2004/05/19 14:40:58  reddawg
00182  Cleaned up some warning from leaving out typedefs
00183 
00184  Revision 1.1.1.1  2004/04/15 12:07:11  reddawg
00185  UbixOS v1.0
00186 
00187  Revision 1.5  2004/04/13 16:36:33  reddawg
00188  Changed our copyright, it is all now under a BSD-Style license
00189 
00190  END
00191  ***/
00192 

Generated on Sun Dec 3 02:38:04 2006 for UbixOS V2 by  doxygen 1.4.7