mandoc 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +7 -0
  3. data/COPYING +674 -0
  4. data/README.md +117 -0
  5. data/ext/mandoc/extconf.rb +59 -0
  6. data/ext/mandoc/rb_mandoc.c +548 -0
  7. data/ext/mandoc/rb_mandoc.h +22 -0
  8. data/lib/mandoc/version.rb +19 -0
  9. data/lib/mandoc.rb +26 -0
  10. data/mandoc-1.14.6/LICENSE +55 -0
  11. data/mandoc-1.14.6/arch.c +54 -0
  12. data/mandoc-1.14.6/att.c +49 -0
  13. data/mandoc-1.14.6/catman.c +260 -0
  14. data/mandoc-1.14.6/cgi.c +1279 -0
  15. data/mandoc-1.14.6/chars.c +507 -0
  16. data/mandoc-1.14.6/compat_err.c +103 -0
  17. data/mandoc-1.14.6/compat_fts.c +696 -0
  18. data/mandoc-1.14.6/compat_fts.h +106 -0
  19. data/mandoc-1.14.6/compat_getline.c +59 -0
  20. data/mandoc-1.14.6/compat_getsubopt.c +87 -0
  21. data/mandoc-1.14.6/compat_isblank.c +23 -0
  22. data/mandoc-1.14.6/compat_mkdtemp.c +50 -0
  23. data/mandoc-1.14.6/compat_mkstemps.c +63 -0
  24. data/mandoc-1.14.6/compat_ohash.c +330 -0
  25. data/mandoc-1.14.6/compat_ohash.h +72 -0
  26. data/mandoc-1.14.6/compat_progname.c +31 -0
  27. data/mandoc-1.14.6/compat_reallocarray.c +40 -0
  28. data/mandoc-1.14.6/compat_recallocarray.c +99 -0
  29. data/mandoc-1.14.6/compat_strcasestr.c +64 -0
  30. data/mandoc-1.14.6/compat_stringlist.c +135 -0
  31. data/mandoc-1.14.6/compat_stringlist.h +48 -0
  32. data/mandoc-1.14.6/compat_strlcat.c +57 -0
  33. data/mandoc-1.14.6/compat_strlcpy.c +52 -0
  34. data/mandoc-1.14.6/compat_strndup.c +42 -0
  35. data/mandoc-1.14.6/compat_strsep.c +70 -0
  36. data/mandoc-1.14.6/compat_strtonum.c +67 -0
  37. data/mandoc-1.14.6/compat_vasprintf.c +47 -0
  38. data/mandoc-1.14.6/config.h +52 -0
  39. data/mandoc-1.14.6/dba.c +508 -0
  40. data/mandoc-1.14.6/dba.h +50 -0
  41. data/mandoc-1.14.6/dba_array.c +190 -0
  42. data/mandoc-1.14.6/dba_array.h +47 -0
  43. data/mandoc-1.14.6/dba_read.c +74 -0
  44. data/mandoc-1.14.6/dba_write.c +127 -0
  45. data/mandoc-1.14.6/dba_write.h +30 -0
  46. data/mandoc-1.14.6/dbm.c +480 -0
  47. data/mandoc-1.14.6/dbm.h +68 -0
  48. data/mandoc-1.14.6/dbm_map.c +194 -0
  49. data/mandoc-1.14.6/dbm_map.h +29 -0
  50. data/mandoc-1.14.6/demandoc.c +260 -0
  51. data/mandoc-1.14.6/eqn.c +1132 -0
  52. data/mandoc-1.14.6/eqn.h +72 -0
  53. data/mandoc-1.14.6/eqn_html.c +246 -0
  54. data/mandoc-1.14.6/eqn_parse.h +48 -0
  55. data/mandoc-1.14.6/eqn_term.c +174 -0
  56. data/mandoc-1.14.6/html.c +1102 -0
  57. data/mandoc-1.14.6/html.h +142 -0
  58. data/mandoc-1.14.6/lib.c +35 -0
  59. data/mandoc-1.14.6/libman.h +42 -0
  60. data/mandoc-1.14.6/libmandoc.h +85 -0
  61. data/mandoc-1.14.6/libmdoc.h +87 -0
  62. data/mandoc-1.14.6/main.c +1375 -0
  63. data/mandoc-1.14.6/main.h +53 -0
  64. data/mandoc-1.14.6/man.c +345 -0
  65. data/mandoc-1.14.6/man.h +21 -0
  66. data/mandoc-1.14.6/man_html.c +640 -0
  67. data/mandoc-1.14.6/man_macro.c +470 -0
  68. data/mandoc-1.14.6/man_term.c +1143 -0
  69. data/mandoc-1.14.6/man_validate.c +660 -0
  70. data/mandoc-1.14.6/manconf.h +58 -0
  71. data/mandoc-1.14.6/mandoc.c +669 -0
  72. data/mandoc-1.14.6/mandoc.h +329 -0
  73. data/mandoc-1.14.6/mandoc_aux.c +118 -0
  74. data/mandoc-1.14.6/mandoc_aux.h +27 -0
  75. data/mandoc-1.14.6/mandoc_msg.c +375 -0
  76. data/mandoc-1.14.6/mandoc_ohash.c +65 -0
  77. data/mandoc-1.14.6/mandoc_ohash.h +23 -0
  78. data/mandoc-1.14.6/mandoc_parse.h +44 -0
  79. data/mandoc-1.14.6/mandoc_xr.c +123 -0
  80. data/mandoc-1.14.6/mandoc_xr.h +31 -0
  81. data/mandoc-1.14.6/mandocd.c +282 -0
  82. data/mandoc-1.14.6/mandocdb.c +2448 -0
  83. data/mandoc-1.14.6/manpath.c +363 -0
  84. data/mandoc-1.14.6/mansearch.c +851 -0
  85. data/mandoc-1.14.6/mansearch.h +118 -0
  86. data/mandoc-1.14.6/mdoc.c +433 -0
  87. data/mandoc-1.14.6/mdoc.h +158 -0
  88. data/mandoc-1.14.6/mdoc_argv.c +682 -0
  89. data/mandoc-1.14.6/mdoc_html.c +1762 -0
  90. data/mandoc-1.14.6/mdoc_macro.c +1600 -0
  91. data/mandoc-1.14.6/mdoc_man.c +1850 -0
  92. data/mandoc-1.14.6/mdoc_markdown.c +1610 -0
  93. data/mandoc-1.14.6/mdoc_state.c +256 -0
  94. data/mandoc-1.14.6/mdoc_term.c +1964 -0
  95. data/mandoc-1.14.6/mdoc_validate.c +3062 -0
  96. data/mandoc-1.14.6/msec.c +37 -0
  97. data/mandoc-1.14.6/out.c +544 -0
  98. data/mandoc-1.14.6/out.h +70 -0
  99. data/mandoc-1.14.6/preconv.c +179 -0
  100. data/mandoc-1.14.6/read.c +732 -0
  101. data/mandoc-1.14.6/roff.c +4390 -0
  102. data/mandoc-1.14.6/roff.h +561 -0
  103. data/mandoc-1.14.6/roff_html.c +119 -0
  104. data/mandoc-1.14.6/roff_int.h +94 -0
  105. data/mandoc-1.14.6/roff_term.c +266 -0
  106. data/mandoc-1.14.6/roff_validate.c +151 -0
  107. data/mandoc-1.14.6/soelim.c +182 -0
  108. data/mandoc-1.14.6/st.c +82 -0
  109. data/mandoc-1.14.6/tag.c +327 -0
  110. data/mandoc-1.14.6/tag.h +35 -0
  111. data/mandoc-1.14.6/tbl.c +183 -0
  112. data/mandoc-1.14.6/tbl.h +121 -0
  113. data/mandoc-1.14.6/tbl_data.c +323 -0
  114. data/mandoc-1.14.6/tbl_html.c +293 -0
  115. data/mandoc-1.14.6/tbl_int.h +47 -0
  116. data/mandoc-1.14.6/tbl_layout.c +376 -0
  117. data/mandoc-1.14.6/tbl_opts.c +173 -0
  118. data/mandoc-1.14.6/tbl_parse.h +30 -0
  119. data/mandoc-1.14.6/tbl_term.c +948 -0
  120. data/mandoc-1.14.6/term.c +1113 -0
  121. data/mandoc-1.14.6/term.h +158 -0
  122. data/mandoc-1.14.6/term_ascii.c +424 -0
  123. data/mandoc-1.14.6/term_ps.c +1362 -0
  124. data/mandoc-1.14.6/term_tab.c +130 -0
  125. data/mandoc-1.14.6/term_tag.c +227 -0
  126. data/mandoc-1.14.6/term_tag.h +34 -0
  127. data/mandoc-1.14.6/tree.c +536 -0
  128. metadata +170 -0
