⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strlib.c

📁 internich公司实现的一个非常非常小的OS
💻 C
字号:
/* * FILENAME: strlib.c * * Copyright 1998- 2004 By InterNiche Technologies Inc. All rights reserved * Portions Copyright 1993 by NetPort software. * * Universal string  functions, provided for systems with no C library.  * Created for minimal C lib support. Portions of this may only have been   * lightly tested. * * MODULE: NTF * * ROUTINES: strcat(), strchr(), strcmp(), strcpy(),  * ROUTINES: strlen(), strncmp(), strncpy(), strstr(),  * * PORTABLE: yes */#include "license.h"#include "ipport.h"#include "in_utils.h"#ifdef INICHE_LIBS/* FUNCTION: strlen() *  * PARAM1: char * str * * RETURNS:  */intstrlen(char * str){   int   len   =  0;   while (*str++) len++;      return(len);}/* FUNCTION: strcpy() *  * PARAM1: char * dest * PARAM2: char * src * * RETURNS:  */char *   strcpy(char * dest, char * src){   char *   ret   =  dest;   while (*src)      *dest++ = *src++;   *dest = 0;   return ret;}/* FUNCTION: strncpy() *  * PARAM1: char * dest * PARAM2: char * src * PARAM3: int maxcopy * * RETURNS:  */char *   strncpy(char * dest, char * src, int maxcopy){   char *   ret   =  dest;   while (*src && maxcopy)   {         *dest++ = *src++;      maxcopy--;   }   *dest = 0;  /* null terminate string */   return ret;}/* FUNCTION: strcmp() *  * PARAM1: char * str1 * PARAM2: char * str2 * * RETURNS:  */intstrcmp(char * str1, char * str2){   while (*str1)   {      if (*str1 > *str2) return 1;         if (*str1++ < *str2++) return -1;         }   /* added by jharan, 4-26-99 */   /* if we have not gotten to the end of str2 by the time we have      gotten to the end of the str1, then str1 is less than str2 */   if (*str2)      return -1;   return 0;}/* FUNCTION: strncmp() *  * PARAM1: char * str1 * PARAM2: char * str2 * PARAM3: int length * * RETURNS:  */int strncmp(char * str1, char * str2, int length){   while (length--)   {      if (*str1 > *str2)         return 1;      if (*str1++ < *str2++)         return -1;   }   return 0;}/* FUNCTION: strcat() *  * PARAM1: char * str1 * PARAM2: char * str2 * * RETURNS:  */char *   strcat(char * str1, char * str2){   char *   cp;   cp = str1;   while (*cp)    /* find null at the end of str1 */      cp++;   while (*str2)  /* copy str2 onto end */      *cp++ = *str2++;   *cp = 0;       /* null terminate */   return str1;}/* FUNCTION: strchr() *  * PARAM1: char * str * PARAM2: char chr * * RETURNS:  */char * strchr(char * str, char chr){   while (*str)   {      if (*str == chr)         return str;      else         str++;   }   if (chr == 0)  /* caller was looking for null */      return str; /* return pointer to null */   return (char*)0;}/* FUNCTION: strstr() * * strstr(str1, str2) - look for str2 inside str1 * *  * PARAM1: char * str1 * PARAM2: char * str2 * * RETURNS:  */char * strstr(char * str1, char * str2){   while (*str1)   {      if (*str1 == *str2)  /* found first char of str2 in str1 */      {         if (strncmp(str1, str2, strlen(str2)) == 0)         {            return str1;   /* found str2 at str1 */         }      }      str1++;   }   return (char*)0;}#endif   /* INICHE_LIBS */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -