utils.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Useful functions for winegcc
  3. *
  4. * Copyright 2000 Francois Gouget
  5. * Copyright 2002 Dimitrie O. Paun
  6. * Copyright 2003 Richard Cohen
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  21. */
  22. #ifndef __GNUC__
  23. #define __attribute__(X)
  24. #endif
  25. #ifndef DECLSPEC_NORETURN
  26. # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
  27. # define DECLSPEC_NORETURN __declspec(noreturn)
  28. # elif defined(__GNUC__)
  29. # define DECLSPEC_NORETURN __attribute__((noreturn))
  30. # else
  31. # define DECLSPEC_NORETURN
  32. # endif
  33. #endif
  34. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  35. enum target_cpu
  36. {
  37. CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64
  38. };
  39. enum target_platform
  40. {
  41. PLATFORM_UNSPECIFIED,
  42. PLATFORM_APPLE,
  43. PLATFORM_ANDROID,
  44. PLATFORM_SOLARIS,
  45. PLATFORM_WINDOWS,
  46. PLATFORM_MINGW,
  47. PLATFORM_CYGWIN
  48. };
  49. void DECLSPEC_NORETURN error(const char* s, ...);
  50. void* xmalloc(size_t size);
  51. void* xrealloc(void* p, size_t size);
  52. char *xstrdup( const char *str );
  53. char* strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 )));
  54. int strendswith(const char* str, const char* end);
  55. typedef struct {
  56. size_t maximum;
  57. size_t size;
  58. const char** base;
  59. } strarray;
  60. strarray* strarray_alloc(void);
  61. strarray* strarray_dup(const strarray* arr);
  62. void strarray_free(strarray* arr);
  63. void strarray_add(strarray* arr, const char* str);
  64. void strarray_del(strarray* arr, unsigned int i);
  65. void strarray_addall(strarray* arr, const strarray* from);
  66. strarray* strarray_fromstring(const char* str, const char* delim);
  67. char* strarray_tostring(const strarray* arr, const char* sep);
  68. typedef enum {
  69. file_na, file_other, file_obj, file_res, file_rc,
  70. file_arh, file_dll, file_so, file_def, file_spec
  71. } file_type;
  72. char* get_basename(const char* file);
  73. void create_file(const char* name, int mode, const char* fmt, ...);
  74. file_type get_file_type(const char* filename);
  75. file_type get_lib_type(enum target_platform platform, strarray* path, const char *library,
  76. const char *suffix, char** file);
  77. const char *find_binary( const strarray* prefix, const char *name );
  78. int spawn(const strarray* prefix, const strarray* arr, int ignore_errors);
  79. extern int verbose;