jehanne/qa/lib/c/env.rc
Giacomo Tesio 65cdad4317 libc: rewrite putenv and getenv.
These new implementations

- do several validity check on input parameters
- allow a bit larger variable names (127 bytes, aka sizeof(Proc.genbuf)-1)
- preserve nulls in the content (the original version used to replace
  '\0' with ' '). I can't see why they did, actually.
  See also http://marc.info/?l=9fans&m=148475801229908&w=2

Should also fix CID 155718
2017-01-19 00:58:43 +01:00

29 lines
802 B
Bash
Executable File

#!/cmd/rc
# verify that environment variables can have names 127 byte long
# why 127? because it's the size of genbuf in the kernel's Proc structure
# minus the ending \0
abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678=10
if ( ! ~ $abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678 10 ) {
echo FAIL: cannot read an environment variable with a long name
exit FAIL
}
# verify that rc lists work
list=(How now brown cow)
string=$"list
if( ! ~ $#list 4 ) {
echo FAIL: list count does not work on a 4 elements list
exit FAIL
}
if( ! ~ $#string 1 ) {
echo FAIL: list count does not work on a single string
exit FAIL
}
echo PASS
exit PASS