whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 3 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 7 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 11 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 18 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 22 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | */ |
| 32 | /************ |
| 33 | |
| 34 | 64 bits in a Cray word |
| 35 | |
| 36 | 12345678901234567890123456789012 |
| 37 | 1234567890123456789012345678901234567890123456789012345678901234 |
| 38 | ________________________________________________________________ |
| 39 | < pid >< word-offset in file (same #) >< pid > |
| 40 | |
| 41 | 1234567890123456789012345678901234567890123456789012345678901234 |
| 42 | ________________________________________________________________ |
| 43 | < pid >< offset in file of this word >< pid > |
| 44 | |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 45 | 8 bits to a bytes == character |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 46 | NBPW 8 |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 47 | ************/ |
| 48 | |
| 49 | #include <stdio.h> |
| 50 | #include <sys/param.h> |
| 51 | #ifdef UNIT_TEST |
| 52 | #include <unistd.h> |
| 53 | #include <stdlib.h> |
| 54 | #endif |
| 55 | |
| 56 | static char Errmsg[80]; |
| 57 | |
| 58 | #define LOWER16BITS(X) (X & 0177777) |
| 59 | #define LOWER32BITS(X) (X & 0xffffffff) |
| 60 | |
| 61 | /*** |
| 62 | #define HIGHBITS(WRD, bits) ( (-1 << (64-bits)) & WRD) |
| 63 | #define LOWBITS(WRD, bits) ( (-1 >> (64-bits)) & WRD) |
| 64 | ****/ |
| 65 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 66 | #define NBPBYTE 8 /* number bits per byte */ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 67 | |
| 68 | #ifndef DEBUG |
| 69 | #define DEBUG 0 |
| 70 | #endif |
| 71 | |
| 72 | /*********************************************************************** |
| 73 | * |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 74 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 75 | * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 15 bytes |
| 76 | * 1234567890123456789012345678901234567890123456789012345678901234 bits |
| 77 | * ________________________________________________________________ 1 word |
| 78 | * < pid >< offset in file of this word >< pid > |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 79 | * |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 80 | * the words are put together where offset zero is the start. |
| 81 | * thus, offset 16 is the start of the second full word |
| 82 | * Thus, offset 8 is in middle of word 1 |
| 83 | ***********************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 84 | int datapidgen(pid, buffer, bsize, offset) |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 85 | int pid; |
| 86 | char *buffer; |
| 87 | int bsize; |
| 88 | int offset; |
| 89 | { |
| 90 | #if CRAY |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 91 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 92 | int cnt; |
| 93 | int tmp; |
| 94 | char *chr; |
| 95 | long *wptr; |
| 96 | long word; |
| 97 | int woff; /* file offset for the word */ |
| 98 | int boff; /* buffer offset or index */ |
| 99 | int num_full_words; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 100 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 101 | num_full_words = bsize / NBPW; |
| 102 | boff = 0; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 103 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 104 | if (cnt = (offset % NBPW)) { /* partial word */ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 105 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 106 | woff = offset - cnt; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 107 | #if DEBUG |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 108 | printf("partial at beginning, cnt = %d, woff = %d\n", cnt, |
| 109 | woff); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 110 | #endif |
| 111 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 112 | word = |
| 113 | ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | |
| 114 | LOWER16BITS(pid)); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 115 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 116 | chr = (char *)&word; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 117 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 118 | for (tmp = 0; tmp < cnt; tmp++) { /* skip unused bytes */ |
| 119 | chr++; |
| 120 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 121 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 122 | for (; boff < (NBPW - cnt) && boff < bsize; boff++, chr++) { |
| 123 | buffer[boff] = *chr; |
| 124 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 125 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 126 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 127 | /* |
| 128 | * full words |
| 129 | */ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 130 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 131 | num_full_words = (bsize - boff) / NBPW; |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 132 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 133 | woff = offset + boff; |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 134 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 135 | for (cnt = 0; cnt < num_full_words; woff += NBPW, cnt++) { |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 136 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 137 | word = |
| 138 | ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | |
| 139 | LOWER16BITS(pid)); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 140 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 141 | chr = (char *)&word; |
| 142 | for (tmp = 0; tmp < NBPW; tmp++, chr++) { |
| 143 | buffer[boff++] = *chr; |
| 144 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 145 | /****** Only if wptr is a word ellined |
| 146 | wptr = (long *)&buffer[boff]; |
| 147 | *wptr = word; |
| 148 | boff += NBPW; |
| 149 | *****/ |
| 150 | |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 151 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 152 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 153 | /* |
| 154 | * partial word at end of buffer |
| 155 | */ |
| 156 | |
| 157 | if (cnt = ((bsize - boff) % NBPW)) { |
| 158 | #if DEBUG |
| 159 | printf("partial at end\n"); |
| 160 | #endif |
| 161 | word = |
| 162 | ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | |
| 163 | LOWER16BITS(pid)); |
| 164 | |
| 165 | chr = (char *)&word; |
| 166 | |
| 167 | for (tmp = 0; tmp < cnt && boff < bsize; tmp++, chr++) { |
| 168 | buffer[boff++] = *chr; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return bsize; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 173 | |
| 174 | #else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 175 | return -1; /* not support on non-64 bits word machines */ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 176 | |
| 177 | #endif |
| 178 | |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 179 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 180 | |
| 181 | /*********************************************************************** |
| 182 | * |
| 183 | * |
| 184 | ***********************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 185 | int datapidchk(pid, buffer, bsize, offset, errmsg) |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 186 | int pid; |
| 187 | char *buffer; |
| 188 | int bsize; |
| 189 | int offset; |
| 190 | char **errmsg; |
| 191 | { |
| 192 | #if CRAY |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 193 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 194 | int cnt; |
| 195 | int tmp; |
| 196 | char *chr; |
| 197 | long *wptr; |
| 198 | long word; |
| 199 | int woff; /* file offset for the word */ |
| 200 | int boff; /* buffer offset or index */ |
| 201 | int num_full_words; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 202 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 203 | if (errmsg != NULL) { |
| 204 | *errmsg = Errmsg; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 205 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 206 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 207 | num_full_words = bsize / NBPW; |
| 208 | boff = 0; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 209 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 210 | if (cnt = (offset % NBPW)) { /* partial word */ |
| 211 | woff = offset - cnt; |
| 212 | word = |
| 213 | ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | |
| 214 | LOWER16BITS(pid)); |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 215 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 216 | chr = (char *)&word; |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 217 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 218 | for (tmp = 0; tmp < cnt; tmp++) { /* skip unused bytes */ |
| 219 | chr++; |
| 220 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 221 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 222 | for (; boff < (NBPW - cnt) && boff < bsize; boff++, chr++) { |
| 223 | if (buffer[boff] != *chr) { |
| 224 | sprintf(Errmsg, |
| 225 | "Data mismatch at offset %d, exp:%#o, act:%#o", |
| 226 | offset + boff, *chr, buffer[boff]); |
| 227 | return offset + boff; |
| 228 | } |
| 229 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 232 | /* |
| 233 | * full words |
| 234 | */ |
| 235 | |
| 236 | num_full_words = (bsize - boff) / NBPW; |
| 237 | |
| 238 | woff = offset + boff; |
| 239 | |
| 240 | for (cnt = 0; cnt < num_full_words; woff += NBPW, cnt++) { |
| 241 | word = |
| 242 | ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | |
| 243 | LOWER16BITS(pid)); |
| 244 | |
| 245 | chr = (char *)&word; |
| 246 | for (tmp = 0; tmp < NBPW; tmp++, boff++, chr++) { |
| 247 | if (buffer[boff] != *chr) { |
| 248 | sprintf(Errmsg, |
| 249 | "Data mismatch at offset %d, exp:%#o, act:%#o", |
| 250 | woff, *chr, buffer[boff]); |
| 251 | return woff; |
| 252 | } |
| 253 | } |
| 254 | |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 255 | /****** only if a word elined |
| 256 | wptr = (long *)&buffer[boff]; |
Garrett Cooper | 903910d | 2010-11-23 09:27:44 -0800 | [diff] [blame] | 257 | if (*wptr != word) { |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 258 | sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o", |
| 259 | woff, word, *wptr); |
| 260 | return woff; |
| 261 | } |
| 262 | boff += NBPW; |
| 263 | ******/ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 264 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 265 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 266 | /* |
| 267 | * partial word at end of buffer |
| 268 | */ |
| 269 | |
| 270 | if (cnt = ((bsize - boff) % NBPW)) { |
| 271 | #if DEBUG |
| 272 | printf("partial at end\n"); |
| 273 | #endif |
| 274 | word = |
| 275 | ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | |
| 276 | LOWER16BITS(pid)); |
| 277 | |
| 278 | chr = (char *)&word; |
| 279 | |
| 280 | for (tmp = 0; tmp < cnt && boff < bsize; boff++, tmp++, chr++) { |
| 281 | if (buffer[boff] != *chr) { |
| 282 | sprintf(Errmsg, |
| 283 | "Data mismatch at offset %d, exp:%#o, act:%#o", |
| 284 | offset + boff, *chr, buffer[boff]); |
| 285 | return offset + boff; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | sprintf(Errmsg, "all %d bytes match desired pattern", bsize); |
| 291 | return -1; /* buffer is ok */ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 292 | |
| 293 | #else |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 294 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 295 | if (errmsg != NULL) { |
| 296 | *errmsg = Errmsg; |
| 297 | } |
| 298 | sprintf(Errmsg, "Not supported on this OS."); |
| 299 | return 0; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 300 | |
| 301 | #endif |
| 302 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 303 | } /* end of datapidchk */ |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 304 | |
| 305 | #if UNIT_TEST |
| 306 | |
| 307 | /*********************************************************************** |
| 308 | * main for doing unit testing |
| 309 | ***********************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 310 | int main(ac, ag) |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 311 | int ac; |
| 312 | char **ag; |
| 313 | { |
| 314 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 315 | int size = 1234; |
| 316 | char *buffer; |
| 317 | int ret; |
| 318 | char *errmsg; |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 319 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 320 | if ((buffer = (char *)malloc(size)) == NULL) { |
| 321 | perror("malloc"); |
| 322 | exit(2); |
| 323 | } |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 324 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 325 | datapidgen(-1, buffer, size, 3); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 326 | |
| 327 | /*** |
| 328 | fwrite(buffer, size, 1, stdout); |
| 329 | fwrite("\n", 1, 1, stdout); |
| 330 | ****/ |
| 331 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 332 | printf("datapidgen(-1, buffer, size, 3)\n"); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 333 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 334 | ret = datapidchk(-1, buffer, size, 3, &errmsg); |
| 335 | printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n", |
| 336 | size, ret, errmsg); |
| 337 | ret = datapidchk(-1, &buffer[1], size - 1, 4, &errmsg); |
| 338 | printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n", |
| 339 | size - 1, ret, errmsg); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 340 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 341 | buffer[25] = 0x0; |
| 342 | buffer[26] = 0x0; |
| 343 | buffer[27] = 0x0; |
| 344 | buffer[28] = 0x0; |
| 345 | printf("changing char 25-28\n"); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 346 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 347 | ret = datapidchk(-1, &buffer[1], size - 1, 4, &errmsg); |
| 348 | printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n", |
| 349 | size - 1, ret, errmsg); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 350 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 351 | printf("------------------------------------------\n"); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 352 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 353 | datapidgen(getpid(), buffer, size, 5); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 354 | |
| 355 | /******* |
| 356 | fwrite(buffer, size, 1, stdout); |
| 357 | fwrite("\n", 1, 1, stdout); |
| 358 | ******/ |
| 359 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 360 | printf("\ndatapidgen(getpid(), buffer, size, 5)\n"); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 361 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 362 | ret = datapidchk(getpid(), buffer, size, 5, &errmsg); |
| 363 | printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n", |
| 364 | size, ret, errmsg); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 365 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 366 | ret = datapidchk(getpid(), &buffer[1], size - 1, 6, &errmsg); |
| 367 | printf |
| 368 | ("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n", |
| 369 | size - 1, ret, errmsg); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 370 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 371 | buffer[25] = 0x0; |
| 372 | printf("changing char 25\n"); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 373 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 374 | ret = datapidchk(getpid(), &buffer[1], size - 1, 6, &errmsg); |
| 375 | printf |
| 376 | ("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n", |
| 377 | size - 1, ret, errmsg); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 378 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 379 | exit(0); |
whr | b973f2b | 2000-05-05 19:34:50 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | #endif |