Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / device / lib / strlen.c
blob2fbf1de3409190f117c038381aa8420e1749e6d6
1 /*-------------------------------------------------------------------------
2 strlen.c - part of string library functions
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
5 mcs51 assembler by Frieder Ferlemann (2007)
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 MA 02110-1301, USA.
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 #include <string.h>
32 #if (!defined (__SDCC_mcs51))
34 /* Generic routine first */
35 size_t strlen ( const char * str )
37 register size_t i = 0;
39 while (*str++)
40 i++ ;
42 return i;
45 #else
47 #if defined(__SDCC)
48 #include <sdcc-lib.h>
49 #endif
51 /* Assembler version for mcs51 */
52 size_t strlen ( const char * str ) __naked
54 str; /* hush the compiler */
56 __asm
57 ; dptr holds pointer
58 ; b holds pointer memspace
61 ; char *ptr = str:
62 mov r2,dpl
63 mov r3,dph
66 ; while ( *ptr ) ptr++;
67 L00101$:
68 lcall __gptrget
69 jz L00102$
70 inc dptr
71 sjmp L00101$
74 L00102$:
75 ; return ptr - str;
76 clr c
77 mov a,dpl
78 subb a,r2
79 mov dpl,a
81 mov a,dph
82 subb a,r3
83 mov dph,a
85 _RETURN
86 __endasm;
89 #endif