X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2FInitFile.c;fp=listati%2FInitFile.c;h=e7d010ac0ae101ab399428d03c7018f752117576;hp=0000000000000000000000000000000000000000;hb=844ea3e96c657de0e887fd3ebce90d1dff7103ad;hpb=4be39dd3718d708ccff65b01a8f634e05b56f3c9 diff --git a/listati/InitFile.c b/listati/InitFile.c new file mode 100644 index 0000000..e7d010a --- /dev/null +++ b/listati/InitFile.c @@ -0,0 +1,24 @@ +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; + } +}