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@us.ibm.com */ 21/* 06/30/2001 Port to Linux nsharoff@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/***** LTP Port *****/ 43#include "test.h" 44 45char *TCID = "memset01"; 46 47/***** ** ** *****/ 48#undef BSIZE 49#define BSIZE 4096 50#define LEN 100 51#define FAILED 0 52#define PASSED 1 53 54char buf[BSIZE]; 55 56/***** LTP Port *****/ 57int local_flag = PASSED; 58int block_number; 59int TST_TOTAL = 1; 60 61int anyfail(); 62void setup(); 63int blenter(); 64/***** ** ** *****/ 65 66void fill(); 67int checkit(char *str); 68 69/*--------------------------------------------------------------*/ 70int main(int argc, char *argv[]) 71{ 72 register int i, j; 73 char *p; 74 75/*--------------------------------------------------------------*/ 76 local_flag = PASSED; 77 78 fill(); 79 80 for (i = 0; i < 200; i++) { 81 fill(); 82 p = &buf[400]; 83 memset(p, 0, i); 84 if ((j = checkit(p)) != i) { 85 tst_resm(TINFO, 86 "Not enough zero bytes, wanted %d, got %d", i, 87 j); 88 local_flag = FAILED; 89 break; 90 } 91 if (!p[-1] || !p[i]) { 92 tst_resm(TINFO, "Boundary error, clear of %d", i); 93 local_flag = FAILED; 94 } 95 if (local_flag == FAILED) 96 break; 97 } 98 99 (local_flag == FAILED) ? tst_resm(TFAIL, 100 "Test failed") : tst_resm(TPASS, 101 "Test passed"); 102/*--------------------------------------------------------------*/ 103/* Clean up any files created by test before call to anyfail. */ 104 105 (local_flag == FAILED) ? tst_resm(TFAIL, 106 "Test failed") : tst_resm(TPASS, 107 "Test passed"); 108 tst_exit(); 109} 110 111/*--------------------------------------------------------------*/ 112/* FUNCTIONS GO HERE */ 113 114void fill(void) 115{ 116 register int i; 117 for (i = 0; i < BSIZE; i++) 118 buf[i] = 'a'; 119} 120 121int checkit(char *str) 122{ 123 register int i = 0; 124 125 while (!*str++) 126 i++; 127 128 return (i); 129} 130