String handling functions

Copyright © 2007 Christopher Williams (abbrev@gmail.com).

Contents

Introduction

This is an implementation for the Z80 of the string handling functions found in the ANSI C Standard Library. All of the functions, except for two, are implemented. The "POSIX" locale is assumed in functions where applicable. Here is a complete list of the functions in the Standard Library:

*These functions are not implemented (yet).

Note: Strings are zero-terminated (end with a 0 byte), as in C; this allows them to be any length.

C function prototypes

For reference, here are the C function prototypes for all of the functions:

Calling the functions

Calling convention for all functions

All of the functions follow a common convention for arguments and return values.

Inputs

Outputs

Here are the inputs and outputs of each of the functions in detail:

memchr - scan memory for a character

Input

Output

memcmp - compare memory areas

Input

Output

memcpy - copy memory area

Input

Output

memmove - copy memory area

Input

Output

memset - fill memory with a constant byte

Input

Output

strcat - concatenate two strings

Input

Output

strchr - locate character in string

Input

Output

strcmp - compare two strings

Input

Output

strcpy - copy a string

Input

Output

strcspn - search a string for a set of characters

Input

Output

strlen - calculate the length of a string

Input

Output

strncat - concatenate two strings

Input

Output

strncmp - compare two strings

Input

Output

strncpy - copy a string

Input

Output

strpbrk - search a string for any of a set of characters

Input

Output

strrchr - locate character in string

Input

Output

strspn - search a string for a set of characters

Input

Output

strstr - locate a substring

Input

Output

strxfrm - string transformation

Input

Output

Implementation notes

In this implementation, some functions depend on one or more other functions to work correctly. The following table lists these functions and their dependencies.

FunctionDepends on
strcatstrcpy
strcspnstrchr
strpbrkstrchr
strspnstrchr
strstrstrlen and strncmp
strxfrmstrchr and strlen

This means that, for example, if you include "strcat.asm", you should also include "strcpy.asm".

Bugs

There are no known bugs in this version. However, two of the functions in the Standard (strerror and strtok) are missing in this implementation. I did not implement strerror because it's almost useless without more of the C Standard Library. I did not implement strtok for a few reasons, one being that it is not reentrant (it stores static data), another being that it modifies the original string. I may write strtok in a future version, but for now it's missing.

Version History