X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-gethostname.c;h=32723da193a863cfe67e6fc4284e710ed18054b6;hb=dfd4d11c50dd4729bf46c26a3bbdda0c6031409d;hp=d298b7a887340e190e05648617e6976909221284;hpb=3765bb11d93dd02d30df7eb9ada09ba887366131;p=gnulib.git diff --git a/tests/test-gethostname.c b/tests/test-gethostname.c index d298b7a88..32723da19 100644 --- a/tests/test-gethostname.c +++ b/tests/test-gethostname.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Free Software Foundation + * Copyright (C) 2008, 2009 Free Software Foundation * Written by Simon Josefsson. * * This program is free software: you can redistribute it and/or modify @@ -17,26 +17,36 @@ #include +/* Get gethostname() declaration. */ +#include +/* 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[] _UNUSED_PARAMETER_) { - 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; }