Node and Host Name Sizes on HP-UX: Using the Expanded Capabilities of HP-UX

33
time_t hdr_lastmodifytime;
#ifdef NEWVERS
time_t hdr_lastaccesstime;
#endif
}
This single source file can be compiled into two object files by using the following commands:
cc c fetch_hdr.c; mv fetch_hdr.o fetch_hdr_orig.o
cc DNEWVERS c fetch_hdr.c; mv fetch_hdr.o fetch_hdr_new.o
The result is that fetch_hdr_orig.o exports fetch_hdr(), and fetch_hdr_new.o exports
fetch_hdr{rev2}(). Both object files and their functions can be combined into a common library
so that clients built for either interface version can link properly.
Original Interface as Thin Converter
The parallel implementation approach is not always practical. It might not be reasonable to factor the
accesses to the structure into a small routine. An alternative approach is to build one interface as a
thin conversion wrapper around the other. This takes a bit of tricky typecasting. Consider the
following source code (using the same std_hdr.h header file as in the preceding example):
fetch_hdr_orig.c:
/* Thin wrapper to provide nonexpanded version of fetch_hdr() */
/* compile without DNEWVERS, so binary name is fetch_hdr() */
#include “std_hdr.h”
int fetch_hdr(struct std_hdr *hdrp) {
struct std_hdr_orig; /* incomplete definition */
extern int fetch_hdr_translate(struct std_hdr_orig *);
return( fetch_hdr_translate( (struct std_hdr_orig *)hdrp ) );
}
fetch_hdr_translate.c:
/* Translate expanded std_hdr structure to nonexpanded format */
#define NEWVERS
#include “std_hdr.h”
/* define std_hdr_orig as original layout */
struct std_hdr_orig {
int ohdr_identifier;
size_t ohdr_data_size;
time_t ohdr_creationtime;
time_t ohdr_lastmodifytime;
}
int fetch_hdr_translate(struct std_hdr_orig *ohdrp) {
struct std_hdr nhdr; /* local buffer for new header */
retval = fetch_hdr(&nhdr); /* calls new version of function */
/* copy fields to original layout */
ohdrp->ohdr_identifier = nhdr->hdr_identifier;
ohdrp->ohdr_data_size = nhdr->hdr_data_size;
ohdrp->ohdr_creationtime = nhdr->hdr_creationtime;
ohdrp->ohdr_lastmodifytime = nhdr->hdr_lastmodifytime;
return(retval);
}
Here, the bulk of the underlying work is done using the enhanced data-structure version. It is
converted to the original format just before returning it to the client.