| 29 | #include "m_string.h" |
| 30 | |
| 31 | char *strmake(register char *dst, register const char *src, size_t length) |
| 32 | { |
| 33 | #ifdef EXTRA_DEBUG |
| 34 | /* |
| 35 | 'length' is the maximum length of the string; the buffer needs |
| 36 | to be one character larger to accomodate the terminating '\0'. |
| 37 | This is easy to get wrong, so we make sure we write to the |
| 38 | entire length of the buffer to identify incorrect buffer-sizes. |
| 39 | We only initialise the "unused" part of the buffer here, a) for |
| 40 | efficiency, and b) because dst==src is allowed, so initialising |
| 41 | the entire buffer would overwrite the source-string. Also, we |
| 42 | write a character rather than '\0' as this makes spotting these |
| 43 | problems in the results easier. |
| 44 | */ |
| 45 | uint n= 0; |
| 46 | while (n < length && src[n++]); |
| 47 | memset(dst + n, (int) 'Z', length - n + 1); |
| 48 | #endif |
| 49 | |
| 50 | while (length--) |
| 51 | if (! (*dst++ = *src++)) |
| 52 | return dst-1; |
| 53 | *dst=0; |
| 54 | return dst; |
| 55 | } |
no outgoing calls
no test coverage detected