1
/* Copyright (c) 2006, Carlos Lamas
3
based on libc/pmstring/strlcpy_P.S which is
4
Copyright (c) 2003, Eric B. Weddington
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
11
* Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright
14
notice, this list of conditions and the following disclaimer in
15
the documentation and/or other materials provided with the
17
* Neither the name of the copyright holders nor the names of
18
contributors may be used to endorse or promote products derived
19
from this software without specific prior written permission.
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
POSSIBILITY OF SUCH DAMAGE.
35
/* $Id: strlcpy_PF.S 2191 2010-11-05 13:45:57Z arcanum $ */
37
/** \ingroup avr_pgmspace
38
\fn size_t strlcpy_PF (char *dst, uint_farptr_t src, size_t siz)
39
\brief Copy a string from progmem to RAM.
41
Copy src to string dst of size siz. At most siz-1 characters will be
42
copied. Always NULL terminates (unless siz == 0).
44
\returns The strlcpy_PF() function returns strlen(src). If retval >= siz,
45
truncation occurred. The contents of RAMPZ SFR are undefined when the
48
#if !defined(__AVR_TINY__)
50
#if !defined(__DOXYGEN__)
67
.global _U(strlcpy_PF)
68
.type _U(strlcpy_PF), @function
72
X_movw ZL, src_b0 ; Z = src
73
LPM_R0_ZPLUS_INIT src_b2
74
X_movw XL, dst_b0 ; X = dst
75
cp siz_b0, __zero_reg__
76
cpc siz_b0, __zero_reg__ ; size == 0 ?
77
breq .L_strlcpy_PF_truncated
79
.L_strlcpy_PF_copy_loop: ; copy src to dst
82
sbci siz_b1, hi8(1) ; decrement siz
83
breq 1f ; --> siz chars copied
84
LPM_R0_ZPLUS_NEXT src_b2 ; get next src char
86
tst r0 ; end of src string ?
87
breq .L_strlcpy_PF_len ; --> all src chars copied
88
rjmp .L_strlcpy_PF_copy_loop ; next char
89
1: st X, __zero_reg__ ; truncate dst string
91
.L_strlcpy_PF_truncated: ; find Z = end of src string
93
LPM_R0_ZPLUS_NEXT src_b2 ; get next char from src
94
tst r0 ; end of src string ?
95
brne .L_strlcpy_PF_truncated ; next char
97
.L_strlcpy_PF_len: ; calculate strlen(src)
100
sbc ZH, src_b1 ; Z points past \0
107
.size _U(strlcpy_PF), .L_strlcpy_PF_end - _U(strlcpy_PF)
109
#endif /* not __DOXYGEN__ */
111
#endif /* !defined(__AVR_TINY__) */