--- ray/src/common/header.c 2020/07/25 01:10:38 2.40 +++ ray/src/common/header.c 2022/03/03 15:43:04 2.42 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: header.c,v 2.40 2020/07/25 01:10:38 greg Exp $"; +static const char RCSid[] = "$Id: header.c,v 2.42 2022/03/03 15:43:04 greg Exp $"; #endif /* * header.c - routines for reading and writing information headers. @@ -57,7 +57,7 @@ newheader( /* identifying line of information header { fputs(HDRSTR, fp); fputs(s, fp); - putc('\n', fp); + fputc('\n', fp); } @@ -209,9 +209,29 @@ fputformat( /* put out a format value */ FILE *fp ) { + int align = 0; + fputs(FMTSTR, fp); fputs(s, fp); - putc('\n', fp); + /* pad to align binary type for mmap() */ + if (!strncmp(s, "16-bit", 6)) + align = 2; + else if (!strcmp(s, "float") || !strncmp(s, "32-bit", 6)) + align = 4; + else if (!strcmp(s, "double") || !strncmp(s, "64-bit", 6)) + align = 8; + if (align) { + long pos = ftell(fp); + if (pos >= 0) { + pos = (pos + 2) % align; + if (pos) align -= pos; + else align = 0; + } else + align = 0; + } + while (align-- > 0) + putc(' ', fp); + fputc('\n', fp); }