(root)/
grep-3.11/
gnulib-tests/
test-getprogname.c
       1  /* Test the gnulib getprogname module.
       2     Copyright (C) 2016-2023 Free Software Foundation, Inc.
       3  
       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.
       8  
       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.
      13  
      14     You should have received a copy of the GNU General Public License
      15     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      16  
      17  #include <config.h>
      18  
      19  #include <stdlib.h>
      20  
      21  #include <string.h>
      22  #include <assert.h>
      23  
      24  #ifdef __hpux
      25  # define STREQ(a, b) (strncmp (a, b, 14) == 0)
      26  #else
      27  # define STREQ(a, b) (strcmp (a, b) == 0)
      28  #endif
      29  
      30  int
      31  main (void)
      32  {
      33    char const *p = getprogname ();
      34  
      35    /* libtool creates a temporary executable whose name is sometimes prefixed
      36       with "lt-" (depends on the platform).  But the name of the temporary
      37       executable is a detail that should not be visible to the end user and to
      38       the test suite.  Remove this "lt-" prefix here.  */
      39    if (strncmp (p, "lt-", 3) == 0)
      40      p += 3;
      41  
      42    /* Note: You can make this test fail
      43       a) by running it on a case-insensitive file system (such as on Windows,
      44          Cygwin, or on Mac OS X with a case-insensitive HFS+ file system),
      45          with an invocation that contains upper case characters, e.g.
      46          test-GETPROGNAME,
      47       b) by hardlinking or symlinking it to a different name (e.g. test-foo)
      48          and invoking it through that name.
      49       That's not the intended use. The Makefile always invokes it as
      50       'test-getprogname${EXEEXT}'. */
      51  #if defined __CYGWIN__
      52    /* The Cygwin getprogname() function strips the ".exe" suffix. */
      53    assert (STREQ (p, "test-getprogname"));
      54  #else
      55    assert (STREQ (p, "test-getprogname" EXEEXT));
      56  #endif
      57  
      58    return 0;
      59  }