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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <malloc.h>
  18. #include <unistd.h>
  19. #include "util.h"
  20. void die(const char *fmt, ...) {
  21. va_list args;
  22. va_start(args, fmt);
  23. fprintf(stderr, "ERROR: ");
  24. vfprintf(stderr, fmt, args);
  25. if (fmt[strlen(fmt) - 1] != '\n')
  26. fprintf(stderr, "\n");
  27. va_end(args);
  28. exit(EXIT_FAILURE);
  29. }
  30. void *xmalloc(size_t size) {
  31. void *ret = memalign(16, size);
  32. if (!ret)
  33. die("Can't alloc %ld bytes\n", (unsigned long)size);
  34. return ret;
  35. }
  36. void *xzalloc(size_t size) {
  37. void *ret = xmalloc(size);
  38. memset(ret, 0, size);
  39. return ret;
  40. }
  41. void *xcalloc(size_t nmemb, size_t size) {
  42. return xzalloc(nmemb * size);
  43. }
  44. void *xrealloc(void *ptr, size_t size) {
  45. void *ret = realloc(ptr, size);
  46. if (!ret)
  47. die("Can't realloc %ld bytes\n", (unsigned long)size);
  48. return ret;
  49. }
  50. char *xstrdup(const char *s) {
  51. char *ret;
  52. if (!s)
  53. return NULL;
  54. ret = strdup(s);
  55. if (!ret)
  56. die("Can't strdup %lu bytes\n", (unsigned long)strlen(s) + 1);
  57. return ret;
  58. }
  59. char *xstrndup(const char *s, size_t n) {
  60. char *ret;
  61. if (!s)
  62. return NULL;
  63. ret = strndup(s, n);
  64. if (!ret)
  65. die("Can't strndup %lu bytes\n", (unsigned long)n + 1);
  66. return ret;
  67. }
  68. bool streq(const char *s1, const char *s2) {
  69. if(!s1 && s2) { return 0; }
  70. if(s1 && !s2) { return 0; }
  71. if(!s1 && !s2) { return 1; }
  72. return strcmp(s1, s2) == 0;
  73. }