2020-05-17 17:28:51 +00:00
|
|
|
/*
|
2018-08-16 08:50:53 +00:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2020-12-29 12:37:20 +00:00
|
|
|
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2018-08-16 08:50:53 +00:00
|
|
|
*
|
|
|
|
* This file is part of GNU Mes.
|
|
|
|
*
|
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-08 13:36:22 +00:00
|
|
|
#include <mes/lib.h>
|
|
|
|
#include <string.h>
|
2018-08-16 08:50:53 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-05-17 17:28:51 +00:00
|
|
|
// CONSTANT M2_PTR_SIZE 4
|
|
|
|
#define M2_PTR_SIZE 1
|
|
|
|
|
2018-08-16 08:50:53 +00:00
|
|
|
char *
|
2019-05-18 11:27:42 +00:00
|
|
|
getenv (char const *s)
|
2018-08-16 08:50:53 +00:00
|
|
|
{
|
2020-05-17 17:28:51 +00:00
|
|
|
/* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */
|
2018-08-16 08:50:53 +00:00
|
|
|
char **p = environ;
|
2020-12-29 12:37:20 +00:00
|
|
|
char *q;
|
2018-08-16 08:50:53 +00:00
|
|
|
int length = strlen (s);
|
2020-05-17 17:28:51 +00:00
|
|
|
|
|
|
|
while (p[0] != 0)
|
2018-08-16 08:50:53 +00:00
|
|
|
{
|
2020-05-17 17:28:51 +00:00
|
|
|
/* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */
|
|
|
|
if (strncmp (s, p[0], length) == 0)
|
|
|
|
{
|
|
|
|
/* eputs ("found!\n"); */
|
2020-12-29 12:37:20 +00:00
|
|
|
q = p[0] + length;
|
2020-05-17 17:28:51 +00:00
|
|
|
if (q[0] == '=')
|
|
|
|
return q + 1;
|
|
|
|
}
|
|
|
|
/* else */
|
|
|
|
/* eputs ("not found!\n"); */
|
|
|
|
p = p + M2_PTR_SIZE;
|
2018-08-16 08:50:53 +00:00
|
|
|
}
|
2020-05-17 17:28:51 +00:00
|
|
|
|
2018-08-16 08:50:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|