diff options
author | Bruno Haible <bruno@clisp.org> | 2011-12-03 14:09:14 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2011-12-03 14:09:14 +0100 |
commit | 1917369d72235bea2b78b7d61f5ece0ea8e98d7e (patch) | |
tree | da049e39589116fcfddedf99fbc14497bee3e278 | |
parent | ab8fbf44bf4633d1c326940ce1d0715fb63936d4 (diff) | |
download | gnulib-1917369d72235bea2b78b7d61f5ece0ea8e98d7e.tar.gz |
Tweak last commit.
* lib/sethostname.c: Don't include <string.h>.
(sethostname): No need to copy the argument string to the stack. Don't
call clearerr. Preserve errno when fprintf failed.
* m4/sethostname.m4 (gl_FUNC_SETHOSTNAME): Comment about HOST_NAME_MAX.
Don't invoke AC_REPLACE_FUNCS.
* modules/sethostname (Link): Remove empty section.
* doc/glibc-functions/sethostname.texi: Gnulib does not fix the ENOSYS
failure problem.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | doc/glibc-functions/sethostname.texi | 3 | ||||
-rw-r--r-- | lib/sethostname.c | 27 | ||||
-rw-r--r-- | m4/sethostname.m4 | 2 | ||||
-rw-r--r-- | modules/sethostname | 2 |
5 files changed, 26 insertions, 20 deletions
@@ -1,3 +1,15 @@ +2011-12-03 Bruno Haible <bruno@clisp.org> + + Tweak last commit. + * lib/sethostname.c: Don't include <string.h>. + (sethostname): No need to copy the argument string to the stack. Don't + call clearerr. Preserve errno when fprintf failed. + * m4/sethostname.m4 (gl_FUNC_SETHOSTNAME): Comment about HOST_NAME_MAX. + Don't invoke AC_REPLACE_FUNCS. + * modules/sethostname (Link): Remove empty section. + * doc/glibc-functions/sethostname.texi: Gnulib does not fix the ENOSYS + failure problem. + 2011-12-01 Ben Walton <bwalton@artsci.utoronto.ca> New module 'sethostname'. diff --git a/doc/glibc-functions/sethostname.texi b/doc/glibc-functions/sethostname.texi index ec7b11a713..1d2c9ed2a1 100644 --- a/doc/glibc-functions/sethostname.texi +++ b/doc/glibc-functions/sethostname.texi @@ -9,6 +9,7 @@ Portability problems fixed by Gnulib: @item This function is missing on some platforms: Minix 3.1.8, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS. +Note that the Gnulib replacement may fail with ENOSYS on some platforms. @item This function is not declared on some platforms: AIX 7.1, OSF/1 5.1, Solaris 10. @@ -16,8 +17,6 @@ AIX 7.1, OSF/1 5.1, Solaris 10. On Solaris 10, the first argument is @code{char *} instead of @code{const char *} and the second parameter is @code{int} instead of @code{size_t}. -@item -On some platforms the Gnulib replacement always fails with ENOSYS. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/sethostname.c b/lib/sethostname.c index e1b7d74db5..3c2ec3c0c5 100644 --- a/lib/sethostname.c +++ b/lib/sethostname.c @@ -26,7 +26,6 @@ #include <errno.h> #include <stdio.h> -#include <string.h> #include <limits.h> /* Set up to LEN chars of NAME as system hostname. @@ -43,12 +42,6 @@ sethostname (const char *name, size_t len) return -1; } - /* NAME does not need to be null terminated so leave room to terminate - regardless of input. */ - char hostname[HOST_NAME_MAX + 1]; - memcpy ((void *) hostname, (const void *) name, len); - hostname[len] = '\0'; - #ifdef __minix /* Minix */ { FILE *hostf; @@ -63,24 +56,28 @@ sethostname (const char *name, size_t len) r = -1; else { - fprintf (hostf, "%s\n", hostname); + fprintf (hostf, "%.*s\n", (int) len, name); if (ferror (hostf)) { - clearerr (hostf); + /* Close hostf, preserving the errno from the fprintf call. */ + int saved_errno = errno; + fclose (hostf); + errno = saved_errno; r = -1; } - - /* use return value of fclose for function return value as it - matches our needs. fclose will also set errno on - failure */ - r = fclose (hostf); + else + { + if (fclose (hostf)) + /* fclose sets errno on failure. */ + r = -1; + } } return r; } #else /* For platforms that we don't have a better option for, simply bail - out */ + out. */ errno = ENOSYS; return -1; #endif diff --git a/m4/sethostname.m4 b/m4/sethostname.m4 index be5b036778..98a07df9f9 100644 --- a/m4/sethostname.m4 +++ b/m4/sethostname.m4 @@ -6,13 +6,13 @@ dnl with or without modifications, as long as this notice is preserved. # Ensure # - the sethostname() function, +# - the HOST_NAME_MAX macro in <limits.h>. AC_DEFUN([gl_FUNC_SETHOSTNAME], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) gl_PREREQ_HOST_NAME_MAX - AC_REPLACE_FUNCS([sethostname]) AC_CHECK_FUNCS([sethostname]) if test $ac_cv_func_sethostname = no; then HAVE_SETHOSTNAME=0 diff --git a/modules/sethostname b/modules/sethostname index 80087569c4..f3c0d134b5 100644 --- a/modules/sethostname +++ b/modules/sethostname @@ -22,8 +22,6 @@ Makefile.am: Include: <unistd.h> -Link: - License: LGPLv2+ |