diff options
| author | christos <christos@NetBSD.org> | 2002-07-28 21:45:39 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2002-07-28 21:45:39 +0000 |
| commit | f04f8bc9492e77ca7da3c8a8cf08ce637a1a8f27 (patch) | |
| tree | 3f1b7f5708dd8d2c7e0e2783daac274b3254632d | |
| parent | 156b33bc4e6220a8f75b69902fcf409009622fe1 (diff) | |
add utmpname()
| -rw-r--r-- | include/utmp.h | 3 | ||||
| -rw-r--r-- | lib/libc/gen/utmp.c | 26 |
2 files changed, 25 insertions, 4 deletions
diff --git a/include/utmp.h b/include/utmp.h index 09719749fdb..64412c08a11 100644 --- a/include/utmp.h +++ b/include/utmp.h @@ -1,4 +1,4 @@ -/* $NetBSD: utmp.h,v 1.7 2002/07/27 23:57:02 christos Exp $ */ +/* $NetBSD: utmp.h,v 1.8 2002/07/28 21:45:39 christos Exp $ */ /* * Copyright (c) 1988, 1993 @@ -65,6 +65,7 @@ struct utmp { }; __BEGIN_DECLS +int utmpname(const char *); void setutent(void); struct utmp *getutent(void); void endutent(void); diff --git a/lib/libc/gen/utmp.c b/lib/libc/gen/utmp.c index da4326c78a0..e13f9aa5a86 100644 --- a/lib/libc/gen/utmp.c +++ b/lib/libc/gen/utmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: utmp.c,v 1.2 2002/07/28 20:46:43 christos Exp $ */ +/* $NetBSD: utmp.c,v 1.3 2002/07/28 21:46:03 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -38,15 +38,18 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: utmp.c,v 1.2 2002/07/28 20:46:43 christos Exp $"); +__RCSID("$NetBSD: utmp.c,v 1.3 2002/07/28 21:46:03 christos Exp $"); #endif /* LIBC_SCCS and not lint */ +#include <sys/types.h> +#include <sys/param.h> #include <stdio.h> #include <time.h> #include <utmp.h> static struct utmp utmp; static FILE *ut; +static char utfile[MAXPATHLEN] = _PATH_UTMP; void setutent(void) @@ -60,7 +63,7 @@ struct utmp * getutent(void) { if (ut == NULL) { - if ((ut = fopen(_PATH_UTMP, "r")) == NULL) + if ((ut = fopen(utfile, "r")) == NULL) return NULL; } if (fread(&utmp, sizeof(utmp), 1, ut) == 1) @@ -76,3 +79,20 @@ endutent(void) ut = NULL; } } + +int +utmpname(const char *fname) +{ + size_t len = strlen(fname); + + if (len >= sizeof(utfile)) + return 0; + + /* must not end in x! */ + if (fname[len - 1] == 'x') + return 0; + + (void)strcpy(utfile, fname); + endutent(); + return 1; +} |
