|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #if defined(LIBC_SCCS) && !defined(lint)
19: .asciz "@(#)strncat.s 5.5 (Berkeley) 6/27/88"
20: #endif /* LIBC_SCCS and not lint */
21:
22: /*
23: * Concatenate string s2 on the end of s1
24: * and return the base of s1. The parameter
25: * n is the maximum length of string s2 to
26: * concatenate.
27: *
28: * char *
29: * strncat(s1, s2, n)
30: * char *s1, *s2;
31: * int n;
32: */
33: #include "DEFS.h"
34:
35: ENTRY(strncat, R6)
36: movl 12(ap),r6 # r6 = n
37: bleq done # n <= 0
38: movl 4(ap),r3 # r3 = s1
39: movl r3,r1
40: 0:
41: locc $0,$65535,(r1)
42: beql 0b
43: movl r1,r3 # r3 = index(s1, '\0');
44: movl 8(ap),r1 # r1 = s2
45: 1:
46: movzwl $65535,r2 # r2 = bytes in first chunk
47: cmpl r6,r2 # r2 = min(bytes in chunk, n);
48: jgeq 2f
49: movl r6,r2
50: 2:
51: subl2 r2,r6 # update n
52: locc $0,r2,(r1) # '\0' found?
53: jneq 3f
54: subl2 r2,r1 # back up pointer updated by locc
55: movc3 r2,(r1),(r3) # copy in next piece
56: tstl r6 # run out of space?
57: jneq 1b
58: clrb (r3) # force '\0' termination
59: jbr done
60: 3:
61: subl2 r0,r2 # r2 = number of bytes to move
62: subl2 r2,r1 # back up pointer updated by locc
63: incl r2 # copy '\0' as well
64: movc3 r2,(r1),(r3) # copy in last piece
65: done:
66: movl 4(ap),r0 # return s1
67: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.