PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
#include <stddef.h>
Go to the source code of this file.
Macros | |
#define | strcpy dont_use_strcpy_use_strlcpy |
Try to be helpful. More... | |
#define | strncpy dont_use_strncpy_use_strlcpy |
#define | strcat dont_use_strcat_use_strlcat |
#define | strncat dont_use_strncat_use_strlcat |
#define | strtok dont_use_strtok_use_strtok_r |
lib/string.h More... | |
Functions | |
void * | memcpy (void *, const void *, size_t) |
Standard. More... | |
void * | memmove (void *, const void *, size_t) |
Copies SIZE bytes from SRC to DST, which are allowed to overlap. More... | |
char * | strncat (char *, const char *, size_t) |
int | memcmp (const void *, const void *, size_t) |
Find the first differing byte in the two blocks of SIZE bytes at A and B. More... | |
int | strcmp (const char *, const char *) |
Finds the first differing characters in strings A and B. More... | |
void * | memchr (const void *, int, size_t) |
Returns a pointer to the first occurrence of CH in the first SIZE bytes starting at BLOCK. More... | |
char * | strchr (const char *, int) |
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 *, const char *) |
Returns the length of the initial substring of STRING that consists of characters that are not in STOP. More... | |
char * | strpbrk (const char *, const char *) |
Returns a pointer to the first character in STRING that is also in STOP. More... | |
char * | strrchr (const char *, int) |
Returns a pointer to the last occurrence of C in STRING. More... | |
size_t | strspn (const char *, const char *) |
Returns the length of the initial substring of STRING that consists of characters in SKIP. More... | |
char * | strstr (const char *, const char *) |
Returns a pointer to the first occurrence of NEEDLE within HAYSTACK. More... | |
void * | memset (void *, int, size_t) |
Sets the SIZE bytes in DST to VALUE. More... | |
size_t | strlen (const char *) |
Returns the length of STRING. More... | |
size_t | strlcpy (char *, const char *, size_t) |
Extensions. More... | |
size_t | strlcat (char *, const char *, size_t) |
Concatenates string SRC to DST. More... | |
char * | strtok_r (char *, const char *, char **) |
Breaks a string into tokens separated by DELIMITERS. More... | |
size_t | strnlen (const char *, size_t) |
If STRING is less than MAXLEN characters in length, returns its actual length. More... | |
#define strcpy dont_use_strcpy_use_strlcpy |
#define strtok dont_use_strtok_use_strtok_r |
void * memchr | ( | const void * | block_, |
int | ch_, | ||
size_t | size | ||
) |
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.
Referenced by compare_bytes(), load(), main(), strip_antisocial_prefixes(), strstr(), test_main(), and ustar_parse_header().
void * memcpy | ( | void * | dst_, |
const void * | src_, | ||
size_t | size | ||
) |
Standard.
Standard.
Returns DST.
Definition at line 7 of file string.c.
Referenced by inode_read_at(), inode_write_at(), main(), pagedir_create(), prepend(), realloc(), strlcat(), strlcpy(), and test_main().
void * memmove | ( | void * | dst_, |
const void * | src_, | ||
size_t | size | ||
) |
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.
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().
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.
Referenced by read_command_line(), strcspn(), strip_antisocial_prefixes(), strpbrk(), strspn(), and strtok_r().
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.
Referenced by block_get_by_name(), checkf(), lookup(), main(), parse_options(), run_actions(), run_test(), strip_antisocial_prefixes(), and test_main().
size_t strcspn | ( | const char * | string, |
const char * | stop | ||
) |
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().
Extensions.
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().
size_t strlen | ( | const char * | string | ) |
Returns the length of STRING.
Definition at line 293 of file string.c.
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().
char * strncat | ( | char * | , |
const char * | , | ||
size_t | |||
) |
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().
char * strpbrk | ( | const char * | string, |
const char * | stop | ||
) |
char * strrchr | ( | const char * | string, |
int | c_ | ||
) |
size_t strspn | ( | const char * | string, |
const char * | skip | ||
) |
char * strstr | ( | const char * | haystack, |
const char * | needle | ||
) |
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().