extension.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2
  4. *
  5. * Copyright (c) 2013, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to install, execute and perform the Spine Runtimes
  10. * Software (the "Software") solely for internal use. Without the written
  11. * permission of Esoteric Software, you may not (a) modify, translate, adapt or
  12. * otherwise create derivative works, improvements of the Software or develop
  13. * new applications using the Software or (b) remove, delete, alter or obscure
  14. * any trademarks or any copyright, trademark, patent or other intellectual
  15. * property or proprietary rights notices on or in the Software, including
  16. * any copy thereof. Redistributions in binary or source form must include
  17. * this license and terms. THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #include <spine/extension.h>
  29. #include <stdio.h>
  30. static void* (*mallocFunc) (size_t size) = malloc;
  31. static void (*freeFunc) (void* ptr) = free;
  32. void* _malloc (size_t size) {
  33. return mallocFunc(size);
  34. }
  35. void* _calloc (size_t num, size_t size) {
  36. void* ptr = mallocFunc(num * size);
  37. if (ptr) memset(ptr, 0, num * size);
  38. return ptr;
  39. }
  40. void _free (void* ptr) {
  41. freeFunc(ptr);
  42. }
  43. void _setMalloc (void* (*malloc) (size_t size)) {
  44. mallocFunc = malloc;
  45. }
  46. void _setFree (void (*free) (void* ptr)) {
  47. freeFunc = free;
  48. }
  49. char* _readFile (const char* path, int* length) {
  50. char *data;
  51. FILE *file = fopen(path, "rb");
  52. if (!file) return 0;
  53. fseek(file, 0, SEEK_END);
  54. *length = (int)ftell(file);
  55. fseek(file, 0, SEEK_SET);
  56. data = MALLOC(char, *length);
  57. fread(data, 1, *length, file);
  58. fclose(file);
  59. return data;
  60. }
  61. void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) {
  62. }
  63. void _spAtlasPage_disposeTexture (spAtlasPage* self) {
  64. }
  65. char* _spUtil_readFile (const char* path, int* length) {
  66. return _readFile(path, length);
  67. }