summaryrefslogtreecommitdiff
path: root/src/libposixplz/mkfiletemp.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-12-08 15:10:09 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-12-08 15:10:09 +0000
commit30d0c173d87b92a9ad2f3c1b643463a894abb1d9 (patch)
tree544c0917404a5ee3bf1c5f4faceeb51cff084b8d /src/libposixplz/mkfiletemp.c
parent2f017fbdd689e025437783cc8d675a7d304b37c3 (diff)
downloadskalibs-30d0c173d87b92a9ad2f3c1b643463a894abb1d9.tar.xz
Really add mkfootemp and autosurf, I guess ?
Diffstat (limited to 'src/libposixplz/mkfiletemp.c')
-rw-r--r--src/libposixplz/mkfiletemp.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libposixplz/mkfiletemp.c b/src/libposixplz/mkfiletemp.c
new file mode 100644
index 0000000..4eaf151
--- /dev/null
+++ b/src/libposixplz/mkfiletemp.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+
+#include <skalibs/surf.h>
+#include <skalibs/posixplz.h>
+
+int mkfiletemp (char *s, createfunc_t_ref f, mode_t mode, void *data)
+{
+ size_t len = strlen(s) ;
+ size_t xlen = 0 ;
+ int r ;
+ for (; xlen < len ; xlen++) if (s[len - 1 - xlen] != 'X') break ;
+ if (xlen < 6) return (errno = EINVAL, -1) ;
+ do
+ {
+ autosurf_name(s + len - xlen, xlen) ;
+ r = (*f)(s, mode, data) ;
+ } while (r == -1 && errno == EEXIST) ;
+ return r ;
+}