1 /* @(#)sgrow.c	1.16 21/08/20 Copyr 1985-2021 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static	UConst char sccsid[] =
5 	"@(#)sgrow.c	1.16 21/08/20 Copyr 1985-2021 J. Schilling";
6 #endif
7 /*
8  *	Check stack growing response on a machine
9  *
10  *	Copyright (c) 1985-2021 J. Schilling
11  */
12 /*
13  * The contents of this file are subject to the terms of the
14  * Common Development and Distribution License, Version 1.0 only
15  * (the "License").  You may not use this file except in compliance
16  * with the License.
17  *
18  * See the file CDDL.Schily.txt in this distribution for details.
19  * A copy of the CDDL is also available via the Internet at
20  * http://www.opensource.org/licenses/cddl1.txt
21  *
22  * When distributing Covered Code, include this CDDL HEADER in each
23  * file and include the License file CDDL.Schily.txt from this distribution.
24  */
25 
26 #include <schily/stdio.h>
27 #include <schily/standard.h>
28 #include <schily/stdlib.h>
29 #include <schily/utypes.h>
30 #define	GT_COMERR		/* #define comerr gtcomerr */
31 #define	GT_ERROR		/* #define error gterror   */
32 #include <schily/schily.h>
33 #include <schily/nlsdefs.h>
34 
35 char *options = "help,version";
36 
37 EXPORT	int	main	__PR((int ac, char ** av));
38 LOCAL	Intptr_t _ret	__PR((Intptr_t i));
39 LOCAL	Intptr_t grow	__PR((int i));
40 LOCAL	void	usage	__PR((int ret));
41 
42 EXPORT int
main(ac,av)43 main(ac, av)
44 	int  ac;
45 	char *av[];
46 {
47 	int 	i;
48 	char	* const *cav = av;
49 	int 	cac   = ac;
50 	BOOL	help  = FALSE;
51 	BOOL	prversion = FALSE;
52 
53 	save_args(ac, av);
54 
55 	(void) setlocale(LC_ALL, "");
56 
57 #ifdef  USE_NLS
58 #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
59 #define	TEXT_DOMAIN "sgrow"		/* Use this only if it weren't */
60 #endif
61 	{ char	*dir;
62 	dir = searchfileinpath("share/locale", F_OK,
63 					SIP_ANY_FILE|SIP_NO_PATH, NULL);
64 	if (dir)
65 		(void) bindtextdomain(TEXT_DOMAIN, dir);
66 	else
67 #if defined(PROTOTYPES) && defined(INS_BASE)
68 	(void) bindtextdomain(TEXT_DOMAIN, INS_BASE "/share/locale");
69 #else
70 	(void) bindtextdomain(TEXT_DOMAIN, "/usr/share/locale");
71 #endif
72 	(void) textdomain(TEXT_DOMAIN);
73 	}
74 #endif 	/* USE_NLS */
75 
76 	cac--, ++cav;
77 	if (getallargs(&cac, &cav, options, &help, &prversion) == -1) {
78 		errmsgno(EX_BAD, "Bad option: %s.\n", cav[0]);
79 		usage(EX_BAD);
80 	}
81 	if (help)
82 		usage(0);
83 
84 	if (prversion) {
85 		gtprintf("Sgrow release %s (%s-%s-%s) Copyright (C) 1985-2021 %s\n",
86 				"1.16",
87 				HOST_CPU, HOST_VENDOR, HOST_OS,
88 				_("J�rg Schilling"));
89 		exit(0);
90 	}
91 
92 	cac = ac, cav = av;
93 	cac--, ++cav;
94 	if (getfiles(&cac, &cav, options) == 0) {
95 		errmsgno(EX_BAD, "Missing Pagecount.\n");
96 		usage(EX_BAD);
97 	}
98 	if (*astoi(cav[0], &i) != '\0') {
99 		errmsgno(EX_BAD, "not a number: %s.\n", av[1]);
100 		usage(EX_BAD);
101 	}
102 	gtprintf("growing %d * 4k Bytes = %d kBytes.\n", i, i*4);
103 	grow(i);
104 	gtprintf("End.\n");
105 	return (0);
106 }
107 
108 /*
109  * Hide the fact that we like to return the address of a local variable
110  * from the function grow().
111  */
112 LOCAL Intptr_t
_ret(i)113 _ret(i)
114 	Intptr_t	i;
115 {
116 	return (i);
117 }
118 
119 LOCAL Intptr_t
grow(i)120 grow(i)
121 	register int	i;
122 {
123 	char s[0x1000-(sizeof (int) + sizeof (char *) + sizeof (char *) + sizeof (int))];
124 			/* arg i	ret addr	fp		saved reg */
125 
126 	if (i % 10 == 0) {
127 		putchar('.'); fflush(stdout);
128 	}
129 
130 	if (--i <= 0)
131 		return (-1);
132 	grow(i);
133 	return (_ret((Intptr_t)s));
134 }
135 
136 LOCAL void
usage(ret)137 usage(ret)
138 	int	ret;
139 {
140 	error("Usage:   sgrow #\n");
141 	error("\n         # is n * Pagesize (4k Bytes)\n");
142 	exit(ret);
143 }
144