- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# 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: string_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <lib/string.h>
    00031
    00032 int strcmp(const char *str1,const char *str2) {
    00033   while ((*str1 == *str2) && (*str1 != 0x0) && (*str2 != 0x0)) {
    00034     str1++;
    00035     str2++;
    00036     }
    00037   if (*str1 == *str2) {
    00038     return(0);
    00039     }
    00040   else if (*str1 > *str2) {
    00041     return(1);
    00042     }
    00043   else {
    00044     return(-1);
    00045     }
    00046   }
    00047
    00048 int strncmp(const char * a, const char * b, size_t c) {
    00049   int i = 0;
    00050   while (i < c) {
    00051     if ((a[i] != b[i]) || (a[i] == '\0') || (b[i] == '\0'))
    00052       return a[i] - b[i];
    00053     i++;
    00054     }
    00055   return 0;
    00056   }
    00057
    00058
    00059
    00060 void *memcpyold(const void *dst, const void * src, size_t length) {
    00061   //size_t x = length >> 2;
    00062   //size_t y = length;// & 0xf;
    00063   size_t i;
    00064 /*
    00065   for (i = 0; i < x; i++) {
    00066     ((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
    00067     }
    00068 */
    00069 /*
    00070   for (i = 0; i < y; i++) {
    00071     ((char *) dst)[length-y+i] = ((char *) src)[length-y+i];
    00072     }
    00073 */
    00074   for (i = 0x0;i < length;i++)
    00075     ((char *)dst)[i] = ((char *)src)[i];
    00076
    00077   return((void *)dst);
    00078   }
    00079
    00080 int memcmp(const void * dst, const void * src, size_t length)
    00081 {
    00082     size_t x = length >> 2;
    00083     size_t y = length & 0xf;
    00084     size_t i;
    00085
    00086     for (i = 0; i < x; i++)
    00087     {
    00088         if (((unsigned long *)dst)[i] > ((unsigned long *)src)[i])
    00089             return 1;
    00090         if (((unsigned long *)dst)[i] < ((unsigned long *)src)[i])
    00091             return -1;
    00092     }
    00093
    00094     for (i = 0; i < y; i++)
    00095     {
    00096         if (((char *) dst)[length-y+i] > ((char *) src)[length-y+i])
    00097             return 1;
    00098         if (((char *) dst)[length-y+i] < ((char *) src)[length-y+i])
    00099             return -1;
    00100     }
    00101
    00102     return 0;
    00103 }
    00104
    00105 void strncpy(char * dest, const char * src, size_t size)
    00106 {
    00107     if (size == 0)
    00108         return;
    00109     do
    00110     {
    00111         *dest = *src;
    00112         dest++; src++;
    00113         size--;
    00114     }
    00115     while(('\0' != *(src-1)) && (size));
    00116 }
    00117
    00118 char *strstr(const char *s,char *find) {
    00119   char c, sc;
    00120   size_t len;
    00121
    00122   if ((c = *find++) != 0) {
    00123     len = strlen(find);
    00124     do {
    00125       do {
    00126         if ((sc = *s++) == 0)
    00127           return (NULL);
    00128         } while (sc != c);
    00129       } while (strncmp(s, find, len) != 0);
    00130     s--;
    00131     }
    00132   return ((char *)s);
    00133   }
    00134
    00135
    00136 /***
    00137  $Log: string_8c-source.html,v $
    00137  Revision 1.7  2006/12/15 17:47:07  reddawg
    00137  Updates
    00137
    00138  Revision 1.3  2006/12/12 14:09:18  reddawg
    00139  Changes
    00140
    00141  Revision 1.2  2006/12/05 14:10:21  reddawg
    00142  Workign Distro
    00143
    00144  Revision 1.1.1.1  2006/06/01 12:46:16  reddawg
    00145  ubix2
    00146
    00147  Revision 1.2  2005/10/12 00:13:37  reddawg
    00148  Removed
    00149
    00150  Revision 1.1.1.1  2005/09/26 17:24:13  reddawg
    00151  no message
    00152
    00153  Revision 1.6  2004/07/28 15:05:43  reddawg
    00154  Major:
    00155    Pages now have strict security enforcement.
    00156    Many null dereferences have been resolved.
    00157    When apps loaded permissions set for pages rw and ro
    00158
    00159  Revision 1.5  2004/07/20 18:42:41  flameshadow
    00160  add: strcpy()
    00161  chg: modified dirCache.c to use strcpy()
    00162
    00163  Revision 1.4  2004/07/05 23:06:32  reddawg
    00164  Fixens
    00165
    00166  Revision 1.3  2004/06/28 23:12:58  reddawg
    00167  file format now container:/path/to/file
    00168
    00169  Revision 1.2  2004/05/19 14:40:58  reddawg
    00170  Cleaned up some warning from leaving out typedefs
    00171
    00172  Revision 1.1.1.1  2004/04/15 12:07:11  reddawg
    00173  UbixOS v1.0
    00174
    00175  Revision 1.5  2004/04/13 16:36:33  reddawg
    00176  Changed our copyright, it is all now under a BSD-Style license
    00177
    00178  END
    00179  ***/
    00180