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

📄 ansistring.c

📁 vxworks5.5.1源代码。完整源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    {    size_t sz;    /* loop until chars delivered */    do  	{        p->sout = (const uchar_t *) p->buf;        sz = __strxfrm (p->buf, &p->s1, sizeof (p->buf), &p->state);        if ((sz > 0) && (p->buf [sz - 1] == EOS))    	    return (sz - 1);        if (*p->s1 == EOS)	     p->s1 = p->s2;		/* rescan */        } while (sz == 0);    return (sz);    }	/***************************************************************************** strcoll - compare two strings as appropriate to LC_COLLATE  (ANSI)** This routine compares two strings, both interpreted as appropriate to the* LC_COLLATE category of the current locale.** INCLUDE FILES: string.h** RETURNS:* An integer greater than, equal to, or less than zero, according to whether* string <s1> is greater than, equal to, or less than string <s2> when both* are interpreted as appropriate to the current locale.*/int strcoll    (    const char * s1,	/* string 1 */    const char * s2	/* string 2 */    )    {    size_t n1 = 0;		/* size of string 1 */    size_t n2 = 0;		/* size of string 2 */    __sct1 st1;			/* transform structure for string 1 */    __sct1 st2;		 	/* transform structure for string 2 */    static const __cosave initial = 	{	0	};    /* compare s1[], s2[] using locale-dependant rules */    st1.s1	= (const uchar_t *)s1;	/* string transformation 1 */    st1.s2	= (const uchar_t *)s1;    st1.state	= initial;    st2.s1	= (const uchar_t *)s2;	/* string transformation 2 */    st2.s2	= (const uchar_t *)s2;    st2.state	= initial;    FOREVER				/* compare transformed characters */    	{    	int ans;    	size_t sz;    	if (n1 == 0)    	    n1 = getxfrm (&st1);	/* string 1 */    	if (n2 == 0)    	    n2 = getxfrm (&st2);	/* string 2 */    	sz = (n1 < n2) ? n1 : n2;    	if (sz == 0)	    {    	    if (n1 == n2) 		return (0); 	    if (n2 > 0) 		return (-1);	    return (1);            }    	if ((ans = memcmp (st1.sout, st2.sout, sz)) != 0)    	    return (ans);    	st1.sout += sz;    	st2.sout += sz;    	n1 	 -= sz;    	n2 	 -= sz;    	}    }/* strcpy.c - string copy, string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,25feb93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"/********************************************************************************* strcpy - copy one string to another (ANSI)** This routine copies string <s2> (including EOS) to string <s1>.** INCLUDE FILES: string.h** RETURNS: A pointer to <s1>.*/char * strcpy    (    char *       s1,	/* string to copy to */    const char * s2	/* string to copy from */    )    {    char *save = s1;    while ((*s1++ = *s2++) != EOS)	;    return (save);    }/* strcspn.c - search string for character, string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,25feb93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"/********************************************************************************* strcspn - return the string length up to the first character from a given set (ANSI)** This routine computes the length of the maximum initial segment of string* <s1> that consists entirely of characters not included in string <s2>.** INCLUDE FILES: string.h** RETURNS:* The length of the string segment.** SEE ALSO: strpbrk(), strspn()*/ size_t strcspn       (    const char * s1,	/* string to search */    const char * s2	/* set of characters to look for in <s1> */    )    {    const char *save;    const char *p;    char 	c1;    char 	c2;    for (save = s1 + 1; (c1 = *s1++) != EOS; )	/* search for EOS */	for (p = s2; (c2 = *p++) != EOS; )	/* search for first occurance */	    {	    if (c1 == c2)		return (s1 - save);	      	/* return index of substring */            }    return (s1 - save);    }/* strerror.c - string error, string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01d,25feb93,jdi  documentation cleanup for 5.1.01c,30nov92,jdi  fixed doc for strerror() - SPR 1825.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"#include "errno.h"#include "symLib.h"#include "limits.h"#include "stdio.h"#include "sysSymTbl.h"#include "private/funcBindP.h"/* forward declarations */LOCAL STATUS strerrorIf (int errcode, char *buf);/********************************************************************************* strerror_r - map an error number to an error string (POSIX)** This routine maps the error number in <errcode> to an error message string.* It stores the error string in <buffer>.** This routine is the POSIX reentrant version of strerror().** INCLUDE FILES: string.h** RETURNS: OK or ERROR.** SEE ALSO: strerror()*/STATUS strerror_r     (    int    errcode,	/* error code */    char * buffer	/* string buffer */    )    {    return (strerrorIf (errcode, buffer));    }/********************************************************************************* strerror - map an error number to an error string (ANSI)** This routine maps the error number in <errcode> to an error message string.* It returns a pointer to a static buffer that holds the error string.** This routine is not reentrant.  For a reentrant version, see strerror_r().** INCLUDE: string.h** RETURNS: A pointer to the buffer that holds the error string.** SEE ALSO: strerror_r()*/char * strerror    (    int errcode		/* error code */    )    {    static char buffer [NAME_MAX];    (void) strerror_r (errcode, buffer);    return (buffer);    }/********************************************************************************* strerrorIf - interface from libc to VxWorks for strerror_r** RETURNS: OK, or ERROR if <buf> is null.* NOMANUAL*/LOCAL STATUS strerrorIf     (    int   errcode,		/* error code */    char *buf			/* string buffer */    )    {    int		value;    SYM_TYPE	type;    char	statName [NAME_MAX];    if (buf == NULL)	return (ERROR);    if (errcode == 0)	{        strcpy (buf, "OK");	return (OK);	}    if ((_func_symFindByValueAndType != (FUNCPTR) NULL) && (statSymTbl != NULL))	{	(* _func_symFindByValueAndType) (statSymTbl, errcode, statName, &value,					 &type, SYM_MASK_NONE, SYM_MASK_NONE);	if (value == errcode)	    {	    strcpy (buf, statName);	    return (OK);	    }	}    sprintf (buf, "errno = %#x", errcode);    return (OK);    }/* strlen.c - file for string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,25feb93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"/********************************************************************************* strlen - determine the length of a string (ANSI)** This routine returns the number of characters in <s>, not including EOS.** INCLUDE FILES: string.h** RETURNS: The number of non-null characters in the string.*/size_t strlen    (    const char * s        /* string */    )    {    const char *save = s + 1;    while (*s++ != EOS)	;    return (s - save);    }/* strncat.c - file for string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,25feb93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"/********************************************************************************* strncat - concatenate characters from one string to another (ANSI)** This routine appends up to <n> characters from string <src> to the* end of string <dst>.** INCLUDE FILES: string.h** RETURNS: A pointer to the null-terminated string <s1>.*/char * strncat    (    char *	 dst,  	/* string to append to */    const char * src,   /* string to append */    size_t	 n     	/* max no. of characters to append */    )    {    if (n != 0)	{	char *d = dst;	while (*d++ != EOS)			/* find end of string */	    ;	d--;					/* rewind back of EOS */	while (((*d++ = *src++) != EOS) && (--n > 0))	    ;	if (n == 0)	    *d = EOS;				/* NULL terminate string */	}    return (dst);    }/* strncmp.c - string compare, string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,25feb93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"/********************************************************************************* strncmp - compare the first <n> characters of two strings (ANSI)** This routine compares up to <n> characters of string <s1> to string <s2>* lexicographically.** INCLUDE FILES: string.h** RETURNS:* An integer greater than, equal to, or less than 0, according to whether* <s1> is lexicographically greater than, equal to, or less than <s2>,* respectively.*/int strncmp    (    const char * s1,           	/* string to compare */    const char * s2,           	/* string to compare <s1> to */    size_t       n             	/* max no. of characters to compare */    )    {    if (n == 0)	return (0);    while (*s1++ == *s2++)	{	if ((s1 [-1] == EOS) || (--n == 0))	    return (0);        }    return ((s1 [-1]) - (s2 [-1]));    }/* strncpy.c - string copy, string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,25feb93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,08jul92,smb  written and documented.*//*DESCRIPTIONINCLUDE FILES: string.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "string.h"/********************************************************************************* strncpy - copy characters from one string to another (ANSI)** This routine copies <n> characters from string <s2> to string <s1>.* If <n> is greater than the length of <s2>, nulls are added to <s1>.* If <n> is less than or equal to the length of <s2>, the target* string will not be null-terminated.** INCLUDE FILES: string.h** RETURNS: A pointer to <s1>.*/char *strncpy    (    char *      s1,   	/* string to copy to */    const char *s2,   	/* string to copy from */    size_t      n      	/* max no. of characters to copy */    )    {    FAST char *d = s1;    if (n != 0)	{	while ((*d++ = *s2++) != 0)	/* copy <s2>, checking size <n> */	    {	    if (--n == 0)		return (s1);            }	while (--n > 0)	    *d++ = EOS;			/* NULL terminate string */	}    return (s1);    }/* strpbrk.c - string search, string *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------

⌨️ 快捷键说明

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