Permalink
Browse files

added strnlen

  • Loading branch information...
1 parent 951bb48 commit 5678c73dd36bde337d69959f6205a55dca49d147 @Fleurer committed Apr 1, 2012
Showing with 13 additions and 0 deletions.
  1. +1 −0 src/inc/lib.h
  2. +6 −0 src/lib/string.c
  3. +6 −0 usr/libsys/string.c
View
@@ -12,6 +12,7 @@ void* memcpy(void *dest, void *src, unsigned int count);
void* memset(void *dest, char val, unsigned int count);
short* memsetw(short *dest, short val, unsigned int count);
int strlen(char *str);
+int strnlen(char *str, unsigned int size);
char* strchr(const char *str, int c);
char* strrchr(const char *str, int c);
int strcmp(char *s1, char *s2);
View
@@ -35,6 +35,12 @@ int strlen(char *str){
return sp-str;
}
+int strnlen(char *str, unsigned int len){
+ char *sp;
+ for (sp=str; *sp != '\0' && sp <= str+len; sp++);
+ return sp-str;
+}
+
char* strcpy(char *dst, const char *src) {
char *tmp = dst;
while (*dst++ = *src++);
View
@@ -35,6 +35,12 @@ int strlen(char *str){
return sp-str;
}
+int strnlen(char *str, unsigned int len){
+ char *sp;
+ for (sp=str; *sp != '\0' && sp < str+len; sp++);
+ return sp-str;
+}
+
/* ------------------------------------------------------ */
char* strcpy(char *dst, const char *src) {

0 comments on commit 5678c73

Please sign in to comment.