26 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 |
POSSIBILITY OF SUCH DAMAGE. */ |
POSSIBILITY OF SUCH DAMAGE. */ |
28 |
|
|
29 |
|
/* $Id$ */ |
30 |
|
|
31 |
#include "macros.inc" |
#include "macros.inc" |
32 |
|
|
33 |
#define dest_hi r25 |
#define dest_hi r25 |
57 |
.global _U(strncpy) |
.global _U(strncpy) |
58 |
.type _U(strncpy), @function |
.type _U(strncpy), @function |
59 |
_U(strncpy): |
_U(strncpy): |
60 |
LOAD_Z(src_lo, src_hi) |
X_movw ZL, src_lo |
61 |
LOAD_X(dest_lo, dest_hi) |
X_movw XL, dest_lo |
62 |
.strncpy_loop: |
.L_strncpy_loop: |
63 |
subi len_lo, lo8(1) |
subi len_lo, lo8(1) |
64 |
sbci len_hi, hi8(1) |
sbci len_hi, hi8(1) |
65 |
brcs .strncpy_done |
brcs .L_strncpy_done |
66 |
ld __tmp_reg__, Z+ |
ld __tmp_reg__, Z+ |
67 |
st X+, __tmp_reg__ |
st X+, __tmp_reg__ |
68 |
tst __tmp_reg__ |
tst __tmp_reg__ |
69 |
brne .strncpy_loop |
brne .L_strncpy_loop |
70 |
; store null characters up to the end of dest |
; store null characters up to the end of dest |
71 |
; as the glibc manual says: |
; as the glibc manual says: |
72 |
; This behavior is rarely useful, but it is specified by the ISO C standard. |
; This behavior is rarely useful, but it is specified by the ISO C standard. |
73 |
rjmp .strncpy_clr_start |
rjmp .L_strncpy_clr_start |
74 |
.strncpy_clr_loop: |
.L_strncpy_clr_loop: |
75 |
st X+, __zero_reg__ |
st X+, __zero_reg__ |
76 |
.strncpy_clr_start: |
.L_strncpy_clr_start: |
77 |
subi len_lo, lo8(1) |
subi len_lo, lo8(1) |
78 |
sbci len_hi, hi8(1) |
sbci len_hi, hi8(1) |
79 |
brcc .strncpy_clr_loop |
brcc .L_strncpy_clr_loop |
80 |
.strncpy_done: |
.L_strncpy_done: |
81 |
; return dest (unchanged) |
; return dest (unchanged) |
82 |
ret |
ret |
83 |
.strncpy_end: |
.L_strncpy_end: |
84 |
.size _U(strncpy), .strncpy_end - _U(strncpy) |
.size _U(strncpy), .L_strncpy_end - _U(strncpy) |
85 |
|
|
86 |
#endif /* not __DOXYGEN__ */ |
#endif /* not __DOXYGEN__ */ |