aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-09-02 04:44:53 +0200
committerMattias Andrée <maandree@operamail.com>2015-09-02 04:44:53 +0200
commitbd5d2162efae9913f2666c80bdf944a65ea95590 (patch)
tree7cfda8110528b22a8377bf9fdf526b9e203beda9
parentremove old debug line (diff)
downloadslibc-bd5d2162efae9913f2666c80bdf944a65ea95590.tar.gz
slibc-bd5d2162efae9913f2666c80bdf944a65ea95590.tar.bz2
slibc-bd5d2162efae9913f2666c80bdf944a65ea95590.tar.xz
fix more errors
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--include/bits/types.h8
-rw-r--r--include/stdint.h44
-rw-r--r--include/unistd.h6
-rw-r--r--src/string/strcmp.c7
-rw-r--r--src/string/strdup.c1
-rw-r--r--src/string/strstr.c12
-rw-r--r--src/string/substring.h9
-rw-r--r--src/wchar/wcscmp.c7
-rw-r--r--src/wchar/wcsstr.c12
9 files changed, 71 insertions, 35 deletions
diff --git a/include/bits/types.h b/include/bits/types.h
index 7a2244e..41967f2 100644
--- a/include/bits/types.h
+++ b/include/bits/types.h
@@ -75,6 +75,8 @@ typedef unsigned long int uptrdiff_t;
# define __DEFINED_wchar_t
typedef long int wchar_t
__warning("'wchar_t' is not guaranteed to be defined as expected, use 'int32_t'.");
+# endif
+# ifndef __WCHAR_MAX
# define __WCHAR_MAX INTPTR_MAX
# endif
@@ -233,6 +235,8 @@ typedef unsigned __INT_FAST64 uint_fast64_t;
#if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t)
# define __DEFINED_intmax_t
typedef signed __INT64 intmax_t;
+#endif
+#ifndef __INTMAX_MAX
# define __INTMAX_MAX INT64_MAX
#endif
@@ -243,6 +247,8 @@ typedef signed __INT64 intmax_t;
#if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t)
# define __DEFINED_uintmax_t
typedef unsigned __INT64 uintmax_t;
+#endif
+#ifndef __UINTMAX_MAX
# define __UINTMAX_MAX UINT64_MAX
#endif
@@ -256,6 +262,8 @@ typedef unsigned __INT64 uintmax_t;
#if defined(__NEED_sig_atomic_t) && !defined(__DEFINED_sig_atomic_t)
# define __DEFINED_sig_atomic_t
typedef int sig_atomic_t;
+#endif
+#ifndef __SIG_ATOMIC_BIT
# define __SIG_ATOMIC_BIT __INT_BIT
#endif
diff --git a/include/stdint.h b/include/stdint.h
index d9e0dcd..c814f13 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -60,49 +60,49 @@
* Macro that ensure that an unsigned numeral literal
* of at most 16 encoding bits does not overflow.
*/
-#define UINT16_C(value) value # U
+#define UINT16_C(value) value ## U
/**
* Macro that ensure that a signed numeral literal
* of at most 32 encoding bits does not overflow.
*/
-#if __INT_BITS == 16
-# define INT32_C(value) value # L
+#if __INT_BIT == 16
+# define INT32_C(value) value ## L
#else
# define INT32_C(value) value
-#end
+#endif
/**
* Macro that ensure that an unsigned numeral literal
* of at most 32 encoding bits does not overflow.
*/
-#if __INT_BITS == 16
-# define UINT32_C(value) value # UL
+#if __INT_BIT == 16
+# define UINT32_C(value) value ## UL
#else
-# define UINT32_C(value) value # U
-#end
+# define UINT32_C(value) value ## U
+#endif
/**
* Macro that ensure that a signed numeral literal
* of at most 64 encoding bits does not overflow.
*/
-#if __LONG_BITS == 32
-# define INT64_C(value) value # LL
+#if __LONG_BIT == 32
+# define INT64_C(value) value ## LL
#else
-# define INT64_C(value) value # L
-#end
+# define INT64_C(value) value ## L
+#endif
/**
* Macro that ensure that an unsigned numeral literal
* of at most 64 encoding bits does not overflow.
*/
-#if __LONG_BITS == 32
-# define UINT64_C(value) value # ULL
+#if __LONG_BIT == 32
+# define UINT64_C(value) value ## ULL
#else
-# define UINT64_C(value) value # UL
-#end
+# define UINT64_C(value) value ## UL
+#endif
/**
@@ -110,10 +110,10 @@
* does not overflow, unless there is no scalar integer
* type that can hold it.
*/
-#if __LONG_BITS == __LONG_LONG_BITS
-# define INTMAX_C(value) value # L
+#if __LONG_BIT == __LONG_LONG_BIT
+# define INTMAX_C(value) value ## L
#else
-# define INTMAX_C(value) value # LL
+# define INTMAX_C(value) value ## LL
#endif
/**
@@ -121,10 +121,10 @@
* does not overflow, unless there is no scalar integer
* type that can hold it.
*/
-#if __LONG_BITS == __LONG_LONG_BITS
-# define UINTMAX_C(value) value # UL
+#if __LONG_BIT == __LONG_LONG_BIT
+# define UINTMAX_C(value) value ## UL
#else
-# define UINTMAX_C(value) value # ULL
+# define UINTMAX_C(value) value ## ULL
#endif
diff --git a/include/unistd.h b/include/unistd.h
index b2831f5..85c34d5 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -22,6 +22,12 @@
+#define __NEED_size_t
+#define __NEED_ssize_t
+#define __NEED_uid_t /* TODO not implement */
+#define __NEED_gid_t /* TODO not implement */
+#define __NEED_off_t /* TODO not implement */
+#define __NEED_pid_t /* TODO not implement */
#define __NEED_ptrdiff_t
#include <bits/types.h>
diff --git a/src/string/strcmp.c b/src/string/strcmp.c
index f626f91..56b4d1b 100644
--- a/src/string/strcmp.c
+++ b/src/string/strcmp.c
@@ -17,7 +17,7 @@
*/
#include <string.h>
#include <strings.h>
-#include <inttypes.h>
+#include <stdint.h>
#include <ctype.h>
@@ -108,7 +108,7 @@ int strncmp(const char* a, const char* b, size_t length)
int strncasecmp(const char* a, const char* b, size_t length)
{
int c1, c2;
- for (; size--; a++, b++)
+ for (; length--; a++, b++)
if (*a != *b)
{
c1 = isalpha(*a) ? tolower(*a) : (int)*a;
@@ -116,6 +116,9 @@ int strncasecmp(const char* a, const char* b, size_t length)
if ((c1 -= c2))
return c1;
}
+ else if (!*a && !*b) return 0;
+ else if (!*a) return -1;
+ else if (!*b) return +1;
return 0;
}
diff --git a/src/string/strdup.c b/src/string/strdup.c
index c23548b..6a66c2c 100644
--- a/src/string/strdup.c
+++ b/src/string/strdup.c
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
+#include <stdlib.h>
diff --git a/src/string/strstr.c b/src/string/strstr.c
index 68cc647..0c67153 100644
--- a/src/string/strstr.c
+++ b/src/string/strstr.c
@@ -16,7 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <alloca.h>
+#include <ctype.h>
+
+
+# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
@@ -143,7 +149,7 @@ void* memmem(const void* __haystack, size_t haystack_length,
if (haystack_length < needle_length)
return NULL;
if (haystack_length == needle_length)
- return !memcmp(haystack, haystack_length, haystack_length) ? haystack : NULL;
+ return !memcmp(haystack, needle, haystack_length) ? haystack : NULL;
#include "substring.h"
}
@@ -170,7 +176,7 @@ void* memcasemem(const void* __haystack, size_t haystack_length,
if (haystack_length < needle_length)
return NULL;
if (haystack_length == needle_length)
- return !memcasecmp(haystack, haystack_length, haystack_length) ? haystack : NULL;
+ return !memcasecmp(haystack, needle, haystack_length) ? haystack : NULL;
#define CASE
#include "substring.h"
#undef CASE
diff --git a/src/string/substring.h b/src/string/substring.h
index 10e4a7d..9d6dbfe 100644
--- a/src/string/substring.h
+++ b/src/string/substring.h
@@ -47,7 +47,7 @@
ssize_t hay, ned, skp;
ned = 0, skp = next_map[0] = -1;
- while (ned < needle_length)
+ while (ned < (ssize_t)needle_length)
{
while ((skp > -1) && !CHREQ(needle[ned], needle[skp]))
skp = next_map[skp];
@@ -56,15 +56,18 @@
}
hay = ned = 0;
- while (hay < haystack_length)
+ while (hay < (ssize_t)haystack_length)
{
while ((ned > -1) && !CHREQ(haystack[hay], needle[ned]))
ned = next_map[ned];
hay++, ned++;
- if (ned >= needle_length)
+ if (ned >= (ssize_t)needle_length)
return needle + (hay - ned);
}
return NULL;
}
+
+#undef CHREQ
+
diff --git a/src/wchar/wcscmp.c b/src/wchar/wcscmp.c
index c9d1180..7539458 100644
--- a/src/wchar/wcscmp.c
+++ b/src/wchar/wcscmp.c
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wchar.h>
-#include <inttypes.h>
+#include <stdint.h>
#include <wctype.h>
@@ -111,7 +111,7 @@ int wcsncmp(const wchar_t* a, const wchar_t* b, size_t length)
int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t length)
{
wchar_t c1, c2;
- for (; size--; a++, b++)
+ for (; length--; a++, b++)
if (*a != *b)
{
c1 = iswalpha(*a) ? towlower(*a) : *a;
@@ -119,6 +119,9 @@ int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t length)
if (c1 < c2) return -1;
if (c1 > c2) return +1;
}
+ else if (!*a && !*b) return 0;
+ else if (!*a) return -1;
+ else if (!*b) return +1;
return 0;
}
diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c
index 0ae7b71..1a4786e 100644
--- a/src/wchar/wcsstr.c
+++ b/src/wchar/wcsstr.c
@@ -16,11 +16,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wchar.h>
-#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <alloca.h>
+#include <wctype.h>
#define WIDE
+# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
+
+
/**
* This function is identical to `wcsstr`.
@@ -155,7 +161,7 @@ wchar_t* wmemmem(const wchar_t* haystack, size_t haystack_length,
if (haystack_length < needle_length)
return NULL;
if (haystack_length == needle_length)
- return !wmemcmp(haystack, haystack_length, haystack_length) ? haystack : NULL;
+ return !wmemcmp(haystack, needle, haystack_length) ? haystack : NULL;
#include "../string/substring.h"
}
@@ -180,7 +186,7 @@ wchar_t* wmemcasemem(const wchar_t* haystack, size_t haystack_length,
if (haystack_length < needle_length)
return NULL;
if (haystack_length == needle_length)
- return !wmemcasecmp(haystack, haystack_length, haystack_length) ? haystack : NULL;
+ return !wmemcasecmp(haystack, needle, haystack_length) ? haystack : NULL;
#define CASE
#include "../string/substring.h"
#undef CASE