yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* strncpy implementation for SUPERH |
| 2 | * |
| 3 | * Copyright (C) 2009 STMicroelectronics Ltd. |
| 4 | * |
| 5 | * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> |
| 6 | * |
| 7 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | char *strncpy(char *dest, const char *src, size_t n); |
| 12 | */ |
| 13 | |
| 14 | #include <sysdep.h> |
| 15 | |
| 16 | ENTRY(strncpy) |
| 17 | mov #0,r0 |
| 18 | bra 2f |
| 19 | mov r4,r2 |
| 20 | 1: |
| 21 | mov.b r1,@(r0,r2) |
| 22 | add #1,r0 |
| 23 | 2: |
| 24 | cmp/hs r6,r0 |
| 25 | bt 5f |
| 26 | mov.b @(r0,r5),r1 |
| 27 | tst r1,r1 |
| 28 | bf/s 1b |
| 29 | cmp/hs r6,r0 |
| 30 | bra 4f |
| 31 | nop |
| 32 | 3: |
| 33 | mov.b r1,@(r0,r2) |
| 34 | add #1,r0 |
| 35 | cmp/hs r6,r0 |
| 36 | 4: |
| 37 | bf/s 3b |
| 38 | mov #0,r1 |
| 39 | 5: |
| 40 | rts |
| 41 | mov r2,r0 |
| 42 | END(strncpy) |
| 43 | libc_hidden_def(strncpy) |