/** * Copyright (c) 2011 Anup Patel. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * @file arm_string.c * @author Anup Patel (anup@brainfault.org) * @brief source file for common string functions */ #include #include void *arm_memcpy(void *dest, const void *src, unsigned int count) { u8 *dst8 = (u8 *) dest; u8 *src8 = (u8 *) src; if (count & 1) { dst8[0] = src8[0]; dst8 += 1; src8 += 1; } count /= 2; while (count--) { dst8[0] = src8[0]; dst8[1] = src8[1]; dst8 += 2; src8 += 2; } return dest; } void *arm_memmove(void *dest, const void *src, unsigned int count) { u8 *dst8 = (u8 *) dest; const u8 *src8 = (u8 *) src; if(dest == src) return dest; if (src8 > dst8) { if (count & 1) { dst8[0] = src8[0]; dst8 += 1; src8 += 1; } count /= 2; while (count--) { dst8[0] = src8[0]; dst8[1] = src8[1]; dst8 += 2; src8 += 2; } } else { dst8 += count; src8 += count; if (count & 1) { dst8 -= 1; src8 -= 1; dst8[0] = src8[0]; } count /= 2; while (count--) { dst8 -= 2; src8 -= 2; dst8[0] = src8[0]; dst8[1] = src8[1]; } } return dest; } void *arm_memset(void *dest, int c, unsigned int count) { u8 *dst8 = (u8 *) dest; u8 ch = (u8) c; if (count & 1) { dst8[0] = ch; dst8 += 1; } count /= 2; while (count--) { dst8[0] = ch; dst8[1] = ch; dst8 += 2; } return dest; } int arm_memcmp(const void *s1, const void *s2, unsigned int count) { u8 *p1 = (u8 *) s1; u8 *p2 = (u8 *) s2; if (count != 0) { do { if (*p1++ != *p2++) return (*--p1 - *--p2); } while (--count != 0); } return (0); } char *arm_memchr(const char *p, int ch, int count) { int i; for(i=0; i> (4 * (8 - ite - 1))) & 0xF)) { continue; } dst[pos] = hexchars[(src >> (4 * (8 - ite - 1))) & 0xF]; pos++; } if (pos == 0) { dst[pos] = '0'; pos++; } dst[pos] = '\0'; } void arm_ulonglong2hexstr(char *dst, unsigned long long src) { int ite, pos = 0; static const char hexchars[] = "0123456789ABCDEF"; for (ite = 0; ite < 16; ite++) { if ((pos == 0) && !((src >> (4 * (16 - ite - 1))) & 0xF)) { continue; } dst[pos] = hexchars[(src >> (4 * (16 - ite - 1))) & 0xF]; pos++; } if (pos == 0) { dst[pos] = '0'; pos++; } dst[pos] = '\0'; }