Using "utime" properly (so it works on 4.2BSD)

Guy Harris guy at rlgvax.UUCP
Wed Jan 11 05:34:12 AEST 1984


The manual page for the "utime" system call says that the second argument,
which gives the times to set the accessed and modified times to, is either
an array of two times or a structure containing two times (depending on
whether you're reading the V7/4.xBSD manual or the S3/S5 manual).  Several
programs ("pack", "unpack", and "cpio" among them) assume that the accessed
and modified times in the structure filled in by the "stat" system call are
contiguous in memory, and therefore that one may pass the address of the
accessed time as the second argument to the "utime" call.

Well, this works on V7, 4.1BSD, S3, and S5.

But it does *not* work on 4.2BSD!

The "stat" structure changed in 4.2BSD, so they are no longer contiguous.
The "long" following the accessed time is reserved for the microseconds part
of the accessed time, and is currently set to zero, so "utime" will set
the modified time to zero.

When using "utime", don't assume that the "stat" structure looks like what
it does on your machine, or what the V7/4.1BSD manual says it does.  Note
that the S3/S5 manual does not say what the structure looks like; it merely
says that the structure includes certain fields with certain types, and
doesn't even commit to those being the only fields.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.unix mailing list