3 <<strlen>>---character string length
10 size_t strlen(const char *<[str]>);
14 size_t strlen(<[str]>)
18 The <<strlen>> function works out the length of the string
19 starting at <<*<[str]>>> by counting chararacters until it
20 reaches a <<NULL>> character.
23 <<strlen>> returns the character count.
28 <<strlen>> requires no supporting OS subroutines.
38 #define LBLOCKSIZE (sizeof (long))
39 #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
41 #if LONG_MAX == 2147483647L
42 #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
44 #if LONG_MAX == 9223372036854775807L
45 /* Nonzero if X (a long int) contains a NULL byte. */
46 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
48 #error long int is not a 32bit or 64bit type.
53 #error long int is not a 32bit or 64bit byte
57 _DEFUN (strlen
, (str
),
58 _CONST
char *str
) __attribute__ ((section (".icode")));
61 _DEFUN (strlen
, (str
),
64 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
65 _CONST
char *start
= str
;
72 _CONST
char *start
= str
;
73 unsigned long *aligned_addr
;
77 /* If the string is word-aligned, we can check for the presence of
78 a null in each word-sized block. */
79 aligned_addr
= (unsigned long*)str
;
80 while (!DETECTNULL (*aligned_addr
))
83 /* Once a null is detected, we check each byte in that block for a
84 precise position of the null. */
85 str
= (char*)aligned_addr
;
91 #endif /* not PREFER_SIZE_OVER_SPEED */