Configuration of dwm for Mac Computers
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.

100 lines
1.5 KiB

18 years ago
18 years ago
  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <sys/wait.h>
  11. #include <unistd.h>
  12. #include "util.h"
  13. void
  14. error(char *errstr, ...) {
  15. va_list ap;
  16. va_start(ap, errstr);
  17. vfprintf(stderr, errstr, ap);
  18. va_end(ap);
  19. exit(1);
  20. }
  21. static void
  22. bad_malloc(unsigned int size)
  23. {
  24. fprintf(stderr, "fatal: could not malloc() %d bytes\n",
  25. (int) size);
  26. exit(1);
  27. }
  28. void *
  29. emallocz(unsigned int size)
  30. {
  31. void *res = calloc(1, size);
  32. if(!res)
  33. bad_malloc(size);
  34. return res;
  35. }
  36. void *
  37. emalloc(unsigned int size)
  38. {
  39. void *res = malloc(size);
  40. if(!res)
  41. bad_malloc(size);
  42. return res;
  43. }
  44. void *
  45. erealloc(void *ptr, unsigned int size)
  46. {
  47. void *res = realloc(ptr, size);
  48. if(!res)
  49. bad_malloc(size);
  50. return res;
  51. }
  52. char *
  53. estrdup(const char *str)
  54. {
  55. void *res = strdup(str);
  56. if(!res)
  57. bad_malloc(strlen(str));
  58. return res;
  59. }
  60. void
  61. failed_assert(char *a, char *file, int line)
  62. {
  63. fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line);
  64. abort();
  65. }
  66. void
  67. swap(void **p1, void **p2)
  68. {
  69. void *tmp = *p1;
  70. *p1 = *p2;
  71. *p2 = tmp;
  72. }
  73. void
  74. spawn(Display *dpy, const char *shell, const char *cmd)
  75. {
  76. if(!cmd || !shell)
  77. return;
  78. if(fork() == 0) {
  79. if(fork() == 0) {
  80. if(dpy)
  81. close(ConnectionNumber(dpy));
  82. execl(shell, shell, "-c", cmd, (const char *)0);
  83. fprintf(stderr, "gridwm: execl %s", shell);
  84. perror(" failed");
  85. }
  86. exit (0);
  87. }
  88. wait(0);
  89. }