aboutsummaryrefslogtreecommitdiffstats
path: root/src/string
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-09-01 21:07:54 +0200
committerMattias Andrée <maandree@operamail.com>2015-09-01 21:07:54 +0200
commitac044784a6ce64ff15610d4b70750065a7f01b80 (patch)
tree8ac8629c0089099f21be9107a5d3779963d33ca0 /src/string
parentadd memfrob (diff)
downloadslibc-ac044784a6ce64ff15610d4b70750065a7f01b80.tar.gz
slibc-ac044784a6ce64ff15610d4b70750065a7f01b80.tar.bz2
slibc-ac044784a6ce64ff15610d4b70750065a7f01b80.tar.xz
start on makefile and fixing warnings and errors
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/string/memccpy.c12
-rw-r--r--src/string/memcpy.c10
-rw-r--r--src/string/memfrob.c1
-rw-r--r--src/string/strcat.c1
-rw-r--r--src/string/strchr.c19
-rw-r--r--src/string/strcmp.c1
-rw-r--r--src/string/strcpy.c3
-rw-r--r--src/string/strdup.c1
-rw-r--r--src/string/strerror.c2
-rw-r--r--src/string/strfry.c5
-rw-r--r--src/string/strlen.c1
-rw-r--r--src/string/strmove.c3
-rw-r--r--src/string/strspn.c8
-rw-r--r--src/string/strstr.c1
-rw-r--r--src/string/strtok.c3
-rw-r--r--src/strings/bzero.c2
16 files changed, 39 insertions, 34 deletions
diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index 85378d9..4212419 100644
--- a/src/string/memccpy.c
+++ b/src/string/memccpy.c
@@ -35,10 +35,10 @@
*/
void* memccpy(void* restrict whither, const void* restrict whence, int c, size_t size)
{
- char_t* stop = memchr(whence, c, size);
- void* r = NULL
+ char* stop = memchr(whence, c, size);
+ void* r = NULL;
if (stop != NULL)
- size = (size_t)(stop - whence), r = whither + size;
+ size = (size_t)(stop - (const char*)whence), r = whither + size;
memcpy(whither, whence, size);
return r;
}
@@ -62,10 +62,10 @@ void* memccpy(void* restrict whither, const void* restrict whence, int c, size_t
*/
void* memcmove(void* whither, const void* whence, int c, size_t size)
{
- char_t* stop = memchr(whence, c, size);
- void* r = NULL
+ char* stop = memchr(whence, c, size);
+ void* r = NULL;
if (stop != NULL)
- size = (size_t)(stop - whence), r = whither + size;
+ size = (size_t)(stop - (const char*)whence), r = whither + size;
memmove(whither, whence, size);
return r;
}
diff --git a/src/string/memcpy.c b/src/string/memcpy.c
index 4582544..02479cd 100644
--- a/src/string/memcpy.c
+++ b/src/string/memcpy.c
@@ -18,6 +18,9 @@
#include <string.h>
+# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
+
+
/**
* Copy a memory segment to another, non-overlapping, segment.
@@ -30,10 +33,11 @@
void* memcpy(void* restrict whither, const void* restrict whence, size_t size)
{
/* TODO improve implementation of memcpy */
- void* r = whither;
+ char* d = whither;
+ char* s = whence;
while (size--)
- *whither++ = *whence++;
- return r;
+ *d++ = *s++;
+ return whither;
}
diff --git a/src/string/memfrob.c b/src/string/memfrob.c
index e43496a..7ec9abd 100644
--- a/src/string/memfrob.c
+++ b/src/string/memfrob.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
diff --git a/src/string/strcat.c b/src/string/strcat.c
index ed10cc2..2205f39 100644
--- a/src/string/strcat.c
+++ b/src/string/strcat.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
diff --git a/src/string/strchr.c b/src/string/strchr.c
index 21345d4..2b49c2e 100644
--- a/src/string/strchr.c
+++ b/src/string/strchr.c
@@ -16,7 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
+
+
+# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
@@ -31,9 +33,10 @@
*/
void* memchr(const void* segment, int c, size_t size)
{
+ char* s = segment;
while (size--)
- if (*segment++ == c)
- return segment - 1;
+ if (*s++ == c)
+ return s - 1;
return NULL;
}
@@ -50,9 +53,10 @@ void* memchr(const void* segment, int c, size_t size)
*/
void* rawmemchr(const void* segment, int c)
{
+ char* s = segment;
for (;;)
- if (*segment++ == c)
- return segment - 1;
+ if (*s++ == c)
+ return s - 1;
}
@@ -71,9 +75,10 @@ void* rawmemchr(const void* segment, int c)
*/
void* memrchr(const void* segment, int c, size_t size)
{
+ char* s = segment;
while (size--)
- if (segment[size] == c)
- return segment + size;
+ if (s[size] == c)
+ return s + size;
return NULL;
}
diff --git a/src/string/strcmp.c b/src/string/strcmp.c
index 966bb06..f626f91 100644
--- a/src/string/strcmp.c
+++ b/src/string/strcmp.c
@@ -17,7 +17,6 @@
*/
#include <string.h>
#include <strings.h>
-#include <stddef.h>
#include <inttypes.h>
#include <ctype.h>
diff --git a/src/string/strcpy.c b/src/string/strcpy.c
index dfbdc75..17dd339 100644
--- a/src/string/strcpy.c
+++ b/src/string/strcpy.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
@@ -93,7 +92,7 @@ char* strstrcpy(char* restrict whither, const char* restrict whence, const char*
{
const char* stop = str == NULL ? NULL : strstr(whence, str);
size_t n = stop == NULL ? strlen(whence) : (size_t)(stop - whence);
- char* r = stop == NULL ? NULL ? whither + n;
+ char* r = stop == NULL ? NULL : (whither + n);
memcpy(whither, whence, n);
whither[n] = 0;
return r;
diff --git a/src/string/strdup.c b/src/string/strdup.c
index c65970e..c23548b 100644
--- a/src/string/strdup.c
+++ b/src/string/strdup.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
diff --git a/src/string/strerror.c b/src/string/strerror.c
index 7366f63..87f3261 100644
--- a/src/string/strerror.c
+++ b/src/string/strerror.c
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
+#include <errno.h>
diff --git a/src/string/strfry.c b/src/string/strfry.c
index f020202..cf8d643 100644
--- a/src/string/strfry.c
+++ b/src/string/strfry.c
@@ -34,13 +34,16 @@
char* strfry(char* anagram)
{
size_t i, j;
+ int r;
char t;
if (anagram == NULL)
return NULL;
for (i = strlen(anagram); --i;)
{
- j = (int)((double)rand() / (RAND_MAX + 1));
+ r = rand();
+ j = (int)((double)r / (RAND_MAX + 1));
t = anagram[i], anagram[i] = anagram[j], anagram[j] = t;
}
+ return anagram;
}
diff --git a/src/string/strlen.c b/src/string/strlen.c
index 7023cc0..7a08fa0 100644
--- a/src/string/strlen.c
+++ b/src/string/strlen.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
diff --git a/src/string/strmove.c b/src/string/strmove.c
index 86298cf..596822a 100644
--- a/src/string/strmove.c
+++ b/src/string/strmove.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
@@ -97,7 +96,7 @@ char* strstrmove(char* whither, const char* whence, const char* restrict str)
{
const char* stop = str == NULL ? NULL : strstr(whence, str);
size_t n = stop == NULL ? strlen(whence) : (size_t)(stop - whence);
- char* r = stop == NULL ? NULL ? whither + n;
+ char* r = stop == NULL ? NULL : (whither + n);
memmove(whither, whence, n);
whither[n] = 0;
return r;
diff --git a/src/string/strspn.c b/src/string/strspn.c
index cf82529..3facfd8 100644
--- a/src/string/strspn.c
+++ b/src/string/strspn.c
@@ -16,7 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
+
+
+# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
@@ -59,7 +61,7 @@ size_t strcspn(const char* string, const char* stopset)
char c;
const char* s = string;
memset(set, 0, 256);
- while ((c = *skipset++))
+ while ((c = *stopset++))
set[(size_t)c] = 1;
while ((c = *s++))
if (!set[(size_t)c])
@@ -86,7 +88,7 @@ char* stpbrk(const char* string, const char* stopset)
char c;
const char* s = string;
memset(set, 0, 256);
- while ((c = *skipset++))
+ while ((c = *stopset++))
set[(size_t)c] = 1;
while ((c = *s++))
if (!set[(size_t)c])
diff --git a/src/string/strstr.c b/src/string/strstr.c
index a7e490a..68cc647 100644
--- a/src/string/strstr.c
+++ b/src/string/strstr.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
#include <inttypes.h>
diff --git a/src/string/strtok.c b/src/string/strtok.c
index 04668fc..1520431 100644
--- a/src/string/strtok.c
+++ b/src/string/strtok.c
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
-#include <stddef.h>
@@ -102,7 +101,7 @@ char* strsep(char** restrict string, const char* restrict delimiters)
if (r == NULL)
return NULL;
- next = stpbrk(string, delimiters);
+ next = stpbrk(r, delimiters);
if (next != NULL)
*next++ = 0;
*string = next;
diff --git a/src/strings/bzero.c b/src/strings/bzero.c
index ab7a5f8..4be0948 100644
--- a/src/strings/bzero.c
+++ b/src/strings/bzero.c
@@ -23,7 +23,7 @@
/**
* `memset`, except calls to it cannot be removed by the compiler.
*/
-void* (volatile *__slibc_explicit_memset)(void*, int, size_t) = memset;
+void* (*volatile __slibc_explicit_memset)(void*, int, size_t) = memset;