diff options
author | Robb Matzke <matzke@llnl.gov> | 1998-07-29 16:43:59 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1998-07-29 16:43:59 (GMT) |
commit | a34534c9b8321f4de9fadd836be926497f7461d4 (patch) | |
tree | 5c00d4cb7693ceed4b5e4d84f699953c7ccab048 /src/H5Omtime.c | |
parent | 14ea12a6baba9dfb4d63ce8579242a375d78c6a4 (diff) | |
download | hdf5-a34534c9b8321f4de9fadd836be926497f7461d4.zip hdf5-a34534c9b8321f4de9fadd836be926497f7461d4.tar.gz hdf5-a34534c9b8321f4de9fadd836be926497f7461d4.tar.bz2 |
[svn-r546] Changes since 19980724
----------------------
./MANIFEST
./doc/html/H5.format.html
./src/H5O.c
./src/H5Oprivate.h
./src/H5Omtime.c [NEW]
./src/H5private.h
./src/Makefile.in
Added the modification time message. If an object header has
this message then it's value is updated with the current time
whenever anything changes in the object header.
./acconfig.h
./configure.in
Alas, there seems to be no standard way to convert a string
time like 19980727122800 in UTC to a time_t since mktime()
only converts local times to time_t. So I've modified the
configuration to check for various ways of getting the time
zone information:
* Added checks for the `tm_gmtoff' field of `struct tm'.
* Added a check for the `timezone' global variable.
* Added a check for `struct timezone'.
* Added a check for BSDgettimeofday().
* Added a check for gettimeofday() although it doesn't
actually set the timezone argument on some systems.
* Added a check to see if `tm_zone' is a member of `struct tm'.
* Added a check to see if `tzname' is a global variable.
* Added a check to see if `struct tm' is defined in time.h
or sys/time.h.
It's not difficult to get the right UTC modification message
into the object header, but some systems might have problems
getting the right time back out (Irix64 is one) and those
systems will report zero for the H5G_stat_t.mtime from an
H5Gstat() call as if the mtime message isn't even present. It
will, however, continue to be updated as normal.
./src/H5G.c
./src/H5Gpublic.h
The H5G_stat_t struct now contains an `mtime' field which will
hold the object modification time. If the object has no
object modification time then the `mtime' will be initialized
to zero.
Fixed a bug in H5G_stat() that caused the `objno' field of the
H5G_stat_t to be set incorrectly on some machines.
./src/H5D.c
Writing to external datasets fail if the hdf5 file is not open
for writing.
A modification time message is added to the dataset object
header when it's created and H5O_touch() is called from
H5D_write() to update that message.
./src/H5T.c
Fixed a bug in H5Tget_member_dims() that caused a segmentation
fault if one of the output array arguments was the null
pointer.
Relaxed the member dimension checking in H5Tinsert_array() so
it can also be used for scalar members.
./test/Makefile.in
Added additional file names to the `mostlyclean' target.
./tools/h5dump.c
./tools/h5tools.h
Increased the temporary buffer size to 1MB.
Added support for printing compound data types with array
members.
When printing H5T_NATIVE_CHAR and H5T_NATIVE_UCHAR we escape
double quote characters.
./tools/h5ls.c
Changed the output format a little because we were starting to
get too much info to fit on a line. Without `--verbose' each
object occupies one line of output. Otherwise, additional
information is printed below the object name: object file
address, comment, and modification time. If `--dump' is given
then the data is printed after the other information.
./test/cmpd_dset.c
Changed the way the dataset is initialized to be more uniform.
Diffstat (limited to 'src/H5Omtime.c')
-rw-r--r-- | src/H5Omtime.c | 316 |
1 files changed, 316 insertions, 0 deletions
diff --git a/src/H5Omtime.c b/src/H5Omtime.c new file mode 100644 index 0000000..ae85abb --- /dev/null +++ b/src/H5Omtime.c @@ -0,0 +1,316 @@ +/* + * Copyright © 1998 NCSA + * All rights reserved. + * + * Programmer: Robb Matzke <matzke@llnl.gov> + * Friday, July 24, 1998 + * + * Purpose: The object modification time message. + */ +#include <H5private.h> +#include <H5Eprivate.h> +#include <H5MMprivate.h> +#include <H5Oprivate.h> + +#define PABLO_MASK H5O_mtime_mask + +static void *H5O_mtime_decode(H5F_t *f, const uint8 *p, H5O_shared_t *sh); +static herr_t H5O_mtime_encode(H5F_t *f, uint8 *p, const void *_mesg); +static void *H5O_mtime_copy(const void *_mesg, void *_dest); +static size_t H5O_mtime_size(H5F_t *f, const void *_mesg); +static herr_t H5O_mtime_debug(H5F_t *f, const void *_mesg, FILE * stream, + intn indent, intn fwidth); + +/* This message derives from H5O */ +const H5O_class_t H5O_MTIME[1] = {{ + H5O_MTIME_ID, /*message id number */ + "mtime", /*message name for debugging */ + sizeof(time_t), /*native message size */ + H5O_mtime_decode, /*decode message */ + H5O_mtime_encode, /*encode message */ + H5O_mtime_copy, /*copy the native value */ + H5O_mtime_size, /*raw message size */ + NULL, /*free internal memory */ + NULL, /*get share method */ + NULL, /*set share method */ + H5O_mtime_debug, /*debug the message */ +}}; + +/* Interface initialization */ +static hbool_t interface_initialize_g = FALSE; +#define INTERFACE_INIT NULL + + +/*------------------------------------------------------------------------- + * Function: H5O_mtime_decode + * + * Purpose: Decode a modification time message and return a pointer to a + * new time_t value. + * + * Return: Success: Ptr to new message in native struct. + * + * Failure: NULL + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 24 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void * +H5O_mtime_decode(H5F_t __unused__ *f, const uint8 *p, + H5O_shared_t __unused__ *sh) +{ + time_t *mesg, the_time; + intn i; + struct tm tm; + static int ncalls=0; + + FUNC_ENTER(H5O_mtime_decode, NULL); + + /* check args */ + assert(f); + assert(p); + assert (!sh); + + /* Initialize time zone information */ + if (0==ncalls++) tzset(); + + /* decode */ + for (i=0; i<14; i++) { + if (!isdigit(p[i])) { + HRETURN_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, + "badly formatted modification time message"); + } + } + + /* + * Convert YYYYMMDDhhmmss UTC to a time_t. This is a little problematic + * because mktime() operates on local times. We convert to local time + * and then figure out the adjustment based on the local time zone and + * daylight savings setting. + */ + memset(&tm, 0, sizeof tm); + tm.tm_year = (p[0]-'0')*1000 + (p[1]-'0')*100 + + (p[2]-'0')*10 + (p[3]-'0') - 1900; + tm.tm_mon = (p[4]-'0')*10 + (p[5]-'0') - 1; + tm.tm_mday = (p[6]-'0')*10 + (p[7]-'0'); + tm.tm_hour = (p[8]-'0')*10 + (p[9]-'0'); + tm.tm_min = (p[10]-'0')*10 + (p[11]-'0'); + tm.tm_sec = (p[12]-'0')*10 + (p[13]-'0'); + tm.tm_isdst = -1; /*figure it out*/ + if ((time_t)-1==(the_time=mktime(&tm))) { + HRETURN_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, + "badly formatted modification time message"); + } + +#if defined(HAVE_TM_GMTOFF) + /* FreeBSD, OSF 4.0 */ + the_time += tm.tm_gmtoff; +#elif defined(HAVE_TIMEZONE) + /* Linux */ + the_time -= timezone - (tm.tm_isdst?3600:0); +#elif defined(HAVE_BSDGETTIMEOFDAY) && defined(HAVE_STRUCT_TIMEZONE) + /* Irix5.3 */ + { + struct timezone tz; + if (BSDgettimeofday(NULL, &tz)<0) { + HRETURN_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, + "unable to obtain local timezone information"); + } + the_time -= tz.tz_minuteswest*60 - (tm.tm_idst?3600:0); + } +#elif defined(HAVE_GETTIMEOFDAY) && defined(HAVE_STRUCT_TIMEZONE) + { + struct timezone tz; + if (gettimeofday(NULL, &tz)<0) { + HRETURN_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, + "unable to obtain local timezone information"); + } + the_time -= tz.tz_minuteswest*60 - (tm.tm_isdst?3600:0); + } +#else + /* + * The catch-all. If we can't convert a character string universal + * coordinated time to a time_t value reliably then we can't decode the + * modification time message. This really isn't as bad as it sounds -- + * the only way a user can get the modification time is from H5Gstat() + * and H5G_stat() can gracefully recover. + */ + + /* Irix64 */ + HRETURN_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, + "unable to obtain local timezone information"); +#endif + + /* The return value */ + if (NULL==(mesg = H5MM_calloc(sizeof(time_t)))) { + HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, + "memory allocation failed"); + } + *mesg = the_time; + + FUNC_LEAVE((void*)mesg); +} + + +/*------------------------------------------------------------------------- + * Function: H5O_mtime_encode + * + * Purpose: Encodes a modification time message. + * + * Return: Success: SUCCEED + * + * Failure: FAIL + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 24 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_mtime_encode(H5F_t __unused__ *f, uint8 *p, const void *_mesg) +{ + const time_t *mesg = (const time_t *) _mesg; + struct tm *tm; + + + FUNC_ENTER(H5O_mtime_encode, FAIL); + + /* check args */ + assert(f); + assert(p); + assert(mesg); + + /* encode */ + tm = gmtime(mesg); + sprintf(p, "%04d%02d%02d%02d%02d%02d", + 1900+tm->tm_year, 1+tm->tm_mon, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + + FUNC_LEAVE(SUCCEED); +} + + +/*------------------------------------------------------------------------- + * Function: H5O_mtime_copy + * + * Purpose: Copies a message from _MESG to _DEST, allocating _DEST if + * necessary. + * + * Return: Success: Ptr to _DEST + * + * Failure: NULL + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 24 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void * +H5O_mtime_copy(const void *_mesg, void *_dest) +{ + const time_t *mesg = (const time_t *) _mesg; + time_t *dest = (time_t *) _dest; + + FUNC_ENTER(H5O_mtime_copy, NULL); + + /* check args */ + assert(mesg); + if (!dest && NULL==(dest = H5MM_calloc(sizeof(time_t)))) { + HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, + "memory allocation failed"); + } + + /* copy */ + *dest = *mesg; + + FUNC_LEAVE((void *) dest); +} + +/*------------------------------------------------------------------------- + * Function: H5O_mtime_size + * + * Purpose: Returns the size of the raw message in bytes not + * counting the message type or size fields, but only the data + * fields. This function doesn't take into account + * alignment. + * + * Return: Success: Message data size in bytes w/o alignment. + * + * Failure: FAIL + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 14 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static size_t +H5O_mtime_size(H5F_t __unused__ *f, const void __unused__ *mesg) +{ + FUNC_ENTER(H5O_mtime_size, 0); + + /* check args */ + assert(f); + assert(mesg); + + FUNC_LEAVE(16); +} + + +/*------------------------------------------------------------------------- + * Function: H5O_mtime_debug + * + * Purpose: Prints debugging info for the message. + * + * Return: Success: SUCCEED + * + * Failure: FAIL + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 24 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +H5O_mtime_debug(H5F_t __unused__ *f, const void *_mesg, FILE *stream, + intn indent, intn fwidth) +{ + const time_t *mesg = (const time_t *)_mesg; + struct tm *tm; + char buf[128]; + + FUNC_ENTER(H5O_mtime_debug, FAIL); + + /* check args */ + assert(f); + assert(mesg); + assert(stream); + assert(indent >= 0); + assert(fwidth >= 0); + + /* debug */ + tm = localtime(mesg); + + + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", tm); + fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + "Time:", buf); + + FUNC_LEAVE(SUCCEED); +} + |