1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Improve fix for not exporting readonly attribute (re: 7954855f)

The bitmask of attributes to export was repeatedly defined in three
different places, and that fix changed only one of them.

src/cmd/ksh93/sh/name.c:
- Single point of truth: define ATTR_TO_EXPORT macro with the
  bitmask of all the attributes to export (excluding NV_RDONLY).
- attstore(), pushnam(), sh_envgen(): Use the ATTR_TO_EXPORT macro,
  removing superflous NV_RDONLY handling from the former two.
This commit is contained in:
Martijn Dekker 2021-05-13 02:20:50 +02:00
parent 2e6346ef52
commit cd39ea7863

View file

@ -34,6 +34,7 @@
#include "FEATURE/externs" #include "FEATURE/externs"
#include "streval.h" #include "streval.h"
#define ATTR_TO_EXPORT (NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER)
#define NVCACHE 8 /* must be a power of 2 */ #define NVCACHE 8 /* must be a power of 2 */
static char *savesub = 0; static char *savesub = 0;
static char Null[1]; static char Null[1];
@ -2181,7 +2182,7 @@ static void attstore(register Namval_t *np, void *data)
if(data && strcmp(data,e_tolower) && strcmp(data,e_toupper)) if(data && strcmp(data,e_tolower) && strcmp(data,e_toupper))
return; return;
} }
flag &= (NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER); flag &= ATTR_TO_EXPORT;
*ap->attval++ = '='; *ap->attval++ = '=';
if((flag&NV_DOUBLE) == NV_DOUBLE) if((flag&NV_DOUBLE) == NV_DOUBLE)
{ {
@ -2210,7 +2211,7 @@ static void pushnam(Namval_t *np, void *data)
*ap->argnam++ = np->nvenv; *ap->argnam++ = np->nvenv;
else if(value=nv_getval(np)) else if(value=nv_getval(np))
*ap->argnam++ = staknam(np,value); *ap->argnam++ = staknam(np,value);
if(nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER)) if(!sh_isoption(SH_POSIX) && nv_isattr(np,ATTR_TO_EXPORT))
ap->attsize += (strlen(nv_name(np))+4); ap->attsize += (strlen(nv_name(np))+4);
} }
@ -2242,7 +2243,7 @@ char **sh_envgen(void)
/* Export variable attributes into env var named by e_envmarker, unless POSIX mode is on */ /* Export variable attributes into env var named by e_envmarker, unless POSIX mode is on */
cp = data.attval = strcopy(*data.argnam,e_envmarker); cp = data.attval = strcopy(*data.argnam,e_envmarker);
if(!sh_isoption(SH_POSIX)) if(!sh_isoption(SH_POSIX))
nv_scan(shp->var_tree, attstore,&data,0,(NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER)); nv_scan(shp->var_tree, attstore,&data,0,ATTR_TO_EXPORT);
*data.attval = 0; *data.attval = 0;
if(cp!=data.attval) if(cp!=data.attval)
data.argnam++; data.argnam++;