X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-gethostname.c;h=45c223a2f870aefa38d9f0cd2c8cf29563b7b0f0;hb=b40d2e71aa6bbe8f25c53323a94e31f391db7dfd;hp=d298b7a887340e190e05648617e6976909221284;hpb=3765bb11d93dd02d30df7eb9ada09ba887366131;p=gnulib.git diff --git a/tests/test-gethostname.c b/tests/test-gethostname.c index d298b7a88..45c223a2f 100644 --- a/tests/test-gethostname.c +++ b/tests/test-gethostname.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Free Software Foundation + * Copyright (C) 2008-2011 Free Software Foundation, Inc. * Written by Simon Josefsson. * * This program is free software: you can redistribute it and/or modify @@ -17,26 +17,40 @@ #include +/* Get gethostname() declaration. */ +#include + +#include "signature.h" +SIGNATURE_CHECK (gethostname, int, (char *, size_t)); + +/* Get HOST_NAME_MAX definition. */ +#include + #include #include #include -#include #define NOHOSTNAME "magic-gnulib-test-string" int -main (int argc, char *argv[]) +main (int argc, char *argv[] _GL_UNUSED) { - char buf[2500]; + char buf[HOST_NAME_MAX]; int rc; + if (strlen (NOHOSTNAME) >= HOST_NAME_MAX) + { + printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX); + return 2; + } + strcpy (buf, NOHOSTNAME); rc = gethostname (buf, sizeof (buf)); if (rc != 0) { - printf ("gethostname failed, rc %d errno %d\n", errno); + printf ("gethostname failed, rc %d errno %d\n", rc, errno); return 1; }