utxent.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * utexent.c : Support for accessing user accounting database.
  4. * Copyright (C) 2010 STMicroelectronics Ltd.
  5. *
  6. * Author: Salvatore Cro <salvatore.cro@st.com>
  7. *
  8. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  9. *
  10. */
  11. #include <features.h>
  12. #include <string.h>
  13. #include <utmpx.h>
  14. #include <utmp.h>
  15. void setutxent(void)
  16. {
  17. setutent ();
  18. }
  19. void endutxent(void)
  20. {
  21. endutent ();
  22. }
  23. struct utmpx *getutxent(void)
  24. {
  25. return (struct utmpx *) getutent ();
  26. }
  27. struct utmpx *getutxid(const struct utmpx *utmp_entry)
  28. {
  29. return (struct utmpx *) getutid ((const struct utmp *) utmp_entry);
  30. }
  31. struct utmpx *getutxline(const struct utmpx *utmp_entry)
  32. {
  33. return (struct utmpx *) getutline ((const struct utmp *) utmp_entry);
  34. }
  35. struct utmpx *pututxline (const struct utmpx *utmp_entry)
  36. {
  37. return (struct utmpx *) pututline ((const struct utmp *) utmp_entry);
  38. }
  39. int utmpxname (const char *new_ut_name)
  40. {
  41. return utmpname (new_ut_name);
  42. }
  43. void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx)
  44. {
  45. updwtmp (wtmpx_file, (const struct utmp *) utmpx);
  46. }
  47. /* Copy the information in UTMPX to UTMP. */
  48. void getutmp (const struct utmpx *utmpx, struct utmp *utmp)
  49. {
  50. #if _HAVE_UT_TYPE - 0
  51. utmp->ut_type = utmpx->ut_type;
  52. #endif
  53. #if _HAVE_UT_PID - 0
  54. utmp->ut_pid = utmpx->ut_pid;
  55. #endif
  56. memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line));
  57. memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user));
  58. #if _HAVE_UT_ID - 0
  59. memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id));
  60. #endif
  61. #if _HAVE_UT_HOST - 0
  62. memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host));
  63. #endif
  64. #if _HAVE_UT_TV - 0
  65. utmp->ut_tv.tv_sec = utmpx->ut_tv.tv_sec;
  66. utmp->ut_tv.tv_usec = utmpx->ut_tv.tv_usec;
  67. #else
  68. utmp->ut_time = utmpx->ut_time;
  69. #endif
  70. }
  71. /* Copy the information in UTMP to UTMPX. */
  72. void getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
  73. {
  74. memset (utmpx, 0, sizeof (struct utmpx));
  75. #if _HAVE_UT_TYPE - 0
  76. utmpx->ut_type = utmp->ut_type;
  77. #endif
  78. #if _HAVE_UT_PID - 0
  79. utmpx->ut_pid = utmp->ut_pid;
  80. #endif
  81. memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line));
  82. memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user));
  83. #if _HAVE_UT_ID - 0
  84. memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id));
  85. #endif
  86. #if _HAVE_UT_HOST - 0
  87. memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host));
  88. #endif
  89. #if _HAVE_UT_TV - 0
  90. utmpx->ut_tv.tv_sec = utmp->ut_tv.tv_sec;
  91. utmpx->ut_tv.tv_usec = utmp->ut_tv.tv_usec;
  92. #else
  93. utmpx->ut_time = utmp->ut_time;
  94. #endif
  95. }