Skip to content
This repository has been archived by the owner on Jan 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from warmachine2002/master
Browse files Browse the repository at this point in the history
Implemented more <string.h> functions.
  • Loading branch information
artob committed Jul 18, 2016
2 parents 3fe91ec + 82aa20f commit e4ca94f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions CREDITS
@@ -1 +1,2 @@
* Vlad Gluhovsky <gluk256@gmail.com>
* Syed Nasim <warhacker.2002@gmail.com>
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -220,6 +220,8 @@ Contributors

* `Vlad Gluhovsky <https://github.com/gluckq>`_

* `Syed Nasim <https://github.com/warmachine2002>`_

Donations
=========

Expand Down
Empty file modified autogen.sh 100755 → 100644
Empty file.
9 changes: 8 additions & 1 deletion src/string/memcpy.c
Expand Up @@ -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;
}
21 changes: 20 additions & 1 deletion src/string/memmove.c
Expand Up @@ -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;
}
9 changes: 8 additions & 1 deletion src/string/strcat.c
Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion src/string/strcpy.c
Expand Up @@ -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;
}
16 changes: 15 additions & 1 deletion src/string/strncmp.c
Expand Up @@ -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 );
}
}
12 changes: 11 additions & 1 deletion src/string/strncpy.c
Expand Up @@ -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.