Permalink
Browse files

Merge pull request #2 from warmachine2002/master

Implemented more <string.h> functions.
  • Loading branch information...
bendiken committed Jul 18, 2016
2 parents 3fe91ec + 82aa20f commit e4ca94fa9cccb2e40f1351811202d92c8fde7e7a
Showing with 69 additions and 6 deletions.
  1. +1 −0 CREDITS
  2. +2 −0 README.rst
  3. 0 autogen.sh
  4. +8 −1 src/string/memcpy.c
  5. +20 −1 src/string/memmove.c
  6. +8 −1 src/string/strcat.c
  7. +4 −1 src/string/strcpy.c
  8. +15 −1 src/string/strncmp.c
  9. +11 −1 src/string/strncpy.c
View
@@ -1 +1,2 @@
* Vlad Gluhovsky <gluk256@gmail.com>
* Syed Nasim <warhacker.2002@gmail.com>
View
@@ -220,6 +220,8 @@ Contributors
* `Vlad Gluhovsky <https://github.com/gluckq>`_
* `Syed Nasim <https://github.com/warmachine2002>`_
Donations
=========
View
0 autogen.sh 100755 → 100644
No changes.
View
@@ -9,12 +9,19 @@
/**
* @date 2013-05-24
* @author Arto Bendiken
* @auther Syed Nasim
* @see http://libc11.org/string/memcpy.html
*/
void*
memcpy(void* restrict s1,
const void* restrict s2,
size_t n) {
return (void)s1, (void)s2, (void)n, NULL; // TODO
char * dest = (char *) s1;
const char * src = (const char *) s2;
while ( n-- )
{
*dest++ = *src++;
}
return s1;
}
View
@@ -9,12 +9,31 @@
/**
* @date 2013-05-24
* @author Arto Bendiken
* @auther Syed Nasim
* @see http://libc11.org/string/memmove.html
*/
void*
memmove(void* s1,
const void* s2,
size_t n) {
return (void)s1, (void)s2, (void)n, NULL; // TODO
char * dest = (char *) s1;
const char * src = (const char *) s2;
if ( dest <= src )
{
while ( n-- )
{
*dest++ = *src++;
}
}
else
{
src += n;
dest += n;
while ( n-- )
{
*--dest = *--src;
}
}
return s1;
}
View
@@ -9,11 +9,18 @@
/**
* @date 2014-11-23
* @author Arto Bendiken
* @auther Syed Nasim
* @see http://libc11.org/string/strcat.html
*/
char*
strcat(char* restrict s1,
const char* restrict s2) {
return (void)s1, (void)s2, NULL; // TODO
char * rc = s1;
if ( *s1 )
{
while ( *++s1 );
}
while ( (*s1++ = *s2++) );
return rc;
}
View
@@ -9,11 +9,14 @@
/**
* @date 2014-11-23
* @author Arto Bendiken
* @auther Syed Nasim
* @see http://libc11.org/string/strcpy.html
*/
char*
strcpy(char* restrict s1,
const char* restrict s2) {
return (void)s1, (void)s2, NULL; // TODO
char * rc = s1;
while (( *s1++ = *s2++ ));
return rc;
}
View
@@ -9,12 +9,26 @@
/**
* @date 2013-05-24
* @author Arto Bendiken
* @auther Syed Nasim
* @see http://libc11.org/string/strncmp.html
*/
int
strncmp(const char* const s1,
const char* const s2,
const size_t n) {
return (void)s1, (void)s2, (void)n, -1; // TODO
while ( *s1 && n && ( *s1 == *s2 ) )
{
++s1;
++s2;
--n;
}
if ( ( n == 0 ) )
{
return 0;
}
else
{
return ( *(uint8_t *)s1 - *(uint8_t *)s2 );
}
}
View
@@ -9,12 +9,22 @@
/**
* @date 2014-11-23
* @author Arto Bendiken
* @auther Syed Nasim
* @see http://libc11.org/string/strncpy.html
*/
char*
strncpy(char* restrict s1,
const char* restrict s2,
size_t n) {
return (void)s1, (void)s2, (void)n, NULL; // TODO
char * rc = s1;
while ( ( n > 0 ) && ( *s1++ = *s2++ ) )
{
--n;
}
while ( n-- > 1 )
{
*s1++ = '\0';
}
return rc;
}

0 comments on commit e4ca94f

Please sign in to comment.