plibc.c 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*****************************************************************************\
  2. * EFSL - Embedded Filesystems Library *
  3. * ----------------------------------- *
  4. * *
  5. * Filename : plibc.c *
  6. * Release : 0.3 - devel *
  7. * Description : This file contains replacements of common c library functions *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of the GNU General Public License *
  11. * as published by the Free Software Foundation; version 2 *
  12. * of the License. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, *
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  17. * GNU General Public License for more details. *
  18. * *
  19. * As a special exception, if other files instantiate templates or *
  20. * use macros or inline functions from this file, or you compile this *
  21. * file and link it with other works to produce a work based on this file, *
  22. * this file does not by itself cause the resulting work to be covered *
  23. * by the GNU General Public License. However the source code for this *
  24. * file must still be made available in accordance with section (3) of *
  25. * the GNU General Public License. *
  26. * *
  27. * This exception does not invalidate any other reasons why a work based *
  28. * on this file might be covered by the GNU General Public License. *
  29. * *
  30. * (c)2006 Lennart Yseboodt *
  31. * (c)2006 Michael De Nil *
  32. \*****************************************************************************/
  33. /*****************************************************************************/
  34. #include "plibc.h"
  35. /*****************************************************************************/
  36. /* ****************************************************************************
  37. * unsigned short strMatch(char* bufa, char*bufb, unsigned long n)
  38. * Description: Compares bufa and bufb for a length of n bytes.
  39. * Return value: Returns the number of character NOT matching.
  40. */
  41. euint16 strMatch(eint8* bufa, eint8*bufb,euint32 n)
  42. {
  43. euint32 c;
  44. euint16 res=0;
  45. for(c=0;c<n;c++)if(bufa[c]!=bufb[c])res++;
  46. return(res);
  47. }
  48. /*****************************************************************************/
  49. /* ****************************************************************************
  50. * void memCpy(void* psrc, void* pdest, unsigned long size)
  51. * Description: Copies the contents of psrc into pdest on a byte per byte basis.
  52. * The total number of bytes copies is size.
  53. */
  54. void memCpy(void* psrc, void* pdest, euint32 size)
  55. {
  56. while(size>0){
  57. *((eint8*)pdest+size-1)=*((eint8*)psrc+size-1);
  58. size--;
  59. }
  60. }
  61. /*****************************************************************************/
  62. void memClr(void *pdest,euint32 size)
  63. {
  64. while(size>0){
  65. *(((eint8*)pdest)+size-1)=0x00;
  66. size--;
  67. }
  68. }
  69. void memSet(void *pdest,euint32 size,euint8 data)
  70. {
  71. while(size>0){
  72. *(((eint8*)pdest)+size-1)=data;
  73. size--;
  74. }
  75. }