Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / s390 / s390-32 / strncpy.S
blobb0e234e2da070e20583f55aedec18736c4dd92aa
1 /* strncpy - copy at most n characters from a string from source to
2    destination.  For IBM S390
3    This file is part of the GNU C Library.
4    Copyright (C) 2000-2015 Free Software Foundation, Inc.
5    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, see
19    <http://www.gnu.org/licenses/>.  */
22  * R2 = address of destination (dst)
23  * R3 = address of source (src)
24  * R4 = max of bytes to copy
25  */
27 #include "sysdep.h"
28 #include "asm-syntax.h"
30 ENTRY(strncpy)
31         .text
32         st    %r2,24(%r15)          # save dst pointer
33         slr   %r2,%r3               # %r3 points to src, %r2+%r3 to dst
34         lhi   %r1,3
35         nr    %r1,%r4               # last 2 bits of # bytes
36         srl   %r4,2
37         ltr   %r4,%r4               # less than 4 bytes to copy ?
38         jz    .L1
39         bras  %r5,.L0               # enter loop & load address of a 0
40         .long 0
41 .L0:    icm   %r0,8,0(%r3)          # first byte
42         jz    .L3
43         icm   %r0,4,1(%r3)          # second byte
44         jz    .L4
45         icm   %r0,2,2(%r3)          # third byte
46         jz    .L5
47         icm   %r0,1,3(%r3)          # fourth byte
48         jz    .L6
49         st    %r0,0(%r2,%r3)        # store all four to dest.
50         la    %r3,4(%r3)
51         brct  %r4,.L0
52 .L1:    ltr   %r1,%r1
53         jz    .Lexit
54 .L2:    icm   %r0,1,0(%r3)
55         stc   %r0,0(%r2,%r3)
56         la    %r3,1(%r3)
57         jz    .L7
58         brct  %r1,.L2
59         j     .Lexit
60 .L3:    icm   %r0,4,0(%r5)
61 .L4:    icm   %r0,2,0(%r5)
62 .L5:    icm   %r0,1,0(%r5)
63 .L6:    st    %r0,0(%r2,%r3)
64         la    %r3,4(%r3)
65         ahi   %r4,-1
66         j     .L8
67 .L7:    ahi   %r1,-1
68 .L8:    sll   %r4,2
69         alr   %r4,%r1
70         alr   %r2,%r3               # start of dst area to be zeroed
71         lr    %r3,%r4
72         slr   %r4,%r4
73         slr   %r5,%r5
74 .L9:    mvcle %r2,%r4,0             # pad dst with zeroes
75         jo    .L9
76 .Lexit: l     %r2,24(%r15)          # return dst pointer
77         br    %r14
78 END(strncpy)
79 libc_hidden_builtin_def (strncpy)