--- /dev/null
+ssize_t InitFile(int dirfd, const char *file, const char *buf, size_t size)
+{
+ int fd, written, res;
+ char path[PATH_MAX];
+
+ fd = openat(dirfd, ".", O_TMPFILE|O_RDWR, S_IRUSR|S_IWUSR);
+ if (fd < 0) {
+ perror("Cannot get temporary filedescritor");
+ return(fd);
+ }
+ written = FullWrite(fd, buf, size);
+ if (written < 0) {
+ perror("error writing on tmp file");
+ return(res);
+ }
+ snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd);
+ res = linkat(AT_FDCWD, path, dirfd, file, AT_SYMLINK_FOLLOW);
+ if (res < 0) {
+ perror("error linking the file");
+ return(res);
+ } else {
+ return written;
+ }
+}