OSDN Git Service

* winbase.h: Turn on inline versions of Interlocked* by default.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / string.h
1 /* string.h: Extra string defs
2
3    Copyright 2001 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 extern const char isalpha_array[];
42
43 #undef strcasematch
44 #define strcasematch cygwin_strcasematch
45
46 static inline int
47 cygwin_strcasematch (const char *cs, const char *ct)
48 {
49   register int __res;
50   int d0, d1;
51   __asm__ ("\
52         .global _isalpha_array                  \n\
53         cld                                     \n\
54         andl    $0xff,%%eax                     \n\
55 1:      lodsb                                   \n\
56         scasb                                   \n\
57         je      2f                              \n\
58         xorb    _isalpha_array(%%eax),%%al      \n\
59         cmpb    -1(%%edi),%%al                  \n\
60         jne     3f                              \n\
61 2:      testb   %%al,%%al                       \n\
62         jnz     1b                              \n\
63         movl    $1,%%eax                        \n\
64         jmp     4f                              \n\
65 3:      xor     %0,%0                           \n\
66 4:"
67         :"=a" (__res), "=&S" (d0), "=&D" (d1)
68                      : "1" (cs),   "2" (ct));
69
70   return __res;
71 }
72
73 #undef strncasematch
74 #define strncasematch cygwin_strncasematch
75
76 static inline int
77 cygwin_strncasematch (const char *cs, const char *ct, size_t n)
78 {
79   register int __res;
80   int d0, d1, d2;
81   __asm__ ("\
82         .global _isalpha_array;                 \n\
83         cld                                     \n\
84         andl    $0xff,%%eax                     \n\
85 1:      decl    %3                              \n\
86         js      3f                              \n\
87         lodsb                                   \n\
88         scasb                                   \n\
89         je      2f                              \n\
90         xorb    _isalpha_array(%%eax),%%al      \n\
91         cmpb    -1(%%edi),%%al                  \n\
92         jne     4f                              \n\
93 2:      testb   %%al,%%al                       \n\
94         jnz     1b                              \n\
95 3:      movl    $1,%%eax                        \n\
96         jmp     5f                              \n\
97 4:      xor     %0,%0                           \n\
98 5:"
99         :"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
100                        :"1" (cs),  "2" (ct), "3" (n));
101
102   return __res;
103 }
104
105 #ifdef __cplusplus
106 }
107 #endif
108 #endif /* _CYGWIN_STRING_H */