Compare commits

..

No commits in common. "af0cb83a58decf405ea83b0df2a2a05631351e94" and "5c0104111d7b13fab7d96dfe9c38dd47155448db" have entirely different histories.

4 changed files with 12 additions and 5 deletions

View File

@ -38,9 +38,6 @@ extern "C"
/* Return a pointer to the first occurrence of the character c in str, or NULL if it could not be found. */ /* Return a pointer to the first occurrence of the character c in str, or NULL if it could not be found. */
char* strchr(const char* str, int c); char* strchr(const char* str, int c);
/* Return a pointer to the last occurrence of the character c in str, or NULL if it could not be found. */
char* strrchr(const char* str, int c);
/* Return a heap-allocated copy of a string. */ /* Return a heap-allocated copy of a string. */
char* strdup(const char* str); char* strdup(const char* str);

View File

@ -23,6 +23,10 @@ extern "C"
char* strdup(const char* str); char* strdup(const char* str);
char* strndup(const char* str, usize max); char* strndup(const char* str, usize max);
// Copies len bytes from src into dest and adds a null terminator.
// FIXME: Replace this invented function with strlcpy().
void nullcpy(char* dest, const char* src, usize len);
usize strlcpy(char* dest, const char* src, usize len); usize strlcpy(char* dest, const char* src, usize len);
[[deprecated]] char* strcpy(char* dst, const char* src); [[deprecated]] char* strcpy(char* dst, const char* src);

View File

@ -96,6 +96,12 @@ extern "C"
return dest; return dest;
} }
void nullcpy(char* dest, const char* src, usize len)
{
memcpy(dest, src, len);
dest[len] = 0;
}
char* strcpy(char* dest, const char* src) char* strcpy(char* dest, const char* src)
{ {
char* s = dest; char* s = dest;

View File

@ -40,7 +40,7 @@ Result<TarStream::Entry> TarStream::parse_header(const TarStream::TarHeader* hdr
Entry entry; Entry entry;
char size[13]; char size[13];
strlcpy(size, hdr->size, 13); nullcpy(size, hdr->size, 12);
entry.size = parse_unsigned_integer(size, nullptr, 8); entry.size = parse_unsigned_integer(size, nullptr, 8);
entry.mode = (mode_t)parse_unsigned_integer(hdr->mode, nullptr, 8); entry.mode = (mode_t)parse_unsigned_integer(hdr->mode, nullptr, 8);
@ -56,7 +56,7 @@ Result<TarStream::Entry> TarStream::parse_header(const TarStream::TarHeader* hdr
default: return err(EFIXME); default: return err(EFIXME);
} }
if (!strlen(hdr->prefix)) { strlcpy(entry.name, hdr->name, 101); } if (!strlen(hdr->prefix)) { nullcpy(entry.name, hdr->name, 100); }
else { return err(EFIXME); } else { return err(EFIXME); }
if (entry.size) if (entry.size)