Annotation of 43BSDTahoe/lib/libc/gen/gen.vax/strncpy.s, revision 1.1.1.1

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 "@(#)strncpy.s   5.5 (Berkeley) 6/27/88"
                     20: #endif /* LIBC_SCCS and not lint */
                     21: 
                     22: /*
                     23:  * Copy string s2 over top of string s1.
                     24:  * Truncate or null-pad to n bytes.
                     25:  *
                     26:  * char *
                     27:  * strncpy(s1, s2, n)
                     28:  *     char *s1, *s2;
                     29:  */
                     30: #include "DEFS.h"
                     31: 
                     32: ENTRY(strncpy, R6)
                     33:        movl    12(ap),r6       # r6 = n
                     34:        bleq    done            # n <= 0
                     35:        movl    4(ap),r3        # r3 = s1
                     36:        movl    8(ap),r1        # r1 = s2
                     37: 1:
                     38:        movzwl  $65535,r2       # r2 = bytes in first chunk
                     39:        cmpl    r6,r2           # r2 = min(bytes in chunk, n);
                     40:        jgeq    2f
                     41:        movl    r6,r2
                     42: 2:
                     43:        subl2   r2,r6           # update n
                     44:        locc    $0,r2,(r1)      # '\0' found?
                     45:        jneq    3f
                     46:        subl2   r2,r1           # back up pointer updated by locc
                     47:        movc3   r2,(r1),(r3)    # copy in next piece
                     48:        tstl    r6              # run out of space?
                     49:        jneq    1b
                     50:        jbr     done
                     51: 3:                             # copy up to '\0' logic
                     52:        addl2   r0,r6           # r6 = number of null-pad bytes
                     53:        subl2   r0,r2           # r2 = number of bytes to move
                     54:        subl2   r2,r1           # back up pointer updated by locc
                     55:        movc3   r2,(r1),(r3)    # copy in last piece
                     56: 4:                             # null-pad logic
                     57:        movzwl  $65535,r2       # r2 = bytes in first chunk
                     58:        cmpl    r6,r2           # r2 = min(bytes in chunk, n);
                     59:        jgeq    5f
                     60:        movl    r6,r2
                     61: 5:
                     62:        subl2   r2,r6           # update n
                     63:        movc5   $0,(r3),$0,r2,(r3)# pad with '\0's
                     64:        tstl    r6              # finished padding?
                     65:        jneq    4b
                     66: done:
                     67:        movl    4(ap),r0        # return s1
                     68:        ret

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.