blob: 5bb2496a4985e1e6515e5019ae7062e6990cf59e [file] [log] [blame]
robbiew35bd5872003-01-03 20:17:28 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew35bd5872003-01-03 20:17:28 +000018 */
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"
robbiew35bd5872003-01-03 20:17:28 +000044
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
robbiew35bd5872003-01-03 20:17:28 +000054char buf[BSIZE];
55
56/***** LTP Port *****/
57int local_flag = PASSED;
58int block_number;
robbiew35bd5872003-01-03 20:17:28 +000059int TST_TOTAL = 1;
60
robbiew35bd5872003-01-03 20:17:28 +000061int anyfail();
62void setup();
63int blenter();
64/***** ** ** *****/
65
66void fill();
67int checkit(char *str);
68
robbiew35bd5872003-01-03 20:17:28 +000069/*--------------------------------------------------------------*/
subrata_modak56207ce2009-03-23 13:35:39 +000070int main(int argc, char *argv[])
robbiew35bd5872003-01-03 20:17:28 +000071{
72 register int i, j;
73 char *p;
74
75/*--------------------------------------------------------------*/
subrata_modak56207ce2009-03-23 13:35:39 +000076 local_flag = PASSED;
robbiew35bd5872003-01-03 20:17:28 +000077
78 fill();
79
subrata_modak56207ce2009-03-23 13:35:39 +000080 for (i = 0; i < 200; i++) {
robbiew35bd5872003-01-03 20:17:28 +000081 fill();
82 p = &buf[400];
83 memset(p, 0, i);
84 if ((j = checkit(p)) != i) {
subrata_modak56207ce2009-03-23 13:35:39 +000085 tst_resm(TINFO,
86 "Not enough zero bytes, wanted %d, got %d", i,
87 j);
robbiew35bd5872003-01-03 20:17:28 +000088 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
subrata_modak56207ce2009-03-23 13:35:39 +000099 (local_flag == FAILED) ? tst_resm(TFAIL,
100 "Test failed") : tst_resm(TPASS,
101 "Test passed");
robbiew35bd5872003-01-03 20:17:28 +0000102/*--------------------------------------------------------------*/
103/* Clean up any files created by test before call to anyfail. */
104
subrata_modak56207ce2009-03-23 13:35:39 +0000105 (local_flag == FAILED) ? tst_resm(TFAIL,
106 "Test failed") : tst_resm(TPASS,
107 "Test passed");
robbiew35bd5872003-01-03 20:17:28 +0000108 tst_exit();
robbiew35bd5872003-01-03 20:17:28 +0000109}
subrata_modak56207ce2009-03-23 13:35:39 +0000110
robbiew35bd5872003-01-03 20:17:28 +0000111/*--------------------------------------------------------------*/
112/* FUNCTIONS GO HERE */
113
Mike Frysingerc57fba52014-04-09 18:56:30 -0400114void fill(void)
robbiew35bd5872003-01-03 20:17:28 +0000115{
116 register int i;
subrata_modak56207ce2009-03-23 13:35:39 +0000117 for (i = 0; i < BSIZE; i++)
robbiew35bd5872003-01-03 20:17:28 +0000118 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);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700129}