@@ -0,0 +1,106 @@
1
+ /* $OpenBSD: fts.h,v 1.14 2012/12/05 23:19:57 deraadt Exp $ */
2
+ /* $NetBSD: fts.h,v 1.7 2012/03/01 16:18:51 hans Exp $ */
3
+
4
+ /*
5
+ * Copyright (c) 1989, 1993
6
+ * The Regents of the University of California. All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions
10
+ * are met:
11
+ * 1. Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * 3. Neither the name of the University nor the names of its contributors
17
+ * may be used to endorse or promote products derived from this software
18
+ * without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
+ * SUCH DAMAGE.
31
+ *
32
+ * @(#)fts.h 8.3 (Berkeley) 8/14/94
33
+ */
34
+
35
+ #ifndef _FTS_H_
36
+ #define _FTS_H_
37
+
38
+ typedef struct {
39
+ struct _ftsent *fts_cur; /* current node */
40
+ struct _ftsent *fts_child; /* linked list of children */
41
+ struct _ftsent **fts_array; /* sort array */
42
+ dev_t fts_dev; /* starting device # */
43
+ char *fts_path; /* path for this descent */
44
+ size_t fts_pathlen; /* sizeof(path) */
45
+ int fts_nitems; /* elements in the sort array */
46
+ int (*fts_compar)(const struct _ftsent **, const struct _ftsent **);
47
+ /* compare function */
48
+
49
+ #define FTS_NOCHDIR 0x0004 /* don't change directories */
50
+ #define FTS_PHYSICAL 0x0010 /* physical walk */
51
+ #define FTS_XDEV 0x0040 /* don't cross devices */
52
+ #define FTS_OPTIONMASK 0x0054 /* valid user option mask */
53
+
54
+ #define FTS_STOP 0x2000 /* (private) unrecoverable error */
55
+ int fts_options; /* fts_open options, global flags */
56
+ } FTS;
57
+
58
+ typedef struct _ftsent {
59
+ struct _ftsent *fts_cycle; /* cycle node */
60
+ struct _ftsent *fts_parent; /* parent directory */
61
+ struct _ftsent *fts_link; /* next file in directory */
62
+ char *fts_accpath; /* access path */
63
+ char *fts_path; /* root path */
64
+ int fts_errno; /* errno for this node */
65
+ size_t fts_pathlen; /* strlen(fts_path) */
66
+ size_t fts_namelen; /* strlen(fts_name) */
67
+
68
+ ino_t fts_ino; /* inode */
69
+ dev_t fts_dev; /* device */
70
+ nlink_t fts_nlink; /* link count */
71
+
72
+ #define FTS_ROOTPARENTLEVEL -1
73
+ #define FTS_ROOTLEVEL 0
74
+ #define FTS_MAXLEVEL 0x7fffffff
75
+ int fts_level; /* depth (-1 to N) */
76
+
77
+ #define FTS_D 1 /* preorder directory */
78
+ #define FTS_DC 2 /* directory that causes cycles */
79
+ #define FTS_DEFAULT 3 /* none of the above */
80
+ #define FTS_DNR 4 /* unreadable directory */
81
+ #define FTS_DOT 5 /* dot or dot-dot */
82
+ #define FTS_DP 6 /* postorder directory */
83
+ #define FTS_ERR 7 /* error; errno is set */
84
+ #define FTS_F 8 /* regular file */
85
+ #define FTS_INIT 9 /* initialized only */
86
+ #define FTS_NS 10 /* stat(2) failed */
87
+ #define FTS_NSOK 11 /* no stat(2) requested */
88
+ #define FTS_SL 12 /* symbolic link */
89
+ unsigned short fts_info; /* user flags for FTSENT structure */
90
+
91
+ #define FTS_NOINSTR 3 /* no instructions */
92
+ #define FTS_SKIP 4 /* discard node */
93
+ unsigned short fts_instr; /* fts_set() instructions */
94
+
95
+ struct stat *fts_statp; /* stat(2) information */
96
+ char fts_name[1]; /* file name */
97
+ } FTSENT;
98
+
99
+
100
+ int fts_close(FTS *);
101
+ FTS *fts_open(char * const *, int,
102
+ int (*)(const FTSENT **, const FTSENT **));
103
+ FTSENT *fts_read(FTS *);
104
+ int fts_set(FTS *, FTSENT *, int);
105
+
106
+ #endif /* !_FTS_H_ */
@@ -0,0 +1,59 @@
1
+ /* $Id: compat_getline.c,v 1.2 2020/06/15 01:37:14 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.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
+ #include "config.h"
18
+
19
+ #include <sys/types.h>
20
+ #include <errno.h>
21
+ #include <stdio.h>
22
+ #include <stdlib.h>
23
+
24
+ ssize_t
25
+ getline(char **buf, size_t *bufsz, FILE *fp)
26
+ {
27
+ char *nbuf;
28
+ size_t nbufsz, pos;
29
+ int c;
30
+
31
+ if (buf == NULL || bufsz == NULL) {
32
+ errno = EINVAL;
33
+ return -1;
34
+ }
35
+
36
+ if (*buf == NULL)
37
+ *bufsz = 0;
38
+ else
39
+ **buf = '\0';
40
+
41
+ pos = 0;
42
+ for (;;) {
43
+ if (pos + 1 >= *bufsz) {
44
+ nbufsz = *bufsz ? *bufsz * 2 : BUFSIZ;
45
+ if ((nbuf = realloc(*buf, nbufsz)) == NULL)
46
+ return -1;
47
+ *buf = nbuf;
48
+ *bufsz = nbufsz;
49
+ }
50
+ if ((c = fgetc(fp)) == EOF) {
51
+ (*buf)[pos] = '\0';
52
+ return pos > 0 && feof(fp) ? (ssize_t)pos : -1;
53
+ }
54
+ (*buf)[pos++] = c;
55
+ (*buf)[pos] = '\0';
56
+ if (c == '\n')
57
+ return pos;
58
+ }
59
+ }
@@ -0,0 +1,87 @@
1
+ /* $Id: compat_getsubopt.c,v 1.6 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /* $OpenBSD: getsubopt.c,v 1.4 2005/08/08 08:05:36 espie Exp $ */
3
+
4
+ /*-
5
+ * Copyright (c) 1990, 1993
6
+ * The Regents of the University of California. All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions
10
+ * are met:
11
+ * 1. Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * 3. Neither the name of the University nor the names of its contributors
17
+ * may be used to endorse or promote products derived from this software
18
+ * without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
+ * SUCH DAMAGE.
31
+ */
32
+ #include "config.h"
33
+
34
+ #include <unistd.h>
35
+ #include <stdlib.h>
36
+ #include <string.h>
37
+
38
+ int
39
+ getsubopt(char **optionp, char * const *tokens, char **valuep)
40
+ {
41
+ int cnt;
42
+ char *suboptarg;
43
+ char *p;
44
+
45
+ suboptarg = *valuep = NULL;
46
+
47
+ if (!optionp || !*optionp)
48
+ return(-1);
49
+
50
+ /* skip leading white-space, commas */
51
+ for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
52
+
53
+ if (!*p) {
54
+ *optionp = p;
55
+ return(-1);
56
+ }
57
+
58
+ /* save the start of the token, and skip the rest of the token. */
59
+ for (suboptarg = p;
60
+ *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';);
61
+
62
+ if (*p) {
63
+ /*
64
+ * If there's an equals sign, set the value pointer, and
65
+ * skip over the value part of the token. Terminate the
66
+ * token.
67
+ */
68
+ if (*p == '=') {
69
+ *p = '\0';
70
+ for (*valuep = ++p;
71
+ *p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
72
+ if (*p)
73
+ *p++ = '\0';
74
+ } else
75
+ *p++ = '\0';
76
+ /* Skip any whitespace or commas after this token. */
77
+ for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
78
+ }
79
+
80
+ /* set optionp for next round. */
81
+ *optionp = p;
82
+
83
+ for (cnt = 0; *tokens; ++tokens, ++cnt)
84
+ if (!strcmp(suboptarg, *tokens))
85
+ return(cnt);
86
+ return(-1);
87
+ }
@@ -0,0 +1,23 @@
1
+ /* $Id: compat_isblank.c,v 1.3 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.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
+ #include "config.h"
18
+
19
+ int
20
+ isblank(int c)
21
+ {
22
+ return c == ' ' || c == '\t';
23
+ }
@@ -0,0 +1,50 @@
1
+ /* $Id: compat_mkdtemp.c,v 1.4 2021/09/19 15:02:55 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2015, 2021 Ingo Schwarze <schwarze@openbsd.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
+ * The algorithm of this function is inspired by OpenBSD mkdtemp(3)
18
+ * by Theo de Raadt and Todd Miller, but the code differs.
19
+ */
20
+ #include "config.h"
21
+
22
+ #include <sys/stat.h>
23
+ #include <errno.h>
24
+ #include <limits.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+
28
+ char *
29
+ mkdtemp(char *path)
30
+ {
31
+ char *start, *cp;
32
+ unsigned int tries;
33
+
34
+ start = strchr(path, '\0');
35
+ while (start > path && start[-1] == 'X')
36
+ start--;
37
+
38
+ for (tries = INT_MAX; tries; tries--) {
39
+ if (mktemp(path) == NULL)
40
+ return NULL;
41
+ if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0)
42
+ return path;
43
+ for (cp = start; *cp != '\0'; cp++)
44
+ *cp = 'X';
45
+ if (errno != EEXIST)
46
+ return NULL;
47
+ }
48
+ errno = EEXIST;
49
+ return NULL;
50
+ }
@@ -0,0 +1,63 @@
1
+ /* $Id: compat_mkstemps.c,v 1.1 2021/09/19 15:05:39 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2015, 2021 Ingo Schwarze <schwarze@openbsd.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
+ * Parts of the algorithm of this function are inspired by OpenBSD
18
+ * mkdtemp(3) by Theo de Raadt and Todd Miller, but the code differs.
19
+ */
20
+ #include "config.h"
21
+
22
+ #include <sys/stat.h>
23
+ #include <errno.h>
24
+ #include <fcntl.h>
25
+ #include <limits.h>
26
+ #include <stdlib.h>
27
+ #include <string.h>
28
+
29
+ int
30
+ mkstemps(char *path, int suffixlen)
31
+ {
32
+ char *start, *end, *cp;
33
+ int fd, tries;
34
+ char backup;
35
+
36
+ end = strchr(path, '\0');
37
+ if (suffixlen < 0 || suffixlen > end - path - 6) {
38
+ errno = EINVAL;
39
+ return -1;
40
+ }
41
+ end -= suffixlen;
42
+ for (start = end; start > path; start--)
43
+ if (start[-1] != 'X')
44
+ break;
45
+
46
+ backup = *end;
47
+ for (tries = INT_MAX; tries; tries--) {
48
+ *end = '\0';
49
+ cp = mktemp(path);
50
+ *end = backup;
51
+ if (cp == NULL)
52
+ return -1;
53
+ fd = open(path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
54
+ if (fd != -1)
55
+ return fd;
56
+ for (cp = start; cp < end; cp++)
57
+ *cp = 'X';
58
+ if (errno != EEXIST)
59
+ return -1;
60
+ }
61
+ errno = EEXIST;
62
+ return -1;
63
+ }