Back to index

glibc  2.9
utmpx-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    02111-1307 USA.  */
00019 
00020 
00021 /* This file provides functions converting between the 32 and 64 bit
00022    struct utmp variants.  */
00023 
00024 #ifndef _UTMPX_CONVERT_H
00025 #define _UTMPX_CONVERT_H 1
00026 
00027 #include <string.h>
00028 #include "utmpx32.h"
00029 
00030 /* Convert the 64 bit struct utmpx value in FROM to the 32 bit version
00031    returned in TO.  */
00032 static inline void
00033 utmpx_convert64to32 (const struct utmpx *from, struct utmpx32 *to)
00034 {
00035 #if _HAVE_UT_TYPE - 0
00036   to->ut_type = from->ut_type;
00037 #endif
00038 #if _HAVE_UT_PID - 0
00039   to->ut_pid = from->ut_pid;
00040 #endif
00041   memcpy (to->ut_line, from->ut_line, __UT_LINESIZE);
00042   memcpy (to->ut_user, from->ut_user, __UT_NAMESIZE);
00043 #if _HAVE_UT_ID - 0
00044   memcpy (to->ut_id, from->ut_id, 4);
00045 #endif
00046 #if _HAVE_UT_HOST - 0
00047   memcpy (to->ut_host, from->ut_host, __UT_HOSTSIZE);
00048 #endif
00049   to->ut_exit = from->ut_exit;
00050   to->ut_session = (int32_t) from->ut_session;
00051 #if _HAVE_UT_TV - 0
00052   to->ut_tv.tv_sec = (int32_t) from->ut_tv.tv_sec;
00053   to->ut_tv.tv_usec = (int32_t) from->ut_tv.tv_usec;
00054 #endif
00055   memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4);
00056 }
00057 
00058 /* Convert the 32 bit struct utmpx value in FROM to the 64 bit version
00059    returned in TO.  */
00060 static inline void
00061 utmpx_convert32to64 (const struct utmpx32 *from, struct utmpx *to)
00062 {
00063 #if _HAVE_UT_TYPE - 0
00064   to->ut_type = from->ut_type;
00065 #endif
00066 #if _HAVE_UT_PID - 0
00067   to->ut_pid = from->ut_pid;
00068 #endif
00069   memcpy (to->ut_line, from->ut_line, __UT_LINESIZE);
00070   memcpy (to->ut_user, from->ut_user, __UT_NAMESIZE);
00071 #if _HAVE_UT_ID - 0
00072   memcpy (to->ut_id, from->ut_id, 4);
00073 #endif
00074 #if _HAVE_UT_HOST - 0
00075   memcpy (to->ut_host, from->ut_host, __UT_HOSTSIZE);
00076 #endif
00077   to->ut_exit = from->ut_exit;
00078   to->ut_session = (int64_t) from->ut_session;
00079 #if _HAVE_UT_TV - 0
00080   to->ut_tv.tv_sec = (int64_t) from->ut_tv.tv_sec;
00081   to->ut_tv.tv_usec = (int64_t) from->ut_tv.tv_usec;
00082 #endif
00083   memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4);
00084 }
00085 
00086 #endif /* utmpx-convert.h */