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 *memcpyold(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 /*
00080   for (i = 0; i < y; i++) {
00081     ((char *) dst)[length-y+i] = ((char *) src)[length-y+i];
00082     }
00083 */
00084   for (i = 0x0;i < length;i++)
00085     ((char *)dst)[i] = ((char *)src)[i];
00086 
00087   return((void *)dst);
00088   }
00089 
00090 
00091 int strlen(const char * string) {
00092   int i = 0;
00093 
00094   while (1) {
00095     if (string[i] == '\0')
00096       return i;
00097     i++;
00098     }
00099   return 0;
00100   }  
00101 
00102 int memcmp(const void * dst, const void * src, size_t length)
00103 {
00104     size_t x = length >> 2;
00105     size_t y = length & 0xf;
00106     size_t i;
00107 
00108     for (i = 0; i < x; i++)
00109     {
00110         if (((unsigned long *)dst)[i] > ((unsigned long *)src)[i])
00111             return 1;
00112         if (((unsigned long *)dst)[i] < ((unsigned long *)src)[i])
00113             return -1;
00114     }
00115 
00116     for (i = 0; i < y; i++)
00117     {
00118         if (((char *) dst)[length-y+i] > ((char *) src)[length-y+i])
00119             return 1;
00120         if (((char *) dst)[length-y+i] < ((char *) src)[length-y+i])
00121             return -1;
00122     }
00123 
00124     return 0;
00125 }
00126 
00127 void strncpy(char * dest, const char * src, size_t size)
00128 {
00129     if (size == 0)
00130         return;
00131     do
00132     {
00133         *dest = *src;
00134         dest++; src++;
00135         size--;
00136     }
00137     while(('\0' != *(src-1)) && (size));
00138 }
00139 
00140 char *strstr(const char *s,char *find) {
00141   char c, sc;
00142   size_t len;
00143 
00144   if ((c = *find++) != 0) {
00145     len = strlen(find);
00146     do {
00147       do {
00148         if ((sc = *s++) == 0)
00149           return (NULL);
00150         } while (sc != c);
00151       } while (strncmp(s, find, len) != 0);
00152     s--;
00153     }
00154   return ((char *)s);
00155   }
00156 
00157 
00158 /***
00159  $Log$
00160  Revision 1.2  2006/12/05 14:10:21  reddawg
00161  Workign Distro
00162 
00163  Revision 1.1.1.1  2006/06/01 12:46:16  reddawg
00164  ubix2
00165 
00166  Revision 1.2  2005/10/12 00:13:37  reddawg
00167  Removed
00168 
00169  Revision 1.1.1.1  2005/09/26 17:24:13  reddawg
00170  no message
00171 
00172  Revision 1.6  2004/07/28 15:05:43  reddawg
00173  Major:
00174    Pages now have strict security enforcement.
00175    Many null dereferences have been resolved.
00176    When apps loaded permissions set for pages rw and ro
00177 
00178  Revision 1.5  2004/07/20 18:42:41  flameshadow
00179  add: strcpy()
00180  chg: modified dirCache.c to use strcpy()
00181 
00182  Revision 1.4  2004/07/05 23:06:32  reddawg
00183  Fixens
00184 
00185  Revision 1.3  2004/06/28 23:12:58  reddawg
00186  file format now container:/path/to/file
00187 
00188  Revision 1.2  2004/05/19 14:40:58  reddawg
00189  Cleaned up some warning from leaving out typedefs
00190 
00191  Revision 1.1.1.1  2004/04/15 12:07:11  reddawg
00192  UbixOS v1.0
00193 
00194  Revision 1.5  2004/04/13 16:36:33  reddawg
00195  Changed our copyright, it is all now under a BSD-Style license
00196 
00197  END
00198  ***/
00199 

Generated on Tue Dec 5 09:28:05 2006 for UbixOS V2 by  doxygen 1.4.7