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

📄 cm_lib.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 2 页
字号:
*
*/
#ifdef ANSI
PUBLIC U8 *cmMemset
(
U8           *str,
U8           val,
PTR          len
)
#else
PUBLIC U8 *cmMemset(str, val, len)
U8           *str;
U8           val;
PTR          len;
#endif
{
#if (MEMSET_AVAIL) /* memset is available */
   RETVALUE((U8 *) memset((Void *)str, (U8)val, (size_t)len));
#else  /* MEMSET_AVAIL: memset is not available */
   while (len --)
      *str++ = val;

   RETVALUE(str);
#endif /* MEMSET_AVAIL */
} /* end of cmMemset */


/*
*
*       Fun:   cmStrcmp
*
*       Desc:  common primitive to compare a contiguous string of characters
*              terminated by the '\0' character.
*
*              when strcmp is available, it uses that. otherwise, it
*              compares the strings using a for loop.
*
*              The following is the "strcmp" description from the SunOS 5.4
*              man-page. cmStrcmp follows this.
*
*             strcmp() compares two strings byte-by-byte, according to the
*             ordering  of  your  machine's  character  set.  The function
*             returns an integer greater than, equal to, or less  than  0,
*             if the string pointed to by s1 is greater than, equal to, or
*             less than the string pointed to by s2 respectively. The sign
*             of  a non-zero return value is determined by the sign of the
*             difference between the values of the  first  pair  of  bytes
*             that  differ in the strings being compared.
*
*             Bytes following a null byte are not compared.
*
*
*       Ret:    < 0 => s1 < s2
*               > 0 => s1 > s2
*               = 0 => s1 = s2
*
*       Notes: None
*
*       File:  cm_lib.c
*
*/
#ifdef ANSI
PUBLIC S16 cmStrcmp
(
CONSTANT U8 *s1,
CONSTANT U8 *s2
)
#else
PUBLIC S16 cmStrcmp (s1, s2)
CONSTANT U8 *s1;
CONSTANT U8 *s2;
#endif
{
#if (STRCMP_AVAIL)
   RETVALUE(strcmp((CONSTANT S8 *)s1, (CONSTANT S8 *)s2));
#else   /* STRCMP_AVAIL */
  
   while (*s1 && *s2)
   {
      if (*s1 ^ *s2)
         RETVALUE(*s1 - *s2);
      s1++;
      s2++;
   }
   RETVALUE(0);
#endif      /* strcmp is not available */

} /* end of cmStrcmp */



/*
*
*       Fun:   cmStrncmp
*
*       Desc:  common primitive to compare a contiguous string of characters
*              terminated by the '\0' character.
*              
*              when strncmp is available, it uses that. otherwise, it
*              compares the strings using a for loop.
*              
*              The following is the "strncmp" description from the SunOS 5.4
*              man-page. cmStrncmp follows this.
*
*              strcmp() compares two strings byte-by-byte, according to the
*              ordering  of  your  machine's  character  set.  The function
*              returns an integer greater than, equal to, or less  than  0,
*              if the string pointed to by s1 is greater than, equal to, or
*              less than the string pointed to by s2 respectively. The sign
*              of  a non-zero return value is determined by the sign of the
*              difference between the values of the  first  pair  of  bytes
*              that  differ in the strings being compared.  strncmp() makes
*              the same comparison but looks  at  a  maximum  of  n  bytes.
*              Bytes following a null byte are not compared.
*
*       Ret:    < 0 => s1 < s2
*               > 0 => s1 > s2
*               = 0 => s1 = s2
*
*       Notes: None
*
*       File:  cm_lib.c
*
*/
#ifdef ANSI
PUBLIC S16 cmStrncmp
(
CONSTANT U8  *s1,
CONSTANT U8  *s2,
S16          len
)
#else
PUBLIC S16 cmStrncmp (s1, s2, len)
CONSTANT U8  *s1;
CONSTANT U8  *s2;
S16          len;
#endif
{
#if (STRNCMP_AVAIL)
   RETVALUE(strncmp((CONSTANT S8 *)s1, (CONSTANT S8 *)s2, (size_t) len));
#else   /* STRNCMP_AVAIL */
  
   while (*s1 && *s2 && len--)
   {
      if (*s1 ^ *s2)
         RETVALUE(*s1 - *s2);
      s1++;
      s2++;
   }
   RETVALUE(0);
#endif   /* strncmp is not available */
} /* end of cmStrncmp */


/*
*
*       Fun:   cmStrlen
*
*       Desc:  common primitive to compute the length of a NULL terminated
*              string.
*              
*              when strlen is available, it uses that. otherwise, it
*              inspects the string using a for loop.
*              
*              The following is the "strlen" description from the SunOS 5.4
*              man-page. cmStrlen follows this.
*
*              strlen() returns the number of bytes in s, not including the
*              terminating null character.
*
*       Ret:   length of string
*
*       Notes: None
*
*       File:  cm_lib.c
*
*/
#ifdef ANSI
PUBLIC S16 cmStrlen
(
CONSTANT U8 *s
)
#else
PUBLIC S16 cmStrlen (s)
CONSTANT U8 *s;
#endif
{
#if (STRLEN_AVAIL)
   RETVALUE((S16)strlen((CONSTANT S8 *)s));
#else   /* STRLEN_AVAIL */
   S16 i;
  
   for (i = 0; *s; i++, s++);
   RETVALUE(i);
#endif   /* strlen is not available */
} /* end of cmStrlen */


  
/********************************************************************30**
  
         End of file:     cm_lib.c@@/main/10 - Fri Feb  9 16:23:51 2001
  
*********************************************************************31*/


/********************************************************************40**
  
        Notes:
  
*********************************************************************41*/

/********************************************************************50**

*********************************************************************51*/

   
/********************************************************************60**
  
        Revision history:
  
*********************************************************************61*/
  
/********************************************************************80**
  version    pat  init                   description
----------- ----- ----  ------------------------------------------------

*********************************************************************81*/

/********************************************************************90**
 
     ver       pat    init                  description
------------ -------- ---- ----------------------------------------------
1.1          ---      ak   initial release
 
1.2          ---      ak   fixed problem in cmMemcmp where difference is
                           in higher two bytes of 32 bit aligned words.

1.3          ---      ak   1. added function calls to SLogError if library
                             is chosen to be used but code not present.

1.4          ---      ak   1. fixed bugs with cmMemcpy and cmStrlen
             ---      aa   2. fixed compilation problem in strncmp
1.5          ---      mk   1. Changed the Data Type of the parameter
                             'len' in the functions cmMemcpy, cmMemcmp
                             cmMemset, from S16 to PTR.
             ---      an   2. Corrected the comparision check in cmMemcmp by
                             typcasting the reult to S32 before checking for
                             less than or greater that zero.
             ---      mg   3. Changes to pass through chksrc

1.6          ---      bbk  1. Changed copyright header date.

1.7          ---      tej  1. Change in header

             ---      jjn  1. The c string library function has been removed
                              from ifdef SUNOS51, because most of the operating
                              systems provide this library functions. Also
                              this library function provide the most optimum
                              copy operation. Checking of PTR type has been
                              removed from the code as it resulted in the
                              code being non - portable.

/main/9      ---      db   1. Rolled in patch cm_lib_c_001.107 for 64 bit
                              compilation.
/main/9      ---      cv   1. Added #include string.h for SYSLIB mem calls     
/main/10     ---      dvs  1. ClearCase release
*********************************************************************91*/

⌨️ 快捷键说明

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