utxent.c 2.5 KB

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