getlogin_r-tests: avoid false failure under sudo/ssh etc.

* tests/test-getlogin_r.c (main): Sync up with test-getlogin.c
changes from commit 97249cf29 to not depend on environment variables.
xalloc: don't potentially generate invalid code for xmemdup calls

* lib/xalloc.h (xmemdup): Do not mark with _GL_ATTRIBUTE_ALLOC, as
this function can initialize the newly-allocated storage with new
pointers, which means this function is not malloc-like.  See:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56955
update from texinfo
fchdir: port 'open' and 'close' redefinitions to AIX 7.1

* lib/chown.c, lib/clean-temp.c, lib/copy-file.c, lib/execute.c:
* lib/fsusage.c, lib/gc-gnulib.c, lib/javacomp.c, lib/mountlist.c:
* lib/openat-proc.c, lib/pagealign_alloc.c, lib/progreloc.c:
* lib/spawn-pipe.c:
Do not #undef 'open' and 'close'.  AIX 7 does '#define open open64'
and then 'int open64(const char *, int, ...);', which means the
declaration for 'open' gets lost if we later '#undef open'.
Discovered while building grep pretest 2.18.151-1c770 on AIX 7.1,
where the compilation reported the non-fatal error "In function
'openat_proc_name' ... warning: implicit declaration of function
'open'".  In this case the error is relatively harmless, but in
other cases it might not be so minor.
getlogin_r-tests: fix various issues in recent change

* tests/test-getlogin_r.c: Include required headers that were
missed in recent commit eec20b4e.
Also consistently check the errno rather than the return value from
getlogin_r as POSIX only specifies that non zero is returned on error.
* modules/getlogin_r-tests (configure.ac): Add the check for ttyname().
getlogin_r-tests: check return value rather than errno

* tests/test-getlogin_r.c (main): As per POSIX we should be
verifying the return value from getlogin_r() rather than errno.