@@ -92,6 +92,102 @@ struct tempfile {
92
92
*/
93
93
extern int create_tempfile (struct tempfile * tempfile , const char * path );
94
94
95
+
96
+ /*
97
+ * mks_tempfile functions
98
+ *
99
+ * The following functions attempt to create and open temporary files
100
+ * with names derived automatically from a template, in the manner of
101
+ * mkstemps(), and arrange for them to be deleted if the program ends
102
+ * before they are deleted explicitly. There is a whole family of such
103
+ * functions, named according to the following pattern:
104
+ *
105
+ * x?mks_tempfile_t?s?m?()
106
+ *
107
+ * The optional letters have the following meanings:
108
+ *
109
+ * x - die if the temporary file cannot be created.
110
+ *
111
+ * t - create the temporary file under $TMPDIR (as opposed to
112
+ * relative to the current directory). When these variants are
113
+ * used, template should be the pattern for the filename alone,
114
+ * without a path.
115
+ *
116
+ * s - template includes a suffix that is suffixlen characters long.
117
+ *
118
+ * m - the temporary file should be created with the specified mode
119
+ * (otherwise, the mode is set to 0600).
120
+ *
121
+ * None of these functions modify template. If the caller wants to
122
+ * know the (absolute) path of the file that was created, it can be
123
+ * read from tempfile->filename.
124
+ *
125
+ * On success, the functions return a file descriptor that is open for
126
+ * writing the temporary file. On errors, they return -1 and set errno
127
+ * appropriately (except for the "x" variants, which die() on errors).
128
+ */
129
+
130
+ /* See "mks_tempfile functions" above. */
131
+ extern int mks_tempfile_sm (struct tempfile * tempfile ,
132
+ const char * template , int suffixlen , int mode );
133
+
134
+ /* See "mks_tempfile functions" above. */
135
+ static inline int mks_tempfile_s (struct tempfile * tempfile ,
136
+ const char * template , int suffixlen )
137
+ {
138
+ return mks_tempfile_sm (tempfile , template , suffixlen , 0600 );
139
+ }
140
+
141
+ /* See "mks_tempfile functions" above. */
142
+ static inline int mks_tempfile_m (struct tempfile * tempfile ,
143
+ const char * template , int mode )
144
+ {
145
+ return mks_tempfile_sm (tempfile , template , 0 , mode );
146
+ }
147
+
148
+ /* See "mks_tempfile functions" above. */
149
+ static inline int mks_tempfile (struct tempfile * tempfile ,
150
+ const char * template )
151
+ {
152
+ return mks_tempfile_sm (tempfile , template , 0 , 0600 );
153
+ }
154
+
155
+ /* See "mks_tempfile functions" above. */
156
+ extern int mks_tempfile_tsm (struct tempfile * tempfile ,
157
+ const char * template , int suffixlen , int mode );
158
+
159
+ /* See "mks_tempfile functions" above. */
160
+ static inline int mks_tempfile_ts (struct tempfile * tempfile ,
161
+ const char * template , int suffixlen )
162
+ {
163
+ return mks_tempfile_tsm (tempfile , template , suffixlen , 0600 );
164
+ }
165
+
166
+ /* See "mks_tempfile functions" above. */
167
+ static inline int mks_tempfile_tm (struct tempfile * tempfile ,
168
+ const char * template , int mode )
169
+ {
170
+ return mks_tempfile_tsm (tempfile , template , 0 , mode );
171
+ }
172
+
173
+ /* See "mks_tempfile functions" above. */
174
+ static inline int mks_tempfile_t (struct tempfile * tempfile ,
175
+ const char * template )
176
+ {
177
+ return mks_tempfile_tsm (tempfile , template , 0 , 0600 );
178
+ }
179
+
180
+ /* See "mks_tempfile functions" above. */
181
+ extern int xmks_tempfile_m (struct tempfile * tempfile ,
182
+ const char * template , int mode );
183
+
184
+ /* See "mks_tempfile functions" above. */
185
+ static inline int xmks_tempfile (struct tempfile * tempfile ,
186
+ const char * template )
187
+ {
188
+ return xmks_tempfile_m (tempfile , template , 0600 );
189
+ }
190
+
95
191
/*
96
192
* Associate a stdio stream with the temporary file (which must still
97
193
* be open). Return `NULL` (*without* deleting the file) on error. The
0 commit comments