+The following sample demonstrates the need to use packing and alignment
+controls; without the attribute, in 64-bit code, the fields of the structure are not
+placed at the locations that the kernel expects.
+.
+.Bd -literal
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <err.h>
+#include <time.h>
+#include <sys/attr.h>
+.Pp
+/* The alignment and packing attribute is necessary in 64-bit code */
+struct AttrListTimes {
+ u_int32_t length;
+ struct timespec st_crtime;
+ struct timespec st_modtime;
+} __attribute__((aligned(4), packed));
+.Pp
+main(int argc, char **argv)
+{
+ int rv;
+ int i;
+.Pp
+ for (i = 1; i < argc; i++) {
+ struct attrlist attrList;
+ struct AttrListTimes myStat = {0};
+ char *path = argv[i];
+.Pp
+ memset(&attrList, 0, sizeof(attrList));
+ attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
+ attrList.commonattr = ATTR_CMN_CRTIME |
+ ATTR_CMN_MODTIME;
+.Pp
+ rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
+.Pp
+ if (rv == -1) {
+ warn("getattrlist(%s)", path);
+ continue;
+ }
+ printf("%s: Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
+ }
+ return 0;
+}
+.Ed
+.Pp