utmp-equal.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Helper function for utmp functions to see if two entries are equal.
  2. Copyright (C) 1996-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>
  5. and Paul Janzen <pcj@primenet.com>, 1996.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. #include <string.h>
  18. #include <utmp.h>
  19. #include "utmp-private.h"
  20. /* Test whether two entries match. */
  21. static int
  22. __utmp_equal (const struct utmp *entry, const struct utmp *match)
  23. {
  24. return
  25. (
  26. #if _HAVE_UT_TYPE - 0
  27. (entry->ut_type == INIT_PROCESS
  28. || entry->ut_type == LOGIN_PROCESS
  29. || entry->ut_type == USER_PROCESS
  30. || entry->ut_type == DEAD_PROCESS)
  31. &&
  32. (match->ut_type == INIT_PROCESS
  33. || match->ut_type == LOGIN_PROCESS
  34. || match->ut_type == USER_PROCESS
  35. || match->ut_type == DEAD_PROCESS)
  36. &&
  37. #endif
  38. #if _HAVE_UT_ID - 0
  39. (entry->ut_id[0] && match->ut_id[0]
  40. ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
  41. : strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0)
  42. #else
  43. strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
  44. #endif
  45. );
  46. }