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_P) |
.global _U(strncpy_P) |
58 |
.type _U(strncpy_P), @function |
.type _U(strncpy_P), @function |
59 |
_U(strncpy_P): |
_U(strncpy_P): |
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_P_loop: |
.L_strncpy_P_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_P_done |
brcs .L_strncpy_P_done |
66 |
LPM_R0_ZP |
LPM_R0_ZP |
67 |
st X+, r0 |
st X+, r0 |
68 |
tst r0 |
tst r0 |
69 |
brne .strncpy_P_loop |
brne .L_strncpy_P_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_P_clr_start |
rjmp .L_strncpy_P_clr_start |
74 |
.strncpy_P_clr_loop: |
.L_strncpy_P_clr_loop: |
75 |
st X+, __zero_reg__ |
st X+, __zero_reg__ |
76 |
.strncpy_P_clr_start: |
.L_strncpy_P_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_P_clr_loop |
brcc .L_strncpy_P_clr_loop |
80 |
.strncpy_P_done: |
.L_strncpy_P_done: |
81 |
; return dest (unchanged) |
; return dest (unchanged) |
82 |
ret |
ret |
83 |
.strncpy_P_end: |
.L_strncpy_P_end: |
84 |
.size _U(strncpy_P), .strncpy_P_end - _U(strncpy_P) |
.size _U(strncpy_P), .L_strncpy_P_end - _U(strncpy_P) |
85 |
|
|
86 |
#endif /* not DOXYGEN */ |
#endif /* not DOXYGEN */ |