BOOT2 - adjust hammerread code to understand the new directory localization cap.
[dragonfly.git] / contrib / opie / libopie / getutmpentry.c
blobf3afe0c3aa1814366b4611784fc2571a92de1bc0
1 /* getutmpentry.c: The __opiegetutmpentry() library function.
3 %%% copyright-cmetz-96
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
9 History:
11 Modified by cmetz for OPIE 2.31. Cache result.
12 Created by cmetz for OPIE 2.3 (re-write).
15 #include "opie_cfg.h"
16 #include <stdio.h>
17 #include <sys/types.h>
18 #include <utmp.h>
20 #if DOUTMPX
21 #include <utmpx.h>
22 #define setutent setutxent
23 #define getutline(x) getutxline(x)
24 #define utmp utmpx
25 #endif /* DOUTMPX */
27 #if HAVE_STRING_H
28 #include <string.h>
29 #endif /* HAVE_STRING_H */
31 #if DEBUG
32 #include <syslog.h>
33 #endif /* DEBUG */
34 #include "opie.h"
36 #if !HAVE_GETUTLINE && !DOUTMPX
37 struct utmp *getutline __P((struct utmp *));
38 #endif /* HAVE_GETUTLINE && !DOUTMPX */
40 static struct utmp u;
42 int __opiegetutmpentry FUNCTION((line, utmp), char *line AND struct utmp *utmp)
44 struct utmp *pu;
46 if (u.ut_line[0]) {
47 pu = &u;
48 goto gotit;
51 memset(&u, 0, sizeof(u));
53 if (!strncmp(line, "/dev/", 5)) {
54 strncpy(u.ut_line, line + 5, sizeof(u.ut_line));
55 setutent();
56 if ((pu = getutline(&u)))
57 goto gotit;
59 #ifdef hpux
60 strcpy(u.ut_line, "pty/");
61 strncpy(u.ut_line + 4, line + 5, sizeof(u.ut_line) - 4);
62 setutent();
63 if ((pu = getutline(&u)))
64 goto gotit;
65 #endif /* hpux */
68 strncpy(u.ut_line, line, sizeof(u.ut_line));
69 setutent();
70 if ((pu = getutline(&u)))
71 goto gotit;
73 #if DEBUG
74 syslog(LOG_DEBUG, "__opiegetutmpentry: failed to find entry for line %s", line);
75 #endif /* DEBUG */
76 return -1;
78 gotit:
79 #if DEBUG
80 syslog(LOG_DEBUG, "__opiegetutmpentry: succeeded with line %s", pu->ut_line);
81 #endif /* DEBUG */
82 memcpy(utmp, pu, sizeof(struct utmp));
83 return 0;