X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fgetenv_num.c;h=d3d257221cd78576b3cb94f0259c0585b70ae5db;hp=a90cc08d297ca89d61fdd5eebe5c6933f4a2b0bd;hb=119b5a6788c26bf7dcc99fcfd54e072946352a93;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/ncurses/tinfo/getenv_num.c b/ncurses/tinfo/getenv_num.c index a90cc08d..d3d25722 100644 --- a/ncurses/tinfo/getenv_num.c +++ b/ncurses/tinfo/getenv_num.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2013,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -36,7 +36,7 @@ #include -MODULE_ID("$Id: getenv_num.c,v 1.3 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: getenv_num.c,v 1.7 2018/06/30 19:54:49 tom Exp $") NCURSES_EXPORT(int) _nc_getenv_num(const char *name) @@ -54,3 +54,22 @@ _nc_getenv_num(const char *name) return (int) value; } + +NCURSES_EXPORT(void) +_nc_setenv_num(const char *name, int value) +{ + if (name != 0 && value >= 0) { + char buffer[128]; +#if HAVE_SETENV + _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%d", value); + setenv(name, buffer, 1); +#elif HAVE_PUTENV + char *s; + _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%s=%d", name, value); + if ((s = strdup(buffer)) != 0) + putenv(s); +#else +#error expected setenv/putenv functions +#endif + } +}