Previously, the function mig_strncpy would always zero-terminate the destination string. Make mig_strncpy behave like mig_strncpy and strncpy in the glibc. Also fix the implementation of mig_strncpy to return the length of the written string to align the implementation with the declaration in include/mach/mig_support.h.
* kern/ipc_mig.c (mig_strncpy): Do not zero-terminate the destination string. Return length of destination string. --- kern/ipc_mig.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kern/ipc_mig.c b/kern/ipc_mig.c index bbc38cf..a52dcb9 100644 --- a/kern/ipc_mig.c +++ b/kern/ipc_mig.c @@ -285,22 +285,23 @@ mig_put_reply_port( * * len - Length of destination buffer. */ -void mig_strncpy(dest, src, len) +vm_size_t +mig_strncpy(dest, src, len) char *dest; const char *src; int len; { + char *dest_ = dest; int i; if (len <= 0) - return; + return 0; - for (i=1; i<len; i++) + for (i=0; i<len; i++) if (! (*dest++ = *src++)) - return; + break; - *dest = '\0'; - return; + return dest - dest_; } #define fast_send_right_lookup(name, port, abort) \ -- 1.8.5.2