1 /* 2 * 3 * Copyright (c) International Business Machines Corp., 2002 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 01/02/2003 Port to LTP avenkat (at) us.ibm.com */ 21 /* 06/30/2001 Port to Linux nsharoff (at) us.ibm.com */ 22 23 /* 24 * NAME 25 * memset1.c -- test setting of buffer 26 * 27 * CALLS 28 * memset(3) 29 * 30 * ALGORITHM 31 * Check boundary conditions, go through 64 byte window. 32 * 33 * RESTRICTIONS 34 */ 35 36 #include <stdio.h> 37 #include <string.h> 38 #include <unistd.h> 39 #include <stdlib.h> 40 #include <errno.h> 41 42 #include "test.h" 43 44 char *TCID = "memset01"; 45 46 #undef BSIZE 47 #define BSIZE 4096 48 #define LEN 100 49 #define FAILED 0 50 #define PASSED 1 51 52 char buf[BSIZE]; 53 54 int local_flag = PASSED; 55 int block_number; 56 int TST_TOTAL = 1; 57 58 void fill(void); 59 int checkit(char *str); 60 61 int main(int argc, char *argv[]) 62 { 63 register int i, j; 64 char *p; 65 66 tst_parse_opts(argc, argv, NULL, NULL); 67 68 local_flag = PASSED; 69 70 fill(); 71 72 for (i = 0; i < 200; i++) { 73 fill(); 74 p = &buf[400]; 75 memset(p, 0, i); 76 if ((j = checkit(p)) != i) { 77 tst_resm(TINFO, 78 "Not enough zero bytes, wanted %d, got %d", i, 79 j); 80 local_flag = FAILED; 81 break; 82 } 83 if (!p[-1] || !p[i]) { 84 tst_resm(TINFO, "Boundary error, clear of %d", i); 85 local_flag = FAILED; 86 } 87 if (local_flag == FAILED) 88 break; 89 } 90 91 (local_flag == FAILED) ? tst_resm(TFAIL, 92 "Test failed") : tst_resm(TPASS, 93 "Test passed"); 94 (local_flag == FAILED) ? tst_resm(TFAIL, 95 "Test failed") : tst_resm(TPASS, 96 "Test passed"); 97 tst_exit(); 98 } 99 100 void fill(void) 101 { 102 register int i; 103 for (i = 0; i < BSIZE; i++) 104 buf[i] = 'a'; 105 } 106 107 int checkit(char *str) 108 { 109 register int i = 0; 110 111 while (!*str++) 112 i++; 113 114 return (i); 115 } 116