utxent.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 = utmpx->ut_tv;
  65. #else
  66. utmp->ut_time = utmpx->ut_time;
  67. #endif
  68. }
  69. /* Copy the information in UTMP to UTMPX. */
  70. void getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
  71. {
  72. memset (utmpx, 0, sizeof (struct utmpx));
  73. #if _HAVE_UT_TYPE - 0
  74. utmpx->ut_type = utmp->ut_type;
  75. #endif
  76. #if _HAVE_UT_PID - 0
  77. utmpx->ut_pid = utmp->ut_pid;
  78. #endif
  79. memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line));
  80. memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user));
  81. #if _HAVE_UT_ID - 0
  82. memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id));
  83. #endif
  84. #if _HAVE_UT_HOST - 0
  85. memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host));
  86. #endif
  87. #if _HAVE_UT_TV - 0
  88. utmpx->ut_tv = utmp->ut_tv;
  89. #else
  90. utmpx->ut_time = utmp->ut_time;
  91. #endif
  92. }