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

📄 blib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    (    const char *source,       	/* pointer to source buffer      */    char *destination,  	/* pointer to destination buffer */    int nbytes          	/* number of bytes to copy       */    )    {    FAST char *dstend;    FAST long *src;    FAST long *dst;    int tmp = destination - source;    if (tmp <= 0 || tmp >= nbytes)	{	/* forward copy */	dstend = destination + nbytes;	/* do byte copy if less than ten or alignment mismatch */	if (nbytes < 10 || (((int)destination ^ (int)source) & ALIGNMENT))	    goto byte_copy_fwd;	/* if odd-aligned copy byte */	while ((int)destination & ALIGNMENT)	    *destination++ = *source++;	src = (long *) source;	dst = (long *) destination;	do	    {	    *dst++ = *src++;	    }	while (((char *)dst + sizeof (long)) <= dstend);	destination = (char *)dst;	source      = (char *)src;byte_copy_fwd:	while (destination < dstend)	    *destination++ = *source++;	}    else	{	/* backward copy */	dstend       = destination;	destination += nbytes - sizeof (char);	source      += nbytes - sizeof (char);	/* do byte copy if less than ten or alignment mismatch */	if (nbytes < 10 || (((int)destination ^ (int)source) & ALIGNMENT))	    goto byte_copy_bwd;	/* if odd-aligned copy byte */	while ((int)destination & ALIGNMENT)	    *destination-- = *source--;	src = (long *) source;	dst = (long *) destination;	do	    {	    *dst-- = *src--;	    }	while (((char *)dst + sizeof(long)) >= dstend);	destination = (char *)dst + sizeof (long);	source      = (char *)src + sizeof (long);byte_copy_bwd:	while (destination >= dstend)	    *destination-- = *source--;	}    }#endif	/* IGNORE GNU LIBS *//********************************************************************************* bcopyBytes - copy one buffer to another one byte at a time** This routine copies the first <nbytes> characters from <source> to* <destination> one byte at a time.  This may be desirable if a buffer can* only be accessed with byte instructions, as in certain byte-wide* memory-mapped peripherals.** RETURNS: N/A** SEE ALSO: bcopy()*/void bcopyBytes    (    char *source,       /* pointer to source buffer      */    char *destination,  /* pointer to destination buffer */    int nbytes          /* number of bytes to copy       */    )    {    FAST char *dstend;    int tmp = destination - source;   /* XXX does it work if MSB was 1 ? */    if (tmp == 0)        return;    else if (tmp < 0 || tmp >= nbytes)    	{	/* forward copy */	dstend = destination + nbytes;	while (destination < dstend)	    *destination++ = *source++;	}    else	{	/* backward copy */	dstend       = destination;	destination += nbytes - 1;	source      += nbytes - 1;	while (destination >= dstend)	    *destination-- = *source--;	}    }/********************************************************************************* bcopyWords - copy one buffer to another one word at a time** This routine copies the first <nwords> words from <source> to <destination>* one word at a time.  This may be desirable if a buffer can only be accessed* with word instructions, as in certain word-wide memory-mapped peripherals.* The source and destination must be word-aligned.** RETURNS: N/A** SEE ALSO: bcopy()*/void bcopyWords    (    char *source,       /* pointer to source buffer      */    char *destination,  /* pointer to destination buffer */    int nwords          /* number of words to copy       */    )    {    FAST short *dstend;    FAST short *src = (short *) source;    FAST short *dst = (short *) destination;    int tmp = destination - source;   /* XXX does it work if MSB was 1 ? */    int nbytes = nwords << 1;           /* convert to bytes */    if (tmp == 0)    return;    else if (tmp < 0 || tmp >= nbytes)	{	/* forward copy */	dstend = dst + nwords;	while (dst < dstend)	    *dst++ = *src++;	}    else	{	/* backward copy */	dstend = dst;        dst   += nwords - 1;	src   += nwords - 1;	while (dst >= dstend)	    *dst-- = *src--;	}    }/********************************************************************************* bcopyLongs - copy one buffer to another one long word at a time** This routine copies the first <nlongs> characters from <source> to* <destination> one long word at a time.  This may be desirable if a buffer* can only be accessed with long instructions, as in certain long-word-wide* memory-mapped peripherals.  The source and destination must be* long-aligned.** RETURNS: N/A** SEE ALSO: bcopy()*/void bcopyLongs    (    char *source,       /* pointer to source buffer      */    char *destination,  /* pointer to destination buffer */    int nlongs          /* number of longs to copy       */    )    {    FAST long *dstend;    FAST long *src = (long *) source;    FAST long *dst = (long *) destination;    int tmp = destination - source;     /* XXX does it work if MSB was 1 ? */    int nbytes = nlongs << 2;           /* convert to bytes */    if (tmp == 0)        return;    else if (tmp < 0 || tmp >= nbytes)	{	/* forward copy */	dstend = dst + nlongs;	while (dst < dstend)	    *dst++ = *src++;	}    else	{	/* backward copy */        dstend = dst;	dst   += nlongs - 1;	src   += nlongs - 1;	while (dst >= dstend)	    *dst-- = *src--;	}    }#undef bfill /* so bfill gets built for those who don't include header files *//********************************************************************************* bfill - fill a buffer with a specified character** This routine fills the first <nbytes> characters of a buffer with the* character <ch>.  Filling is done in the most efficient way possible,* which may be long-word, or even multiple-long-word stores, on some* architectures.  In general, the fill will be significantly faster if* the buffer is long-word aligned.  (For filling that is restricted to* byte stores, see the manual entry for bfillBytes().)** RETURNS: N/A** SEE ALSO: bfillBytes()*/void bfill    (    FAST char *buf,           /* pointer to buffer              */    int nbytes,               /* number of bytes to fill        */    FAST int ch     	      /* char with which to fill buffer */    )    {#if (CPU_FAMILY != I960) || !defined(__GNUC__) || defined(VX_IGNORE_GNU_LIBS)    FAST long *pBuf;    char *bufend = buf + nbytes;    FAST char *buftmp;    FAST long val;    if (nbytes < 10)	goto byte_fill;    val = (ch << 24) | (ch << 16) | (ch << 8) | ch;    /* start on necessary alignment */    while ((int)buf & ALIGNMENT)	*buf++ = ch;    buftmp = bufend - sizeof (long); /* last word boundary before bufend */    pBuf = (long *)buf;    /* fill 4 bytes at a time; don't exceed buf endpoint */    do	{	*pBuf++ = val;	}    while ((char *)pBuf < buftmp);    buf = (char *)pBuf - sizeof (long);    /* fill remaining bytes one at a time */byte_fill:    while (buf < bufend)	*buf++ = ch;#else	/* IGNORE GNU LIBS */    (void) memset ((void *)buf, (int) ch, (size_t) nbytes);#endif	/* IGNORE GNU LIBS */    }/********************************************************************************* bfillBytes - fill buffer with a specified character one byte at a time** This routine fills the first <nbytes> characters of the specified buffer* with the character <ch> one byte at a time.  This may be desirable if a* buffer can only be accessed with byte instructions, as in certain* byte-wide memory-mapped peripherals.** RETURNS: N/A** SEE ALSO: bfill()*/void bfillBytes    (    FAST char *buf,        /* pointer to buffer              */    int nbytes,            /* number of bytes to fill        */    FAST int ch		   /* char with which to fill buffer */    )    {    FAST char *bufend = buf + nbytes;    while (buf < bufend)	*buf++ = ch;    }#endif	/* bLib_PORTABLE */#undef index /* so index gets built for those who don't include header files *//********************************************************************************* index - find the first occurrence of a character in a string** This routine finds the first occurrence of character <c>* in string <s>.** RETURNS:* A pointer to the located character, or* NULL if <c> is not found.** SEE ALSO: strchr().*/char *index    (    FAST const char *s,      /* string in which to find character */    FAST int c               /* character to find in string       */    )    {    FAST char ch;    while (((ch = *(s++)) != c) && (ch != EOS))	;    return (((ch == EOS) && c != EOS) ? NULL : (char *) --s);    }#undef rindex /* so rindex is built for those who don't include header files *//********************************************************************************* rindex - find the last occurrence of a character in a string** This routine finds the last occurrence of character <c>* in string <s>.** RETURNS:* A pointer to <c>, or* NULL if <c> is not found.*/char *rindex    (    FAST const char *s,       	/* string in which to find character */    int c              		/* character to find in string       */    )    {    int i;	/* must be signed! */    i = (int) strlen (s);	/* point to null terminator of s */    while (i >= 0)	{	if (s [i] == c)	    return ((char *) &s [i]);	i--;	}    return ((char *) NULL);    }

⌨️ 快捷键说明

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