《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
567 B

преди 10 години
  1. #include <string.h>
  2. #include <kmalloc.h>
  3. char *
  4. strdup(const char *src) {
  5. char *dst;
  6. size_t len = strlen(src);
  7. if ((dst = kmalloc(len + 1)) != NULL) {
  8. memcpy(dst, src, len);
  9. dst[len] = '\0';
  10. }
  11. return dst;
  12. }
  13. char *
  14. stradd(const char *src1, const char *src2) {
  15. char *ret, *dst;
  16. size_t len1 = strlen(src1), len2 = strlen(src2);
  17. if ((ret = dst = kmalloc(len1 + len2 + 1)) != NULL) {
  18. memcpy(dst, src1, len1), dst += len1;
  19. memcpy(dst, src2, len2), dst += len2;
  20. *dst = '\0';
  21. }
  22. return ret;
  23. }