malloca: Silence a warning from clang's memory sanitizer.
[gnulib.git] / tests / test-getprogname.c
blob299ca3d9294af693aaac3e3774f46b16c482dbd4
1 /* Test the gnulib getprogname module.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include "getprogname.h"
20 #include <string.h>
21 #include <assert.h>
23 #ifdef __hpux
24 # define STREQ(a, b) (strncmp (a, b, 14) == 0)
25 #else
26 # define STREQ(a, b) (strcmp (a, b) == 0)
27 #endif
29 int
30 main (void)
32 char const *p = getprogname ();
34 /* libtool creates a temporary executable whose name is sometimes prefixed
35 with "lt-" (depends on the platform). But the name of the temporary
36 executable is a detail that should not be visible to the end user and to
37 the test suite. Remove this "lt-" prefix here. */
38 if (strncmp (p, "lt-", 3) == 0)
39 p += 3;
41 /* Note: You can make this test fail
42 a) by running it on a case-insensitive file system (such as on Windows,
43 Cygwin, or on Mac OS X with a case-insensitive HFS+ file system),
44 with an invocation that contains upper case characters, e.g.
45 test-GETPROGNAME,
46 b) by hardlinking or symlinking it to a different name (e.g. test-foo)
47 and invoking it through that name.
48 That's not the intended use. The Makefile always invokes it as
49 'test-getprogname${EXEEXT}'. */
50 #if defined __CYGWIN__
51 /* The Cygwin getprogname() function strips the ".exe" suffix. */
52 assert (STREQ (p, "test-getprogname"));
53 #else
54 assert (STREQ (p, "test-getprogname" EXEEXT));
55 #endif
57 return 0;