Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp01.tex V1 - 09/04/2008 6:08pm Page 1121

Appendix A: Architecture Specifics


❑ char * strchr(const char * s, int c)finds the first position in the stringsat which the charac-
tercoccurs.
❑ char * strrchr(const char * s, int c)finds the last position in the stringsat which the char-
actercoccurs.
❑ size_t strlen(const char * s)determines the length of a null-terminated string.
❑ size_t strnlen(const char * s, size_t count)is similar tostrlenbut restricts the operation
to a maximum length ofcount.
❑ size_t strspn(const char *s, const char *accept)calculates the length of the substring ofs
which, consists entirely of characters inaccept.
❑ size_t strcspn(const char *s, const char *reject)is similar tostrspn, but calculates the
length of the substring ofsthat consists entirely of charactersnotinreject.
❑ char * strstr(const char * s1,const char * s2)searchess1for the substrings2.
❑ char * strpbrk(const char * cs,const char * ct)searches for the first occurrence of a member
of the string (ct) in another string (cs).
❑ char * strsep(char **s, const char *ct)splits a string into tokens separated byct.

The following operations act on general memory areas and not on strings:


❑ void * memset(void * s,int c,size_t count)fillscountbytes with the value specified byc
starting at addresss.
❑ memset_iodoes the same for I/O memory areas.
❑ char * bcopy(const char * src, char * dest, int count)copies an area of sizecountfromsrc
todest.
❑ memcpy_fromiodoes the same to copy an area of I/O address space to normal address space.
❑ void * memcpy(void * dest,const void *src,size_t count)is similar tobcopybut usesvoid
pointers as arguments to define the areas involved.
❑ void * memmove(void * dest,const void *src,size_t count)is similar tomemcpybut also func-
tions with overlapping source and destination areas.
❑ int memcmp(const void * cs,const void * ct,size_t count)compares two areas of memory,
byte-by-byte.
❑ void * memscan(void * addr, int c, size_t size)scans the area specified byaddrandsizeto
find the first occurrence of characterc.
❑ void *memchr(const void *s, int c, size_t n)is similar tomemscanbut returns a null pointer
(and not a pointer to the first byte after the scanned area) if the desired element is not found.

All operations are replacement routines for the C standard library member of the same name that are
employed by userspace programs to perform the same tasks as in the kernel.


TheHAVE_ARCH_OPERATIONmacro must be set for each string operation that is defined as optimized
by an architecture; for instance,
HAVE_ARCH_MEMCPYmust be set formemcpy. All nonimplemented
functions are replaced with architecture-independent standard operations that are implemented in
lib/string.c.

Free download pdf