2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 64 bits in a Cray word
22 12345678901234567890123456789012
23 1234567890123456789012345678901234567890123456789012345678901234
24 ________________________________________________________________
25 < pid >< word-offset in file (same #) >< pid >
27 1234567890123456789012345678901234567890123456789012345678901234
28 ________________________________________________________________
29 < pid >< offset in file of this word >< pid >
32 8 bits to a bytes == character
37 #include <sys/param.h>
43 static char Errmsg[80];
45 #define LOWER16BITS(X) (X & 0177777)
46 #define LOWER32BITS(X) (X & 0xffffffff)
49 #define HIGHBITS(WRD, bits) ( (-1 << (64-bits)) & WRD)
50 #define LOWBITS(WRD, bits) ( (-1 >> (64-bits)) & WRD)
53 #define NBPBYTE 8 /* number bits per byte */
59 /***********************************************************************
62 * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 15 bytes
63 * 1234567890123456789012345678901234567890123456789012345678901234 bits
64 * ________________________________________________________________ 1 word
65 * < pid >< offset in file of this word >< pid >
67 * the words are put together where offset zero is the start.
68 * thus, offset 16 is the start of the second full word
69 * Thus, offset 8 is in middle of word 1
70 ***********************************************************************/
72 datapidgen(pid, buffer, bsize, offset)
78 return -1; /* not support on non-64 bits word machines */
83 /***********************************************************************
86 ***********************************************************************/
88 datapidchk(pid, buffer, bsize, offset, errmsg)
95 if ( errmsg != NULL ) {
98 sprintf(Errmsg, "Not supported on this OS.");
101 } /* end of datapidchk */
105 /***********************************************************************
106 * main for doing unit testing
107 ***********************************************************************/
119 if ((buffer=(char *)malloc(size)) == NULL ) {
125 datapidgen(-1, buffer, size, 3);
128 fwrite(buffer, size, 1, stdout);
129 fwrite("\n", 1, 1, stdout);
132 printf("datapidgen(-1, buffer, size, 3)\n");
134 ret=datapidchk(-1, buffer, size, 3, &errmsg);
135 printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n",
137 ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
138 printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
139 size-1, ret, errmsg);
145 printf("changing char 25-28\n");
147 ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
148 printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
149 size-1, ret, errmsg);
151 printf("------------------------------------------\n");
153 datapidgen(getpid(), buffer, size, 5);
156 fwrite(buffer, size, 1, stdout);
157 fwrite("\n", 1, 1, stdout);
160 printf("\ndatapidgen(getpid(), buffer, size, 5)\n");
162 ret=datapidchk(getpid(), buffer, size, 5, &errmsg);
163 printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n",
166 ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
167 printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
168 size-1, ret, errmsg);
171 printf("changing char 25\n");
173 ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
174 printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
175 size-1, ret, errmsg);