utime misusage

Gordon A. Moffett gam at amdahl.UUCP
Thu Nov 29 14:31:59 AEST 1984

> = Doug Gwyn
> The following UNIX System V Release 2.0 commands have erroneous use
> of utime(2) in their source code.  On some systems, this can cause
> files to have their dates set to funny values (like 31-Dec-1969).
> 	cpio	file	pack	tar	unpack

The instances you refer to are of the form:

        char *filename;
        struct stat st;
        utime(filename, &st.st_atime);

Despite its rather inelegant appearance, why should this fail?

The second argument of utime(2) is expected to be the address of
this kind of struct:

        struct utimbuf { time_t actime, modtime; } ubuf;

Using the address of the st_atime field of a stat(2) struct would
provide these values correctly, because the word following st_atime in
the structure is st_mtime (the mod. time).  Here's a picture:

 &st.st_atime -----> st_atime      &ubuf -----> actime
                     st_mtime                   modtime

So is this really a bug, or is your C compiler acting strangely?
Gordon A. Moffett		...!{ihnp4,hplabs,amd,sun}!amdahl!gam

37 22'50" N / 122 59'12" W	[ This is just me talking. ]

More information about the Comp.lang.c mailing list