OSDN Git Service

* Fix copyright dates.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / string.h
1 /* string.h: Extra string defs
2
3    Copyright 2001, 2007, 2008 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #ifndef _CYGWIN_STRING_H
12 #define _CYGWIN_STRING_H
13
14 #include_next <string.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #undef strchr
21 #define strchr cygwin_strchr
22 static inline __stdcall char *
23 strchr (const char *s, int c)
24 {
25   register char * res;
26   __asm__ __volatile__ ("\
27         movb    %%al,%%ah\n\
28 1:      movb    (%1),%%al\n\
29         cmpb    %%ah,%%al\n\
30         je      2f\n\
31         incl    %1\n\
32         testb   %%al,%%al\n\
33         jne     1b\n\
34         xorl    %1,%1\n\
35 2:      movl    %1,%0\n\
36         ":"=a" (res), "=r" (s)
37         :"0" (c), "1" (s));
38   return res;
39 }
40
41 #undef strechr
42 #define strechr cygwin_strechr
43 static inline __stdcall char *
44 strechr (const char *s, int c)
45 {
46   register char * res;
47   __asm__ __volatile__ ("\
48         movb    %%al,%%ah\n\
49 1:      movb    (%1),%%al\n\
50         cmpb    %%ah,%%al\n\
51         je      2f\n\
52         incl    %1\n\
53         testb   %%al,%%al\n\
54         jne     1b\n\
55         decl    %1\n\
56 2:      movl    %1,%0\n\
57         ":"=a" (res), "=r" (s)
58         :"0" (c), "1" (s));
59   return res;
60 }
61
62 #ifdef __INSIDE_CYGWIN__
63
64 extern const char isalpha_array[];
65
66 static inline int
67 ascii_strcasematch (const char *cs, const char *ct)
68 {
69   register int __res;
70   int d0, d1;
71   __asm__ ("\
72         .global _isalpha_array                  \n\
73         cld                                     \n\
74         andl    $0xff,%%eax                     \n\
75 1:      lodsb                                   \n\
76         scasb                                   \n\
77         je      2f                              \n\
78         xorb    _isalpha_array(%%eax),%%al      \n\
79         cmpb    -1(%%edi),%%al                  \n\
80         jne     3f                              \n\
81 2:      testb   %%al,%%al                       \n\
82         jnz     1b                              \n\
83         movl    $1,%%eax                        \n\
84         jmp     4f                              \n\
85 3:      xor     %0,%0                           \n\
86 4:"
87         :"=a" (__res), "=&S" (d0), "=&D" (d1)
88                      : "1" (cs),   "2" (ct));
89
90   return __res;
91 }
92
93 static inline int
94 ascii_strncasematch (const char *cs, const char *ct, size_t n)
95 {
96   register int __res;
97   int d0, d1, d2;
98   __asm__ ("\
99         .global _isalpha_array;                 \n\
100         cld                                     \n\
101         andl    $0xff,%%eax                     \n\
102 1:      decl    %3                              \n\
103         js      3f                              \n\
104         lodsb                                   \n\
105         scasb                                   \n\
106         je      2f                              \n\
107         xorb    _isalpha_array(%%eax),%%al      \n\
108         cmpb    -1(%%edi),%%al                  \n\
109         jne     4f                              \n\
110 2:      testb   %%al,%%al                       \n\
111         jnz     1b                              \n\
112 3:      movl    $1,%%eax                        \n\
113         jmp     5f                              \n\
114 4:      xor     %0,%0                           \n\
115 5:"
116         :"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
117                        :"1" (cs),  "2" (ct), "3" (n));
118
119   return __res;
120 }
121
122 #undef strcasecmp
123 #define strcasecmp cygwin_strcasecmp
124 int __stdcall cygwin_strcasecmp (const char *, const char *);
125
126 #undef strncasecmp
127 #define strncasecmp cygwin_strncasecmp
128 int __stdcall cygwin_strncasecmp (const char *, const char *, size_t);
129
130 #define strcasematch(s1,s2)     (!cygwin_strcasecmp ((s1),(s2)))
131 #define strncasematch(s1,s2,n)  (!cygwin_strncasecmp ((s1),(s2),(n)))
132
133 #undef strlwr
134 #define strlwr cygwin_strlwr
135 char * __stdcall cygwin_strlwr (char *);
136
137 #undef strupr
138 #define strupr cygwin_strupr
139 char * __stdcall cygwin_strupr (char *);
140
141 #endif /* __INSIDE_CYGWIN__ */
142
143 #ifdef __cplusplus
144 }
145 #endif
146
147 #endif /* _CYGWIN_STRING_H */