+ memset (&statbuf, 0, sizeof (statbuf));
+ status = stat (CACHE_FILE, &statbuf);
+ if (status == 0)
+ {
+ if (statbuf.st_mtime >= gl_last_update)
+ {
+ fprintf (stderr, "gl_update_cache: Not writing to cache because it's "
+ "at least as new as our internal data\n");
+ return (0);
+ }
+ }
+ else
+ {
+ status = errno;
+ fprintf (stderr, "gl_update_cache: stat(2) failed with status %i\n",
+ status);
+ /* Continue writing the file if possible. */
+ }
+
+ fd = open (CACHE_FILE, O_WRONLY | O_TRUNC | O_CREAT,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+ if (fd < 0)
+ {
+ status = errno;
+ fprintf (stderr, "gl_update_cache: open(2) failed with status %i\n",
+ status);
+ return (status);
+ }
+
+ memset (&lock, 0, sizeof (lock));
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 0; /* lock everything */
+
+ while (42)
+ {
+ status = fcntl (fd, F_SETLKW, &lock);
+ if (status == 0)
+ break;
+
+ if (errno == EINTR)
+ continue;
+
+ fprintf (stderr, "gl_update_cache: fcntl(2) failed with status %i\n", errno);
+ close (fd);