PKUOS - Pintos
Pintos source browser for PKU Operating System course
Functions
string.c File Reference
#include <string.h>
#include <debug.h>
Include dependency graph for string.c:

Go to the source code of this file.

Functions

void * memcpy (void *dst_, const void *src_, size_t size)
 Copies SIZE bytes from SRC to DST, which must not overlap. More...
 
void * memmove (void *dst_, const void *src_, size_t size)
 Copies SIZE bytes from SRC to DST, which are allowed to overlap. More...
 
int memcmp (const void *a_, const void *b_, size_t size)
 Find the first differing byte in the two blocks of SIZE bytes at A and B. More...
 
int strcmp (const char *a_, const char *b_)
 Finds the first differing characters in strings A and B. More...
 
void * memchr (const void *block_, int ch_, size_t size)
 Returns a pointer to the first occurrence of CH in the first SIZE bytes starting at BLOCK. More...
 
char * strchr (const char *string, int c_)
 Finds and returns the first occurrence of C in STRING, or a null pointer if C does not appear in STRING. More...
 
size_t strcspn (const char *string, const char *stop)
 Returns the length of the initial substring of STRING that consists of characters that are not in STOP. More...
 
char * strpbrk (const char *string, const char *stop)
 Returns a pointer to the first character in STRING that is also in STOP. More...
 
char * strrchr (const char *string, int c_)
 Returns a pointer to the last occurrence of C in STRING. More...
 
size_t strspn (const char *string, const char *skip)
 Returns the length of the initial substring of STRING that consists of characters in SKIP. More...
 
char * strstr (const char *haystack, const char *needle)
 Returns a pointer to the first occurrence of NEEDLE within HAYSTACK. More...
 
char * strtok_r (char *s, const char *delimiters, char **save_ptr)
 Breaks a string into tokens separated by DELIMITERS. More...
 
void * memset (void *dst_, int value, size_t size)
 Sets the SIZE bytes in DST to VALUE. More...
 
size_t strlen (const char *string)
 Returns the length of STRING. More...
 
size_t strnlen (const char *string, size_t maxlen)
 If STRING is less than MAXLEN characters in length, returns its actual length. More...
 
size_t strlcpy (char *dst, const char *src, size_t size)
 Copies string SRC to DST. More...
 
size_t strlcat (char *dst, const char *src, size_t size)
 Concatenates string SRC to DST. More...
 

Function Documentation

◆ memchr()

void * memchr ( const void *  block_,
int  ch_,
size_t  size 
)

Returns a pointer to the first occurrence of CH in the first SIZE bytes starting at BLOCK.

Returns a null pointer if CH does not occur in BLOCK.

Definition at line 94 of file string.c.

References ASSERT, and NULL.

◆ memcmp()

int memcmp ( const void *  a_,
const void *  b_,
size_t  size 
)

Find the first differing byte in the two blocks of SIZE bytes at A and B.

Returns a positive value if the byte in A is greater, a negative value if the byte in B is greater, or zero if blocks A and B are equal.

Definition at line 53 of file string.c.

References ASSERT, and NULL.

Referenced by compare_bytes(), load(), main(), strip_antisocial_prefixes(), strstr(), test_main(), and ustar_parse_header().

Here is the caller graph for this function:

◆ memcpy()

void * memcpy ( void *  dst_,
const void *  src_,
size_t  size 
)

Copies SIZE bytes from SRC to DST, which must not overlap.

Standard.

Returns DST.

Definition at line 7 of file string.c.

References ASSERT, and NULL.

Referenced by inode_read_at(), inode_write_at(), main(), pagedir_create(), prepend(), realloc(), strlcat(), strlcpy(), and test_main().

Here is the caller graph for this function:

◆ memmove()

void * memmove ( void *  dst_,
const void *  src_,
size_t  size 
)

Copies SIZE bytes from SRC to DST, which are allowed to overlap.

Returns DST.

Definition at line 24 of file string.c.

References ASSERT, and NULL.

Referenced by getcwd(), newline(), and relay().

Here is the caller graph for this function:

◆ memset()

void * memset ( void *  dst_,
int  value,
size_t  size 
)

Sets the SIZE bytes in DST to VALUE.

Definition at line 279 of file string.c.

References ASSERT, and NULL.

Referenced by archive_ordinary_file(), bss_init(), calloc(), free(), fsutil_append(), fsutil_extract(), init_thread(), inode_write_at(), load_segment(), main(), palloc_free_multiple(), palloc_get_multiple(), relay(), start_process(), test_main(), and ustar_make_header().

Here is the caller graph for this function:

◆ strchr()

char * strchr ( const char *  string,
int  c_ 
)

Finds and returns the first occurrence of C in STRING, or a null pointer if C does not appear in STRING.

If C == '\0' then returns a pointer to the null terminator at the end of STRING.

Definition at line 113 of file string.c.

References ASSERT, and NULL.

Referenced by read_command_line(), strcspn(), strip_antisocial_prefixes(), strpbrk(), strspn(), and strtok_r().

Here is the caller graph for this function:

◆ strcmp()

int strcmp ( const char *  a_,
const char *  b_ 
)

