1
/* Copyright (c) 2006, Carlos Lamas
3
based on libc/pmstring/strncpy_P.S which is
4
Copyright (c) 2002, Marek Michalkiewicz
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. */
33
/* $Id: strncpy_PF.S 2191 2010-11-05 13:45:57Z arcanum $ */
35
#if !defined(__AVR_TINY__)
49
/** \ingroup avr_pgmspace
50
\fn char *strncpy_PF (char *dst, uint_farptr_t src, size_t n)
51
\brief Duplicate a string until a limited length
53
The strncpy_PF() function is similar to strcpy_PF() except that not more
54
than \e n bytes of \e src are copied. Thus, if there is no null byte among
55
the first \e n bytes of \e src, the result will not be null-terminated
57
In the case where the length of \e src is less than that of \e n, the
58
remainder of \e dst will be padded with nulls
60
\param dst A pointer to the destination string in SRAM
61
\param src A far pointer to the source string in Flash
62
\param n The maximum number of bytes to copy
64
\returns The strncpy_PF() function returns a pointer to the destination
65
string \e dst. The contents of RAMPZ SFR are undefined when the function
68
#if !defined(__DOXYGEN__)
71
.global _U(strncpy_PF)
72
.type _U(strncpy_PF), @function
77
LPM_R0_ZPLUS_INIT src_b2
84
brcs .L_strncpy_PF_done
85
LPM_R0_ZPLUS_NEXT src_b2
88
brne .L_strncpy_PF_loop
90
; store null characters up to the end of dest
91
; as the glibc manual says:
92
; This behavior is rarely useful, but it is specified by the ISO C standard.
94
rjmp .L_strncpy_PF_clr_start
96
.L_strncpy_PF_clr_loop:
100
.L_strncpy_PF_clr_start:
104
brcc .L_strncpy_PF_clr_loop
107
; return dest (unchanged)
113
.size _U(strncpy_PF), .L_strncpy_PF_end - _U(strncpy_PF)
115
#endif /* not __DOXYGEN__ */
117
#endif /* !defined(__AVR_TINY__) */