MonkOS  v0.1
A simple 64-bit operating system (x86_64)
string.h File Reference

String and memory operations. More...

#include <core.h>

Go to the source code of this file.

Functions

size_t strlen (const char *str)
 Return the length of a null-terminated string. More...
 
size_t strlcpy (char *dst, const char *src, size_t dstsize)
 Copy the source string to the destination buffer. More...
 
size_t strlcat (char *dst, const char *src, size_t dstsize)
 Append the source string to the end of the destination string. More...
 
int strcmp (const char *str1, const char *str2)
 Compare two strings and return a value indicating their lexicographical order. More...
 
void * memcpy (void *dst, const void *src, size_t num)
 Copy bytes from one memory region to another. More...
 
void * memmove (void *dst, const void *src, size_t num)
 Move bytes from one memory region to another, even if the regions overlap. More...
 
void * memset (void *dst, int b, size_t num)
 Fill a region of memory with a single byte value. More...
 
void * memsetw (void *dst, int w, size_t num)
 Fill a region of memory with a single 16-bit word value. More...
 
void * memsetd (void *dst, uint32_t d, size_t num)
 Fill a region of memory with a single 32-bit dword value. More...
 
void * memzero (void *dst, size_t num)
 Fill a region of memory with zeroes. More...
 

Detailed Description

String and memory operations.

Definition in file string.h.

Function Documentation

size_t strlen ( const char *  str)

Return the length of a null-terminated string.

Count the number of characters in the null-terminated string and return the count.

Parameters
[in]strPointer to a null-terminated string.
Returns
The number of characters preceding the null terminator.

Referenced by add_msg().

size_t strlcpy ( char *  dst,
const char *  src,
size_t  dstsize 
)

Copy the source string to the destination buffer.

Appends string src to the end of dst. It will copy at most dstsize - 1 characters. A null terminator is added to the end of the destination string unless dstsize was 0.

Parameters
[in]dstPointer to the destination buffer.
[in]srcPointer to the source string.
[in]dstsizeMaximum number of characters in the dst buffer after copying, including the null terminator.
Returns
The length of the copied string after truncation.
size_t strlcat ( char *  dst,
const char *  src,
size_t  dstsize 
)

Append the source string to the end of the destination string.

The function will append at most dstsize - strlen(dst) - 1 characters. A null terminator is added to the end of the concatenated string unless dstsize was 0.

Parameters
[in]dstPointer to the destination string.
[in]srcPointer to the source string.
[in]dstsizeMaximum number of characters in the dst buffer after concatenation, including the null terminator.
Returns
The length of the concatenated string after truncation.
int strcmp ( const char *  str1,
const char *  str2 
)

Compare two strings and return a value indicating their lexicographical order.

String comparison continues until a null terminator is reached in one of the strings.

Parameters
[in]str1Pointer to the first string.
[in]str2Pointer to the second string.
Returns
< 0 if the first character in str1 that doesn't match a character in str2 has a lower value. = 0 if the two strings are identical. > 0 otherwise.

Referenced by cmp_cmds(), and command_exec().

void* memcpy ( void *  dst,
const void *  src,
size_t  num 
)

Copy bytes from one memory region to another.

If the memory regions overlap, this function's behavior is undefined, and you should use memmove instead.

Parameters
[in]dstAddress of the destination memory area.
[in]srcAddress of the source memory area.
[in]numNumber of bytes to copy.
Returns
Destination address.

Referenced by add_msg(), kb_init(), kb_setlayout(), and tty_printchar().

void* memmove ( void *  dst,
const void *  src,
size_t  num 
)

Move bytes from one memory region to another, even if the regions overlap.

Parameters
[in]dstAddress of the destination memory area.
[in]srcAddress of the source memory area.
[in]numNumber of bytes to copy.
Returns
Destination address.

Referenced by collapse(), insertafter(), and log_removecallback().

void* memset ( void *  dst,
int  b,
size_t  num 
)

Fill a region of memory with a single byte value.

Parameters
[in]dstAddress of the destination memory area.
[in]bValue of the byte used to fill memory.
[in]numNumber of bytes to set.
Returns
Destination address.
void* memsetw ( void *  dst,
int  w,
size_t  num 
)

Fill a region of memory with a single 16-bit word value.

Parameters
[in]dstAddress of the destination memory area.
[in]wValue of the word used to fill memory.
[in]numNumber of words to set.
Returns
Destination address.

Referenced by tty_clear(), and tty_printchar().

void* memsetd ( void *  dst,
uint32_t  d,
size_t  num 
)

Fill a region of memory with a single 32-bit dword value.

Parameters
[in]dstAddress of the destination memory area.
[in]dValue of the dword used to fill memory.
[in]numNumber of dwords to set.
Returns
Destination address.
void* memzero ( void *  dst,
size_t  num 
)

Fill a region of memory with zeroes.

Parameters
[in]dstAddress of the destination memory area.
[in]numNumber of bytes to set to zero.
Returns
Destination address.

Referenced by alloc_page(), kb_init(), kmem_init(), page_init(), pagetable_destroy(), pfalloc(), pffree(), and pgalloc().