Finds the first differing characters in strings A and B.

Returns a positive value if the character in A (as an unsigned char) is greater, a negative value if the character in B (as an unsigned char) is greater, or zero if strings A and B are equal.

Definition at line 73 of file string.c.

References ASSERT, and NULL.

Referenced by block_get_by_name(), checkf(), lookup(), main(), parse_options(), run_actions(), run_test(), strip_antisocial_prefixes(), and test_main().

Here is the caller graph for this function:

◆ strcspn()

size_t strcspn ( const char *  string,
const char *  stop 
)

Returns the length of the initial substring of STRING that consists of characters that are not in STOP.

Definition at line 131 of file string.c.

References NULL, and strchr().

Here is the call graph for this function:

◆ strlcat()

size_t strlcat ( char *  dst,
const char *  src,
size_t  size 
)

Concatenates string SRC to DST.

The concatenated string is limited to SIZE - 1 characters. A null terminator is always written to DST, unless SIZE is 0. Returns the length that the concatenated string would have assuming that there was sufficient space, not including a null terminator.

strlcat() is not in the standard C library, but it is an increasingly popular extension. See http://www.courtesan.com/todd/papers/strlcpy.html for information on strlcpy().

Definition at line 356 of file string.c.

References ASSERT, memcpy(), NULL, and strlen().

Here is the call graph for this function:

◆ strlcpy()

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

Copies string SRC to DST.

Extensions.

If SRC is longer than SIZE - 1 characters, only SIZE - 1 characters are copied. A null terminator is always written to DST, unless SIZE is 0. Returns the length of SRC, not including the null terminator.

strlcpy() is not in the standard C library, but it is an increasingly popular extension. See http://www.courtesan.com/todd/papers/strlcpy.html for information on strlcpy().

Definition at line 326 of file string.c.

References ASSERT, memcpy(), NULL, and strlen().

Referenced by block_register(), copy_string_across_boundary(), dir_add(), dir_readdir(), getcwd(), init_thread(), make_tar_archive(), process_execute(), ustar_make_header(), and vmsg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strlen()

size_t strlen ( const char *  string)

Returns the length of STRING.

Definition at line 293 of file string.c.

References ASSERT, and NULL.

Referenced by archive_directory(), copy_string_across_boundary(), dir_add(), main(), map_key(), prepend(), puts(), strlcat(), strlcpy(), strstr(), test_main(), ustar_make_header(), and vmsg().

Here is the caller graph for this function:

◆ strnlen()

size_t strnlen ( const char *  string,
size_t  maxlen 
)

If STRING is less than MAXLEN characters in length, returns its actual length.

Otherwise, returns MAXLEN.

Definition at line 307 of file string.c.

Referenced by __vprintf(), and read_command_line().

Here is the caller graph for this function:

◆ strpbrk()

char * strpbrk ( const char *  string,
const char *  stop 
)

Returns a pointer to the first character in STRING that is also in STOP.

If no character in STRING is in STOP, returns a null pointer.

Definition at line 145 of file string.c.

References NULL, and strchr().

Here is the call graph for this function:

◆ strrchr()

char * strrchr ( const char *  string,
int  c_ 
)

Returns a pointer to the last occurrence of C in STRING.

Returns a null pointer if C does not occur in STRING.

Definition at line 156 of file string.c.

References NULL.

◆ strspn()

size_t strspn ( const char *  string,
const char *  skip 
)

Returns the length of the initial substring of STRING that consists of characters in SKIP.

Definition at line 170 of file string.c.

References NULL, and strchr().

Here is the call graph for this function:

◆ strstr()

char * strstr ( const char *  haystack,
const char *  needle 
)

Returns a pointer to the first occurrence of NEEDLE within HAYSTACK.

Returns a null pointer if NEEDLE does not exist within HAYSTACK.

Definition at line 184 of file string.c.

References memcmp(), NULL, and strlen().

Here is the call graph for this function:

◆ strtok_r()

char * strtok_r ( char *  s,
const char *  delimiters,
char **  save_ptr 
)

Breaks a string into tokens separated by DELIMITERS.

The first time this function is called, S should be the string to tokenize, and in subsequent calls it must be a null pointer. SAVE_PTR is the address of a ‘char *’ variable used to keep track of the tokenizer's position. The return value each time is the next token in the string, or a null pointer if no tokens remain.

This function treats multiple adjacent delimiters as a single delimiter. The returned tokens will never be length 0. DELIMITERS may change from one call to the next within a single string.

strtok_r() modifies the string S, changing delimiters to null bytes. Thus, S must be a modifiable string. String literals, in particular, are not modifiable in C, even though for backward compatibility they are not ‘const’.

Example usage:

char s[] = " String to tokenize. "; char *token, *save_ptr;

for (token = strtok_r (s, " ", &save_ptr); token != NULL; token = strtok_r (NULL, " ", &save_ptr)) printf ("'%s'\n", token);

outputs:

'String' 'to' 'tokenize.'

Definition at line 235 of file string.c.

References ASSERT, NULL, s, and strchr().

Referenced by parse_options().

Here is the call graph for this function:
Here is the caller graph for this function: