strnlen.c

来自「Many C samples. It is a good sample for 」· C语言 代码 · 共 39 行

C
39
字号
/*  File   : strnlen.c
    Author : Richard A. O'Keefe.
    Updated: 10 April 1984
    Defines: strnlen()

    strnlen(src, len)
    returns the number of characters up to the first NUL in src, or len,
    whichever is smaller.  This is the same as strnend(src,len)-src.

    Beware: the VaxAsm version only works for 0 <= len < 65535.
*/

#include "strings.h"

#if	VaxAsm

int strnlen(src, len)
    char *src;
    int len;
    {
	asm("locc $0,8(ap),*4(ap)");
	asm("subl3 4(ap),r1,r0");
    }

#else  ~VaxAsm

int strnlen(s, n)
    register char *s;
    register int n;
    {
	register int L;
	
	for (L = 0; --n >= 0 && *s++; L++) ;
	return L;
    }

#endif	VaxAsm

⌨️ 快捷键说明

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