test_gnunet_prefix.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2011, 2014 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file contrib/test_gnunet_prefix.c
  18. * @brief test if environment variable GNUNET_PREFIX is set so that
  19. * we have a chance to run tests
  20. * @author Christian Grothoff
  21. */
  22. #include "platform.h"
  23. int
  24. main (int argc,
  25. char **argv)
  26. {
  27. const char *basename;
  28. const char *dirname;
  29. basename = getenv ("GNUNET_PREFIX");
  30. if (NULL == basename)
  31. {
  32. fprintf (stderr,
  33. _("Environment variable GNUNET_PREFIX not set\n"));
  34. fprintf (stderr,
  35. _("Testcases will not work!\n"));
  36. return 1;
  37. }
  38. dirname = DIR_SEPARATOR_STR ".." DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR "config.d";
  39. {
  40. char tmp[strlen (basename) + strlen (dirname) + 1];
  41. sprintf (tmp, "%s%s", basename, dirname);
  42. if (0 != access (tmp, R_OK))
  43. {
  44. fprintf (stderr,
  45. _("Failed to access `%s': %s\n"),
  46. tmp,
  47. STRERROR (errno));
  48. fprintf (stderr,
  49. _("Check that you did run `make install' and that GNUNET_PREFIX='%s' is the correct prefix.\n"),
  50. basename);
  51. fprintf (stderr,
  52. _("Testcases will not work!\n"));
  53. return 2;
  54. }
  55. }
  56. return 0;
  57. }