macro and text revision (-mdoc version 3)
[unix-history] / usr / src / lib / libc / vax / string / strncpy.s
CommitLineData
586c39b1
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
493b70ca
KB
3 * All rights reserved.
4 *
019bea33 5 * %sccs.include.redist.c%
586c39b1
DF
6 */
7
f4f66d2c 8#if defined(LIBC_SCCS) && !defined(lint)
019bea33 9 .asciz "@(#)strncpy.s 5.6 (Berkeley) %G%"
f4f66d2c 10#endif /* LIBC_SCCS and not lint */
d5803ce3
SL
11
12/*
13 * Copy string s2 over top of string s1.
14 * Truncate or null-pad to n bytes.
15 *
16 * char *
17 * strncpy(s1, s2, n)
18 * char *s1, *s2;
19 */
dadab5a2 20#include "DEFS.h"
d5803ce3 21
dadab5a2 22ENTRY(strncpy, R6)
d5803ce3
SL
23 movl 12(ap),r6 # r6 = n
24 bleq done # n <= 0
25 movl 4(ap),r3 # r3 = s1
26 movl 8(ap),r1 # r1 = s2
271:
28 movzwl $65535,r2 # r2 = bytes in first chunk
29 cmpl r6,r2 # r2 = min(bytes in chunk, n);
30 jgeq 2f
31 movl r6,r2
322:
33 subl2 r2,r6 # update n
34 locc $0,r2,(r1) # '\0' found?
35 jneq 3f
36 subl2 r2,r1 # back up pointer updated by locc
37 movc3 r2,(r1),(r3) # copy in next piece
38 tstl r6 # run out of space?
39 jneq 1b
40 jbr done
413: # copy up to '\0' logic
42 addl2 r0,r6 # r6 = number of null-pad bytes
43 subl2 r0,r2 # r2 = number of bytes to move
44 subl2 r2,r1 # back up pointer updated by locc
45 movc3 r2,(r1),(r3) # copy in last piece
464: # null-pad logic
47 movzwl $65535,r2 # r2 = bytes in first chunk
48 cmpl r6,r2 # r2 = min(bytes in chunk, n);
49 jgeq 5f
50 movl r6,r2
515:
52 subl2 r2,r6 # update n
53 movc5 $0,(r3),$0,r2,(r3)# pad with '\0's
54 tstl r6 # finished padding?
55 jneq 4b
56done:
57 movl 4(ap),r0 # return s1
58 ret