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 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 Library General Public License as
9 published by the Free Software Foundation ; either version 2 of the
10 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 * R2 = address of destination (dst)
24 * R3 = address of source (src)
25 * R4 = max of bytes to copy
29 #include "asm-syntax.h"
33 st %r2,24(%r15) # save dst pointer
34 slr %r2,%r3 # %r3 points to src, %r2+%r3 to dst
36 nr %r1,%r4 # last 2 bits of # bytes
38 ltr %r4,%r4 # less than 4 bytes to copy ?
40 bras %r5,.L0 # enter loop & load address of a 0
42 .L0: icm %r0,8,0(%r3) # first byte
44 icm %r0,4,1(%r3) # second byte
46 icm %r0,2,2(%r3) # third byte
48 icm %r0,1,3(%r3) # fourth byte
50 st %r0,0(%r2,%r3) # store all four to dest.
64 .L6: st %r0,0(%r2,%r3)
71 alr %r2,%r3 # start of dst area to be zeroed
75 .L9: mvcle %r2,%r4,0 # pad dst with zeroes
77 .Lexit: l %r2,24(%r15) # return dst pointer