Inizio trattazione statx
[gapil.git] / sources / InitFile.c
index 307442a7cc2bcab2c9f7e78498a40217ffc7fd0c..a1e3e46feb07d48edfb369e24b70f0e64a638e53 100644 (file)
@@ -37,9 +37,9 @@
 #include "Gapil.h"
 #include "macros.h"
 
 #include "Gapil.h"
 #include "macros.h"
 
-ssize_t InitFile(int dirfd, const char *file, const char *buf, size_t count
+ssize_t InitFile(int dirfd, const char *file, const char *buf, size_t size
 {
 {
-    int fd, res;
+    int fd, written, res;
     char path[PATH_MAX];
    
     fd = openat(dirfd, ".", O_TMPFILE|O_RDWR, S_IRUSR|S_IWUSR);
     char path[PATH_MAX];
    
     fd = openat(dirfd, ".", O_TMPFILE|O_RDWR, S_IRUSR|S_IWUSR);
@@ -47,18 +47,18 @@ ssize_t InitFile(int dirfd, const char *file, const char *buf, size_t count)
        perror("Cannot get temporary filedescritor");
        return(fd);
     }
        perror("Cannot get temporary filedescritor");
        return(fd);
     }
-    res = FullWrite(fd, buf, count);
-    if (res < 0) {
+    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 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 writing on tmp file");
+       perror("error linking the file");
        return(res);
     } else {
        return(res);
     } else {
-       return 0;
+       return written;
     }
 }
 
     }
 }