utime (was: abs(), utimes())

Karl Heuer karl at haddock.ISC.COM
Mon Apr 11 08:47:17 AEST 1988


In article <10195 at tut.cis.ohio-state.edu> lvc at tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes:
[the utime() system call expects as an argument a pointer to a structure whose
contents are never declared in any header file]

More precisely, depending on the system utime() expects a pointer to (a) the
first of two time_t objects in an array, or (b) a struct containing two time_t
objects, as declared in some header file like <sys/utime.h>; or (c) such a
struct, which is never declared anywhere; or (d) the first of two timeval
structures in an array.  Note that (a)-(c) happen to be binary compatible on
most systems, and (d) actually uses the name "utimes" rather than "utime", to
avoid the incompatibility.

I eventually got fed up with this, and wrote the following header "utime.h",
which I now use exclusively.  I hereby place it in the Public Domain.  (Note:
I don't use interface (d) because for consistency I need to use a time_t, not
a timeval.  I left the definitions in, anyway.)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
---- cut here ----
/*
 * A consistent interface to different flavors of utime().
 * utime_t is an array type suitable for passing to utime();
 * utm_atime() and utm_mtime() are lmacros to access the fields.
 */
#if !defined(_H_UTIME)
#define _H_UTIME

#if defined(MSDOS)      /* and others, no doubt? */
#include <sys/utime.h>
typedef struct utimbuf  utime_t[1];
#define utm_atime(u)    ((u)[0].actime)
#define utm_mtime(u)    ((u)[0].modtime)
#else
#if defined(USG)
typedef struct { time_t _utm_a, _utm_m; }       utime_t[1];
#define utm_atime(u)    ((u)[0]._utm_a)
#define utm_mtime(u)    ((u)[0]._utm_m)
#else
#if 1           /* Current BSD & Research implementation */
typedef time_t          utime_t[2];
#define utm_atime(u)    ((u)[0])
#define utm_mtime(u)    ((u)[1])
#else           /* Possible future BSD implementation */
typedef struct timeval  utime_t[2];
#define utm_atime(u)    ((u)[0])
#define utm_mtime(u)    ((u)[1])
#define utime           utimes
#endif
#endif
#endif
#endif



More information about the Comp.lang.c mailing list