💾 Archived View for gemini.rmf-dev.com › repo › Vaati › cwm › files › 211d64c9bee769a5de6b8e9148d0c2… captured on 2023-01-29 at 04:31:54. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-03-20)

-=-=-=-=-=-=-

0 /*

1 * calmwm - the calm window manager

2 *

3 * Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>

4 *

5 * Permission to use, copy, modify, and distribute this software for any

6 * purpose with or without fee is hereby granted, provided that the above

7 * copyright notice and this permission notice appear in all copies.

8 *

9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF

11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR

12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES

13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN

14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF

15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

16 *

17 * $OpenBSD$

18 */

19

20 #include <sys/types.h>

21 #include <sys/queue.h>

22

23 #include <err.h>

24 #include <errno.h>

25 #include <limits.h>

26 #include <stdarg.h>

27 #include <stdint.h>

28 #include <stdio.h>

29 #include <stdlib.h>

30 #include <string.h>

31 #include <unistd.h>

32

33 #include "calmwm.h"

34

35 void *

36 xmalloc(size_t siz)

37 {

38 void *p;

39

40 if (siz == 0)

41 errx(1, "xmalloc: zero size");

42 if ((p = malloc(siz)) == NULL)

43 err(1, "malloc");

44

45 return p;

46 }

47

48 void *

49 xcalloc(size_t no, size_t siz)

50 {

51 void *p;

52

53 if (siz == 0 || no == 0)

54 errx(1, "xcalloc: zero size");

55 if (SIZE_MAX / no < siz)

56 errx(1, "xcalloc: no * siz > SIZE_MAX");

57 if ((p = calloc(no, siz)) == NULL)

58 err(1, "calloc");

59

60 return p;

61 }

62

63 void *

64 xreallocarray(void *ptr, size_t nmemb, size_t size)

65 {

66 void *p;

67

68 p = reallocarray(ptr, nmemb, size);

69 if (p == NULL)

70 errx(1, "xreallocarray: out of memory (new_size %zu bytes)",

71 nmemb * size);

72 return p;

73 }

74

75 char *

76 xstrdup(const char *str)

77 {

78 char *p;

79

80 if ((p = strdup(str)) == NULL)

81 err(1, "strdup");

82

83 return p;

84 }

85

86 int

87 xasprintf(char **ret, const char *fmt, ...)

88 {

89 va_list ap;

90 int i;

91

92 va_start(ap, fmt);

93 i = xvasprintf(ret, fmt, ap);

94 va_end(ap);

95

96 return i;

97 }

98

99 int

100 xvasprintf(char **ret, const char *fmt, va_list ap)

101 {

102 int i;

103

104 i = vasprintf(ret, fmt, ap);

105 if (i == -1)

106 err(1, "vasprintf");

107

108 return i;

109 }

110