version 1.25, 2008/04/28 20:22:59 |
version 1.25.8.3, 2008/11/23 21:46:05 |
Line 56 __RCSID("$NetBSD$"); |
|
Line 56 __RCSID("$NetBSD$"); |
|
|
|
static FILE *fp; |
static FILE *fp; |
static int readonly = 0; |
static int readonly = 0; |
|
static int version = 1; |
static struct utmpx ut; |
static struct utmpx ut; |
static char utfile[MAXPATHLEN] = _PATH_UTMPX; |
static char utfile[MAXPATHLEN] = _PATH_UTMPX; |
|
|
static struct utmpx *utmp_update(const struct utmpx *); |
static struct utmpx *utmp_update(const struct utmpx *); |
|
|
static const char vers[] = "utmpx-1.00"; |
static const char vers[] = "utmpx-2.00"; |
|
|
|
struct otimeval { |
|
long tv_sec; |
|
long tv_usec; |
|
}; |
|
|
|
static void |
|
old2new(struct utmpx *utx) |
|
{ |
|
struct otimeval otv; |
|
struct timeval *tv = &utx->ut_tv; |
|
(void)memcpy(&otv, tv, sizeof(otv)); |
|
tv->tv_sec = otv.tv_sec; |
|
tv->tv_usec = otv.tv_usec; |
|
} |
|
|
|
static void |
|
new2old(struct utmpx *utx) |
|
{ |
|
struct timeval tv; |
|
struct otimeval *otv = (void *)&utx->ut_tv; |
|
(void)memcpy(&tv, otv, sizeof(tv)); |
|
otv->tv_sec = (long)tv.tv_sec; |
|
otv->tv_usec = (long)tv.tv_usec; |
|
} |
|
|
void |
void |
setutxent() |
setutxent() |
|
|
/* old file, read signature record */ |
/* old file, read signature record */ |
if (fread(&ut, sizeof(ut), 1, fp) != 1) |
if (fread(&ut, sizeof(ut), 1, fp) != 1) |
goto failclose; |
goto failclose; |
if (memcmp(ut.ut_user, vers, sizeof(vers)) != 0 || |
if (memcmp(ut.ut_user, vers, 5) != 0 || |
ut.ut_type != SIGNATURE) |
ut.ut_type != SIGNATURE) |
goto failclose; |
goto failclose; |
} |
} |
|
version = ut.ut_user[6] - '0'; |
} |
} |
|
|
if (fread(&ut, sizeof(ut), 1, fp) != 1) |
if (fread(&ut, sizeof(ut), 1, fp) != 1) |
goto fail; |
goto fail; |
|
if (version == 1) |
|
old2new(&ut); |
|
|
|
printf(">%d %s\n", version, ut.ut_name); |
return &ut; |
return &ut; |
failclose: |
failclose: |
(void)fclose(fp); |
(void)fclose(fp); |
Line 248 pututxline(const struct utmpx *utx) |
|
Line 278 pututxline(const struct utmpx *utx) |
|
return NULL; |
return NULL; |
} |
} |
|
|
|
if (version == 1) |
|
new2old(&temp); |
if (fwrite(&temp, sizeof (temp), 1, fp) != 1) |
if (fwrite(&temp, sizeof (temp), 1, fp) != 1) |
goto fail; |
goto fail; |
|
|