-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from vanbako/c_strmem
Added c string functions
- Loading branch information
Showing
6 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (C) 2024 Koen Van Bastelaere <[email protected]> | ||
**/ | ||
#include "xzre.h" | ||
|
||
void c_memmove(char *dest, char *src, size_t cnt) { | ||
if ((src < dest) && (dest < (src + cnt))) { | ||
size_t curr = cnt - 1; | ||
if (cnt != 0) { | ||
do { | ||
*(dest + curr) = *(src + curr); | ||
--curr; | ||
} while (curr != -1); | ||
return; | ||
} | ||
} else { | ||
if (cnt == 0) | ||
return; | ||
size_t curr = 0; | ||
do { | ||
*(dest + curr) = *(src + curr); | ||
++curr; | ||
} while (cnt != curr); | ||
} | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (C) 2024 Koen Van Bastelaere <[email protected]> | ||
**/ | ||
#include "xzre.h" | ||
|
||
ssize_t c_strlen(char *str) { | ||
if (*str != '\0') { | ||
ssize_t len = 0; | ||
do { | ||
++len; | ||
} while (*(str + len) != '\0'); | ||
return len; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (C) 2024 Koen Van Bastelaere <[email protected]> | ||
**/ | ||
#include "xzre.h" | ||
|
||
ssize_t c_strnlen(char *str, size_t max_len) { | ||
ssize_t len = 0; | ||
if (max_len == 0) | ||
return max_len; | ||
do { | ||
if (*(str + len) == '\0') | ||
return len; | ||
++len; | ||
} while (max_len != len); | ||
return max_len; | ||
} |