tiny_stdlib.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*############################################################################
  2. # Copyright 2017 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /// Tiny portable implementations of standard library functions
  17. /*! \file */
  18. #ifndef EPID_MEMBER_TINY_STDLIB_TINY_STDLIB_H_
  19. #define EPID_MEMBER_TINY_STDLIB_TINY_STDLIB_H_
  20. #include <stddef.h>
  21. /// Fill block of memory
  22. /*!
  23. * Sets the first num bytes of the block of memory pointed by ptr
  24. * to the specified value (interpreted as an unsigned char)
  25. *
  26. * \param ptr Pointer to the block of memory to fill.
  27. * \param value Value to be set. The value is passed as an int,
  28. * but the function fills the block of memory using the
  29. * unsigned char conversion of this value.
  30. * \param num Number of bytes to be set to the value. size_t is
  31. * an unsigned integral type.
  32. * \result ptr is returned.
  33. */
  34. void* memset(void* ptr, int value, size_t num);
  35. /// Compare two blocks of memory
  36. /*!
  37. * Compares the first num bytes of the block of memory pointed by
  38. * ptr1 to the first num bytes pointed by ptr2, returning zero if
  39. * they all match or a value different from zero representing which
  40. * is greater if they do not.
  41. *
  42. * Notice that, unlike strcmp, the function does not stop comparing
  43. * after finding a null character.
  44. *
  45. * \param ptr1 Pointer to block of memory.
  46. * \param ptr2 Pointer to block of memory.
  47. * \param num Number of bytes to compare.
  48. * \result an integral value indicating the relationship between the
  49. * content of the memory blocks:
  50. * \retval <0 the first byte that does not match in both memory
  51. * blocks has a lower value in ptr1 than in ptr2 (if
  52. * evaluated as unsigned char values)
  53. * \retval 0 the contents of both memory blocks are equal
  54. * \retval >0 the first byte that does not match in both memory blocks
  55. * has a greater value in ptr1 than in ptr2 (if evaluated
  56. * as unsigned char values)
  57. */
  58. int memcmp(const void* ptr1, const void* ptr2, size_t num);
  59. #endif // EPID_MEMBER_TINY_STDLIB_TINY_STDLIB_H_