diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-05-26 14:07:50 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-05-26 14:07:50 +0000 |
commit | 393183dccc4d100366972bdbbdc6e03a77839120 (patch) | |
tree | d2e94dac0f1f5da5cb3ecb927b78c4c2a02f4ea6 /libbb/login.c | |
parent | ddfe18df75c15be4a2aadddb241c3b86b1e2968a (diff) | |
download | busybox-w32-393183dccc4d100366972bdbbdc6e03a77839120.tar.gz busybox-w32-393183dccc4d100366972bdbbdc6e03a77839120.tar.bz2 busybox-w32-393183dccc4d100366972bdbbdc6e03a77839120.zip |
Vodz, last_patch_86
Diffstat (limited to 'libbb/login.c')
-rw-r--r-- | libbb/login.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/libbb/login.c b/libbb/login.c index bd8035f41..67636e6b5 100644 --- a/libbb/login.c +++ b/libbb/login.c | |||
@@ -17,26 +17,28 @@ | |||
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | * | 19 | * |
20 | * $Id: login.c,v 1.3 2003/05/13 13:28:25 bug1 Exp $ | 20 | * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru> |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <sys/param.h> /* MAXHOSTNAMELEN */ | ||
23 | #include <stdio.h> | 24 | #include <stdio.h> |
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | #include "busybox.h" | 26 | #include "libbb.h" |
26 | 27 | ||
27 | #include <sys/utsname.h> | 28 | #include <sys/utsname.h> |
28 | #include <time.h> | 29 | #include <time.h> |
29 | 30 | ||
30 | #define LOGIN " login: " | 31 | #define LOGIN " login: " |
31 | 32 | ||
32 | static char fmtstr_d[] = { "%A, %d %B %Y" }; | 33 | static const char fmtstr_d[] = "%A, %d %B %Y"; |
33 | static char fmtstr_t[] = { "%H:%M:%S" }; | 34 | static const char fmtstr_t[] = "%H:%M:%S"; |
34 | 35 | ||
35 | void print_login_issue(const char *issue_file, const char *tty) | 36 | void print_login_issue(const char *issue_file, const char *tty) |
36 | { | 37 | { |
37 | FILE *fd; | 38 | FILE *fd; |
38 | int c; | 39 | int c; |
39 | char buf[256]; | 40 | char buf[256]; |
41 | const char *outbuf; | ||
40 | time_t t; | 42 | time_t t; |
41 | struct utsname uts; | 43 | struct utsname uts; |
42 | 44 | ||
@@ -47,73 +49,75 @@ void print_login_issue(const char *issue_file, const char *tty) | |||
47 | 49 | ||
48 | if ((fd = fopen(issue_file, "r"))) { | 50 | if ((fd = fopen(issue_file, "r"))) { |
49 | while ((c = fgetc(fd)) != EOF) { | 51 | while ((c = fgetc(fd)) != EOF) { |
52 | outbuf = buf; | ||
53 | buf[0] = c; | ||
54 | if(c == '\n') { | ||
55 | buf[1] = '\r'; | ||
56 | buf[2] = 0; | ||
57 | } else { | ||
58 | buf[1] = 0; | ||
59 | } | ||
50 | if (c == '\\' || c == '%') { | 60 | if (c == '\\' || c == '%') { |
51 | c = fgetc(fd); | 61 | c = fgetc(fd); |
52 | |||
53 | switch (c) { | 62 | switch (c) { |
54 | case 's': | 63 | case 's': |
55 | fputs(uts.sysname, stdout); | 64 | outbuf = uts.sysname; |
56 | break; | 65 | break; |
57 | 66 | ||
58 | case 'n': | 67 | case 'n': |
59 | fputs(uts.nodename, stdout); | 68 | outbuf = uts.nodename; |
60 | break; | 69 | break; |
61 | 70 | ||
62 | case 'r': | 71 | case 'r': |
63 | fputs(uts.release, stdout); | 72 | outbuf = uts.release; |
64 | break; | 73 | break; |
65 | 74 | ||
66 | case 'v': | 75 | case 'v': |
67 | fputs(uts.version, stdout); | 76 | outbuf = uts.version; |
68 | break; | 77 | break; |
69 | 78 | ||
70 | case 'm': | 79 | case 'm': |
71 | fputs(uts.machine, stdout); | 80 | outbuf = uts.machine; |
72 | break; | 81 | break; |
73 | 82 | ||
74 | case 'D': | 83 | case 'D': |
75 | case 'o': | 84 | case 'o': |
76 | getdomainname(buf, sizeof(buf)); | 85 | getdomainname(buf, sizeof(buf)); |
77 | buf[sizeof(buf) - 1] = '\0'; | 86 | buf[sizeof(buf) - 1] = '\0'; |
78 | fputs(buf, stdout); | ||
79 | break; | 87 | break; |
80 | 88 | ||
81 | case 'd': | 89 | case 'd': |
82 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); | 90 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); |
83 | fputs(buf, stdout); | ||
84 | break; | 91 | break; |
85 | 92 | ||
86 | case 't': | 93 | case 't': |
87 | strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); | 94 | strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); |
88 | fputs(buf, stdout); | ||
89 | break; | 95 | break; |
90 | 96 | ||
91 | case 'h': | 97 | case 'h': |
92 | gethostname(buf, sizeof(buf)); | 98 | gethostname(buf, sizeof(buf) - 1); |
93 | fputs(buf, stdout); | ||
94 | break; | 99 | break; |
95 | 100 | ||
96 | case 'l': | 101 | case 'l': |
97 | printf("%s", tty); | 102 | outbuf = tty; |
98 | break; | 103 | break; |
99 | 104 | ||
100 | default: | 105 | default: |
101 | putchar(c); | 106 | buf[0] = c; |
102 | } | 107 | } |
103 | } else | ||
104 | putchar(c); | ||
105 | } | 108 | } |
106 | 109 | fputs(outbuf, stdout); | |
107 | puts(""); /* start a new line */ | 110 | } |
108 | fflush(stdout); | ||
109 | 111 | ||
110 | fclose(fd); | 112 | fclose(fd); |
113 | |||
114 | fflush(stdout); | ||
111 | } | 115 | } |
112 | } | 116 | } |
113 | 117 | ||
114 | void print_login_prompt(void) | 118 | void print_login_prompt(void) |
115 | { | 119 | { |
116 | char buf[MAXHOSTNAMELEN]; | 120 | char buf[MAXHOSTNAMELEN+1]; |
117 | 121 | ||
118 | gethostname(buf, MAXHOSTNAMELEN); | 122 | gethostname(buf, MAXHOSTNAMELEN); |
119 | fputs(buf, stdout); | 123 | fputs(buf, stdout); |