Thomas Huth | 90806fe | 2017-07-12 14:49:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * libc-style definitions and functions |
| 3 | * |
Collin L. Walling | fc0e208 | 2018-02-23 10:43:10 -0500 | [diff] [blame] | 4 | * Copyright (c) 2013 Alexander Graf <agraf@suse.de> |
| 5 | * |
Thomas Huth | 90806fe | 2017-07-12 14:49:43 +0200 | [diff] [blame] | 6 | * This code is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #ifndef S390_CCW_LIBC_H |
| 13 | #define S390_CCW_LIBC_H |
| 14 | |
Thomas Huth | e4f8696 | 2018-04-13 16:22:13 +0200 | [diff] [blame] | 15 | typedef unsigned long size_t; |
Thomas Huth | 90806fe | 2017-07-12 14:49:43 +0200 | [diff] [blame] | 16 | typedef int bool; |
| 17 | typedef unsigned char uint8_t; |
| 18 | typedef unsigned short uint16_t; |
| 19 | typedef unsigned int uint32_t; |
| 20 | typedef unsigned long long uint64_t; |
| 21 | |
| 22 | static inline void *memset(void *s, int c, size_t n) |
| 23 | { |
Collin L. Walling | fc0e208 | 2018-02-23 10:43:10 -0500 | [diff] [blame] | 24 | size_t i; |
Thomas Huth | 90806fe | 2017-07-12 14:49:43 +0200 | [diff] [blame] | 25 | unsigned char *p = s; |
| 26 | |
| 27 | for (i = 0; i < n; i++) { |
| 28 | p[i] = c; |
| 29 | } |
| 30 | |
| 31 | return s; |
| 32 | } |
| 33 | |
| 34 | static inline void *memcpy(void *s1, const void *s2, size_t n) |
| 35 | { |
| 36 | uint8_t *dest = s1; |
| 37 | const uint8_t *src = s2; |
Collin L. Walling | fc0e208 | 2018-02-23 10:43:10 -0500 | [diff] [blame] | 38 | size_t i; |
Thomas Huth | 90806fe | 2017-07-12 14:49:43 +0200 | [diff] [blame] | 39 | |
| 40 | for (i = 0; i < n; i++) { |
| 41 | dest[i] = src[i]; |
| 42 | } |
| 43 | |
| 44 | return s1; |
| 45 | } |
| 46 | |
Collin L. Walling | fc0e208 | 2018-02-23 10:43:10 -0500 | [diff] [blame] | 47 | static inline int memcmp(const void *s1, const void *s2, size_t n) |
| 48 | { |
| 49 | size_t i; |
| 50 | const uint8_t *p1 = s1, *p2 = s2; |
| 51 | |
| 52 | for (i = 0; i < n; i++) { |
| 53 | if (p1[i] != p2[i]) { |
| 54 | return p1[i] > p2[i] ? 1 : -1; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static inline size_t strlen(const char *str) |
| 62 | { |
| 63 | size_t i; |
| 64 | for (i = 0; *str; i++) { |
| 65 | str++; |
| 66 | } |
| 67 | return i; |
| 68 | } |
| 69 | |
Jason J. Herne | 86c5870 | 2019-04-04 10:34:28 -0400 | [diff] [blame] | 70 | static inline char *strcat(char *dest, const char *src) |
| 71 | { |
| 72 | int i; |
| 73 | char *dest_end = dest + strlen(dest); |
| 74 | |
| 75 | for (i = 0; i <= strlen(src); i++) { |
| 76 | dest_end[i] = src[i]; |
| 77 | } |
| 78 | return dest; |
| 79 | } |
| 80 | |
Collin L. Walling | fc0e208 | 2018-02-23 10:43:10 -0500 | [diff] [blame] | 81 | static inline int isdigit(int c) |
| 82 | { |
| 83 | return (c >= '0') && (c <= '9'); |
| 84 | } |
| 85 | |
| 86 | uint64_t atoui(const char *str); |
| 87 | char *uitoa(uint64_t num, char *str, size_t len); |
| 88 | |
Thomas Huth | 90806fe | 2017-07-12 14:49:43 +0200 | [diff] [blame] | 89 | #endif |