futime / utime

Is there any very good reason why the futime() function is used instead of
the (POSIX) utime() function?

As noted, futime() isn't supported on all platforms.  I wrote my own
futime() for my personal DJGPP port, but after thinking about it, I found
it was trivial to change one line in tidy.c and use utime() instead.  As
far as I can see, it works as desired.  The main problem would be if the
program reads from stdin, but then haveFileTimes should be false anyway.

As utime() (or _utime()) probably is more widely supported than futime(),
why not change the call in the codebase?  That is, again, unless there are
any good reasons to use futime() instead.

(On DJGPP, you also need to add a redirection header so that <sys/utime.h>
actually includes <utime.h>, but that's not an issue for this list.)

* * *

Patch -- note two changes:
 1. change futime() call to utime()
 2. move fclose() call to happen before utime() call

tidy.c is the file from the 30 Apr 2000 distribution.

*** tidy.c	Wed Mar 29 09:17:38 2000
--- changed/tidy.c	Thu May 18 11:30:40 2000
***************
*** 1089,1100 ****
  
                      PFlushLine(&out, 0);
  
  #if PRESERVEFILETIMES
                      /* set file last accessed/modified times to original
values */
                      if (haveFileTimes)
!                         futime(fileno(fp), &filetimes);
  #endif
-                     fclose(fp);
                  }
                  else
                  {
--- 1089,1100 ----
  
                      PFlushLine(&out, 0);
  
+                     fclose(fp);
  #if PRESERVEFILETIMES
                      /* set file last accessed/modified times to original
values */
                      if (haveFileTimes)
!                         utime(file, &filetimes);
  #endif
                  }
                  else
                  {

Received on Thursday, 18 May 2000 06:51:08 UTC