csv plugin: Fixed the initialization of `struct flock' to be portable.
authorFlorian Forster <octo@crystal.wlan.home.verplant.org>
Mon, 22 Jan 2007 21:52:14 +0000 (22:52 +0100)
committerFlorian Forster <octo@crystal.wlan.home.verplant.org>
Mon, 22 Jan 2007 21:52:14 +0000 (22:52 +0100)
It didn't work on Mac OS X for example.

src/csv.c

index b22f176..dd33ca5 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
@@ -144,7 +144,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl)
        char         values[512];
        FILE        *csv;
        int          csv_fd;
-       struct flock fl = { F_WRLCK, SEEK_SET, 0, 0, getpid () };
+       struct flock fl;
        int          status;
 
        if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0)
@@ -183,6 +183,13 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl)
        }
        csv_fd = fileno (csv);
 
+       memset (&fl, '\0', sizeof (fl));
+       fl.l_start  = 0;
+       fl.l_len    = 0; /* till end of file */
+       fl.l_pid    = getpid ();
+       fl.l_type   = F_WRLCK;
+       fl.l_whence = SEEK_SET;
+
        status = fcntl (csv_fd, F_SETLK, &fl);
        if (status != 0)
        {