1
/* Copyright (c) 2006, Carlos Lamas
3
based on libc/pmstring/strnlen_P.S which is
4
Copyright (c) 2005, Helmut Wallner
6
based on libc/pmstring/strnlen.S which is
7
Copyright (c) 2002, Marek Michalkiewicz
11
Redistribution and use in source and binary forms, with or without
12
modification, are permitted provided that the following conditions are met:
14
* Redistributions of source code must retain the above copyright
15
notice, this list of conditions and the following disclaimer.
16
* Redistributions in binary form must reproduce the above copyright
17
notice, this list of conditions and the following disclaimer in
18
the documentation and/or other materials provided with the
20
* Neither the name of the copyright holders nor the names of
21
contributors may be used to endorse or promote products derived
22
from this software without specific prior written permission.
24
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
POSSIBILITY OF SUCH DAMAGE. */
36
/* $Id: strnlen_PF.S 2191 2010-11-05 13:45:57Z arcanum $ */
39
#if !defined(__AVR_TINY__)
50
/** \ingroup avr_pgmspace
51
\fn size_t strnlen_PF(uint_farptr_t s, size_t len)
52
\brief Determine the length of a fixed-size string
54
The strnlen_PF() function is similar to strnlen(), except that \e s is a
55
far pointer to a string in program space
57
\param s A far pointer to the string in Flash
58
\param len The maximum number of length to return
60
\returns The strnlen_PF function returns strlen_P(\e s), if that is less
61
than \e len, or \e len if there is no '\\0' character among the first \e
62
len characters pointed to by \e s. The contents of RAMPZ SFR are
63
undefined when the function returns */
65
#if !defined(__DOXYGEN__)
68
.global _U(strnlen_PF)
69
.type _U(strnlen_PF), @function
73
LPM_R0_ZPLUS_INIT src_b2
78
LPM_R0_ZPLUS_NEXT src_b2
82
brcc .L_strnlen_PF_loop
84
; RAMPZ:Z points one character past the terminating NUL
85
; return RAMPZ:Z - 1 - src = (-1 - src) + RAMPZ:Z = ~src + RAMPZ:Z
91
X_movw src_b2, src_b0 ; size_t is 16 bits
96
.size _U(strnlen_PF), .L_strnlen_PF_end - _U(strnlen_PF)
98
#endif /* not __DOXYGEN__ */
100
#endif /* !defined(__AVR_TINY__) */