1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright IBM Corp. 1999
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 #ifndef _S390_STRING_H_
9 #define _S390_STRING_H_
11 #ifndef _LINUX_TYPES_H
12 #include <linux/types.h>
15 #define __HAVE_ARCH_MEMCHR /* inline & arch function */
16 #define __HAVE_ARCH_MEMCMP /* arch function */
17 #define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */
18 #define __HAVE_ARCH_MEMMOVE /* gcc builtin & arch function */
19 #define __HAVE_ARCH_MEMSCAN /* inline & arch function */
20 #define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */
21 #define __HAVE_ARCH_MEMSET16 /* arch function */
22 #define __HAVE_ARCH_MEMSET32 /* arch function */
23 #define __HAVE_ARCH_MEMSET64 /* arch function */
24 #define __HAVE_ARCH_STRCAT /* inline & arch function */
25 #define __HAVE_ARCH_STRCMP /* arch function */
26 #define __HAVE_ARCH_STRCPY /* inline & arch function */
27 #define __HAVE_ARCH_STRLCAT /* arch function */
28 #define __HAVE_ARCH_STRLCPY /* arch function */
29 #define __HAVE_ARCH_STRLEN /* inline & arch function */
30 #define __HAVE_ARCH_STRNCAT /* arch function */
31 #define __HAVE_ARCH_STRNCPY /* arch function */
32 #define __HAVE_ARCH_STRNLEN /* inline & arch function */
33 #define __HAVE_ARCH_STRRCHR /* arch function */
34 #define __HAVE_ARCH_STRSTR /* arch function */
36 /* Prototypes for non-inlined arch strings functions. */
37 int memcmp(const void *s1
, const void *s2
, size_t n
);
38 void *memcpy(void *dest
, const void *src
, size_t n
);
39 void *memset(void *s
, int c
, size_t n
);
40 void *memmove(void *dest
, const void *src
, size_t n
);
41 int strcmp(const char *s1
, const char *s2
);
42 size_t strlcat(char *dest
, const char *src
, size_t n
);
43 size_t strlcpy(char *dest
, const char *src
, size_t size
);
44 char *strncat(char *dest
, const char *src
, size_t n
);
45 char *strncpy(char *dest
, const char *src
, size_t n
);
46 char *strrchr(const char *s
, int c
);
47 char *strstr(const char *s1
, const char *s2
);
49 #undef __HAVE_ARCH_STRCHR
50 #undef __HAVE_ARCH_STRNCHR
51 #undef __HAVE_ARCH_STRNCMP
52 #undef __HAVE_ARCH_STRPBRK
53 #undef __HAVE_ARCH_STRSEP
54 #undef __HAVE_ARCH_STRSPN
56 void *__memset16(uint16_t *s
, uint16_t v
, size_t count
);
57 void *__memset32(uint32_t *s
, uint32_t v
, size_t count
);
58 void *__memset64(uint64_t *s
, uint64_t v
, size_t count
);
60 static inline void *memset16(uint16_t *s
, uint16_t v
, size_t count
)
62 return __memset16(s
, v
, count
* sizeof(v
));
65 static inline void *memset32(uint32_t *s
, uint32_t v
, size_t count
)
67 return __memset32(s
, v
, count
* sizeof(v
));
70 static inline void *memset64(uint64_t *s
, uint64_t v
, size_t count
)
72 return __memset64(s
, v
, count
* sizeof(v
));
75 #if !defined(IN_ARCH_STRING_C) && (!defined(CONFIG_FORTIFY_SOURCE) || defined(__NO_FORTIFY))
77 static inline void *memchr(const void * s
, int c
, size_t n
)
79 register int r0
asm("0") = (char) c
;
80 const void *ret
= s
+ n
;
88 : "+a" (ret
), "+&a" (s
) : "d" (r0
) : "cc", "memory");
92 static inline void *memscan(void *s
, int c
, size_t n
)
94 register int r0
asm("0") = (char) c
;
95 const void *ret
= s
+ n
;
100 : "+a" (ret
), "+&a" (s
) : "d" (r0
) : "cc", "memory");
104 static inline char *strcat(char *dst
, const char *src
)
106 register int r0
asm("0") = 0;
115 : "=&a" (dummy
), "+a" (dst
), "+a" (src
)
116 : "d" (r0
), "0" (0) : "cc", "memory" );
120 static inline char *strcpy(char *dst
, const char *src
)
122 register int r0
asm("0") = 0;
128 : "+&a" (dst
), "+&a" (src
) : "d" (r0
)
133 static inline size_t strlen(const char *s
)
135 register unsigned long r0
asm("0") = 0;
141 : "+d" (r0
), "+a" (tmp
) : : "cc", "memory");
142 return r0
- (unsigned long) s
;
145 static inline size_t strnlen(const char * s
, size_t n
)
147 register int r0
asm("0") = 0;
149 const char *end
= s
+ n
;
154 : "+a" (end
), "+a" (tmp
) : "d" (r0
) : "cc", "memory");
157 #else /* IN_ARCH_STRING_C */
158 void *memchr(const void * s
, int c
, size_t n
);
159 void *memscan(void *s
, int c
, size_t n
);
160 char *strcat(char *dst
, const char *src
);
161 char *strcpy(char *dst
, const char *src
);
162 size_t strlen(const char *s
);
163 size_t strnlen(const char * s
, size_t n
);
164 #endif /* !IN_ARCH_STRING_C */
166 #endif /* __S390_STRING_H_ */