videohubctrl can be used to control Blackmagic Design Videohub SDI router device over the network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.c 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * === Utility functions ===
  3. *
  4. * Blackmagic Design Videohub control application
  5. * Copyright (C) 2014 Unix Solutions Ltd.
  6. * Written by Georgi Chorbadzhiyski
  7. *
  8. * Released under MIT license.
  9. * See LICENSE-MIT.txt for license terms.
  10. *
  11. */
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <inttypes.h>
  17. #include <unistd.h>
  18. #include "util.h"
  19. void die(const char *fmt, ...) {
  20. va_list args;
  21. va_start(args, fmt);
  22. fprintf(stderr, "ERROR: ");
  23. vfprintf(stderr, fmt, args);
  24. if (fmt[strlen(fmt) - 1] != '\n')
  25. fprintf(stderr, "\n");
  26. va_end(args);
  27. exit(EXIT_FAILURE);
  28. }
  29. void *xmalloc(size_t size) {
  30. void *ret = malloc(size);
  31. if (!ret)
  32. die("Can't alloc %ld bytes\n", (unsigned long)size);
  33. return ret;
  34. }
  35. void *xzalloc(size_t size) {
  36. void *ret = xmalloc(size);
  37. memset(ret, 0, size);
  38. return ret;
  39. }
  40. void *xcalloc(size_t nmemb, size_t size) {
  41. return xzalloc(nmemb * size);
  42. }
  43. void *xrealloc(void *ptr, size_t size) {
  44. void *ret = realloc(ptr, size);
  45. if (!ret)
  46. die("Can't realloc %ld bytes\n", (unsigned long)size);
  47. return ret;
  48. }
  49. char *xstrdup(const char *s) {
  50. char *ret;
  51. if (!s)
  52. return NULL;
  53. ret = strdup(s);
  54. if (!ret)
  55. die("Can't strdup %lu bytes\n", (unsigned long)strlen(s) + 1);
  56. return ret;
  57. }
  58. char *xstrndup(const char *s, size_t n) {
  59. char *ret;
  60. if (!s)
  61. return NULL;
  62. ret = strndup(s, n);
  63. if (!ret)
  64. die("Can't strndup %lu bytes\n", (unsigned long)n + 1);
  65. return ret;
  66. }
  67. bool streq(const char *s1, const char *s2) {
  68. if(!s1 && s2) { return 0; }
  69. if(s1 && !s2) { return 0; }
  70. if(!s1 && !s2) { return 1; }
  71. return strcmp(s1, s2) == 0;
  72. }