1*0fc0ffeeSpgoyette /* $NetBSD: h_ps_strings1.c,v 1.1 2011/03/05 18:14:33 pgoyette Exp $ */
2*0fc0ffeeSpgoyette /*-
3*0fc0ffeeSpgoyette * Copyright (c) 2011 The NetBSD Foundation, Inc.
4*0fc0ffeeSpgoyette * All rights reserved.
5*0fc0ffeeSpgoyette *
6*0fc0ffeeSpgoyette * This code is derived from software contributed to The NetBSD Foundation
7*0fc0ffeeSpgoyette * by Joerg Sonnenberger.
8*0fc0ffeeSpgoyette *
9*0fc0ffeeSpgoyette * Redistribution and use in source and binary forms, with or without
10*0fc0ffeeSpgoyette * modification, are permitted provided that the following conditions
11*0fc0ffeeSpgoyette * are met:
12*0fc0ffeeSpgoyette *
13*0fc0ffeeSpgoyette * 1. Redistributions of source code must retain the above copyright
14*0fc0ffeeSpgoyette * notice, this list of conditions and the following disclaimer.
15*0fc0ffeeSpgoyette * 2. Redistributions in binary form must reproduce the above copyright
16*0fc0ffeeSpgoyette * notice, this list of conditions and the following disclaimer in
17*0fc0ffeeSpgoyette * the documentation and/or other materials provided with the
18*0fc0ffeeSpgoyette * distribution.
19*0fc0ffeeSpgoyette *
20*0fc0ffeeSpgoyette * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*0fc0ffeeSpgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*0fc0ffeeSpgoyette * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*0fc0ffeeSpgoyette * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24*0fc0ffeeSpgoyette * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*0fc0ffeeSpgoyette * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*0fc0ffeeSpgoyette * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27*0fc0ffeeSpgoyette * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*0fc0ffeeSpgoyette * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*0fc0ffeeSpgoyette * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30*0fc0ffeeSpgoyette * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*0fc0ffeeSpgoyette * SUCH DAMAGE.
32*0fc0ffeeSpgoyette */
33*0fc0ffeeSpgoyette
34*0fc0ffeeSpgoyette #include <sys/types.h>
35*0fc0ffeeSpgoyette #include <sys/exec.h>
36*0fc0ffeeSpgoyette #include <stdlib.h>
37*0fc0ffeeSpgoyette #include <unistd.h>
38*0fc0ffeeSpgoyette
39*0fc0ffeeSpgoyette extern struct ps_strings *__ps_strings;
40*0fc0ffeeSpgoyette
41*0fc0ffeeSpgoyette int
main(int argc,char ** argv,char ** environ)42*0fc0ffeeSpgoyette main(int argc, char **argv, char **environ)
43*0fc0ffeeSpgoyette {
44*0fc0ffeeSpgoyette int ret = 0;
45*0fc0ffeeSpgoyette int nenv;
46*0fc0ffeeSpgoyette
47*0fc0ffeeSpgoyette if (__ps_strings->ps_nargvstr != argc) {
48*0fc0ffeeSpgoyette static const char nargv_err[] = "Wrong argc in ps_strings";
49*0fc0ffeeSpgoyette write(STDOUT_FILENO, nargv_err, sizeof(nargv_err));
50*0fc0ffeeSpgoyette ret = 1;
51*0fc0ffeeSpgoyette }
52*0fc0ffeeSpgoyette
53*0fc0ffeeSpgoyette if (__ps_strings->ps_argvstr != argv) {
54*0fc0ffeeSpgoyette static const char argv_err[] = "Wrong argv in ps_strings";
55*0fc0ffeeSpgoyette write(STDOUT_FILENO, argv_err, sizeof(argv_err));
56*0fc0ffeeSpgoyette ret = 1;
57*0fc0ffeeSpgoyette }
58*0fc0ffeeSpgoyette
59*0fc0ffeeSpgoyette if (__ps_strings->ps_envstr != environ) {
60*0fc0ffeeSpgoyette static const char env_err[] = "Wrong env in ps_strings";
61*0fc0ffeeSpgoyette write(STDOUT_FILENO, env_err, sizeof(env_err));
62*0fc0ffeeSpgoyette ret = 1;
63*0fc0ffeeSpgoyette }
64*0fc0ffeeSpgoyette nenv = 0;
65*0fc0ffeeSpgoyette while (environ[nenv])
66*0fc0ffeeSpgoyette ++nenv;
67*0fc0ffeeSpgoyette if (__ps_strings->ps_nenvstr != nenv) {
68*0fc0ffeeSpgoyette static const char nenv_err[] = "Wrong nenv in ps_strings";
69*0fc0ffeeSpgoyette write(STDOUT_FILENO, nenv_err, sizeof(nenv_err));
70*0fc0ffeeSpgoyette ret = 1;
71*0fc0ffeeSpgoyette }
72*0fc0ffeeSpgoyette
73*0fc0ffeeSpgoyette return ret;
74*0fc0ffeeSpgoyette }
75