Back to index

glibc  2.9
utmp-convert.h
Go to the documentation of this file.
00001 /* Copyright (C) 2008 Free Software Foundation, Inc.
00002    Contributed by Andreas Krebbel <Andreas.Krebbel@de.ibm.com>.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 
00022 /* This file provides functions converting between the 32 and 64 bit
00023    struct utmp variants.  */
00024 
00025 #ifndef _UTMP_CONVERT_H
00026 #define _UTMP_CONVERT_H 1
00027 
00028 #include <string.h>
00029 
00030 #include "utmp32.h"
00031 
00032 /* Convert the 64 bit struct utmp value in FROM to the 32 bit version
00033    returned in TO.  */
00034 static inline void
00035 utmp_convert64to32 (__const struct utmp *from, struct utmp32 *to)
00036 {
00037 #if _HAVE_UT_TYPE - 0
00038   to->ut_type = from->ut_type;
00039 #endif
00040 #if _HAVE_UT_PID - 0
00041   to->ut_pid = from->ut_pid;
00042 #endif
00043   memcpy (to->ut_line, from->ut_line, UT_LINESIZE);
00044   memcpy (to->ut_user, from->ut_user, UT_NAMESIZE);
00045 #if _HAVE_UT_ID - 0
00046   memcpy (to->ut_id, from->ut_id, 4);
00047 #endif
00048 #if _HAVE_UT_HOST - 0
00049   memcpy (to->ut_host, from->ut_host, UT_HOSTSIZE);
00050 #endif
00051   to->ut_exit = from->ut_exit;
00052   to->ut_session = (int32_t) from->ut_session;
00053 #if _HAVE_UT_TV - 0
00054   to->ut_tv.tv_sec = (int32_t) from->ut_tv.tv_sec;
00055   to->ut_tv.tv_usec = (int32_t) from->ut_tv.tv_usec;
00056 #endif
00057   memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4);
00058 }
00059 
00060 /* Convert the 32 bit struct utmp value in FROM to the 64 bit version
00061    returned in TO.  */
00062 static inline void
00063 utmp_convert32to64 (__const struct utmp32 *from, struct utmp *to)
00064 {
00065 #if _HAVE_UT_TYPE - 0
00066   to->ut_type = from->ut_type;
00067 #endif
00068 #if _HAVE_UT_PID - 0
00069   to->ut_pid = from->ut_pid;
00070 #endif
00071   memcpy (to->ut_line, from->ut_line, UT_LINESIZE);
00072   memcpy (to->ut_user, from->ut_user, UT_NAMESIZE);
00073 #if _HAVE_UT_ID - 0
00074   memcpy (to->ut_id, from->ut_id, 4);
00075 #endif
00076 #if _HAVE_UT_HOST - 0
00077   memcpy (to->ut_host, from->ut_host, UT_HOSTSIZE);
00078 #endif
00079   to->ut_exit = from->ut_exit;
00080   to->ut_session = (int64_t) from->ut_session;
00081 #if _HAVE_UT_TV - 0
00082   to->ut_tv.tv_sec = (int64_t) from->ut_tv.tv_sec;
00083   to->ut_tv.tv_usec = (int64_t) from->ut_tv.tv_usec;
00084 #endif
00085   memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4);
00086 }
00087 
00088 #endif /* utmp-convert.h */