config-wrapper-malloc-0-null.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* config.h wrapper that forces calloc(0) to return NULL.
  2. * Used for testing.
  3. */
  4. /*
  5. * Copyright The Mbed TLS Contributors
  6. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  7. *
  8. * This file is provided under the Apache License 2.0, or the
  9. * GNU General Public License v2.0 or later.
  10. *
  11. * **********
  12. * Apache License 2.0:
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. * **********
  27. *
  28. * **********
  29. * GNU General Public License v2.0 or later:
  30. *
  31. * This program is free software; you can redistribute it and/or modify
  32. * it under the terms of the GNU General Public License as published by
  33. * the Free Software Foundation; either version 2 of the License, or
  34. * (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License along
  42. * with this program; if not, write to the Free Software Foundation, Inc.,
  43. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  44. *
  45. * **********
  46. */
  47. #ifndef MBEDTLS_CONFIG_H
  48. /* Don't #define MBEDTLS_CONFIG_H, let config.h do it. */
  49. #include "mbedtls/config.h"
  50. #include <stdlib.h>
  51. static inline void *custom_calloc( size_t nmemb, size_t size )
  52. {
  53. if( nmemb == 0 || size == 0 )
  54. return( NULL );
  55. return( calloc( nmemb, size ) );
  56. }
  57. #define MBEDTLS_PLATFORM_MEMORY
  58. #define MBEDTLS_PLATFORM_STD_CALLOC custom_calloc
  59. #endif /* MBEDTLS_CONFIG_H */