// String manipulation functions. // // Copyright (C) 2008-2013 Kevin O'Connor // // This file may be distributed under the terms of the GNU LGPLv3 license. #include "stacks.h" // yield #include "string.h" // memcpy #include "farptr.h" // SET_SEG /**************************************************************** * String ops ****************************************************************/ // Sum the bytes in the specified area. u8 checksum_far(u16 buf_seg, void *buf_far, u32 len) { SET_SEG(ES, buf_seg); u32 i; u8 sum = 0; for (i=0; i 3) { u32 copylen = len; if (copylen > 2048) copylen = 2048; copylen /= 4; len -= copylen * 4; asm volatile( "rep movsl (%%esi),%%es:(%%edi)" : "+c"(copylen), "+S"(s), "+D"(d) : : "cc", "memory"); yield(); } if (len) // Copy any remaining bytes. memcpy(d, s, len); } void * memmove(void *d, const void *s, size_t len) { if (s >= d) return memcpy(d, s, len); d += len-1; s += len-1; while (len--) { *(char*)d = *(char*)s; d--; s--; } return d; } // Copy a string - truncating it if necessary. char * strtcpy(char *dest, const char *src, size_t len) { char *d = dest; while (--len && *src != '\0') *d++ = *src++; *d = '\0'; return dest; } // locate first occurance of character c in the string s char * strchr(const char *s, int c) { for (; *s; s++) if (*s == c) return (char*)s; return NULL; } // Remove any trailing blank characters (spaces, new lines, carriage returns) char * nullTrailingSpace(char *buf) { int len = strlen(buf); char *end = &buf[len-1]; while (end >= buf && *end <= ' ') *(end--) = '\0'; while (*buf && *buf <= ' ') buf++; return buf; }