Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/login.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/login.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * issue.c: issue printing code … … 4 5 * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org> 5 6 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 7 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru> 10 8 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 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. 19 * 20 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru> 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 21 10 */ 22 11 23 12 #include <sys/param.h> /* MAXHOSTNAMELEN */ 24 #include <stdio.h> 25 #include <unistd.h> 13 #include <sys/utsname.h> 26 14 #include "libbb.h" 27 28 #include <sys/utsname.h>29 #include <time.h>30 15 31 16 #define LOGIN " login: " 32 17 33 static const char fmtstr_d[] = "%A, %d %B %Y";34 static const char fmtstr_t[] = "%H:%M:%S";18 static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y"; 19 static const char fmtstr_t[] ALIGN1 = "%H:%M:%S"; 35 20 36 21 void print_login_issue(const char *issue_file, const char *tty) … … 48 33 puts("\r"); /* start a new line */ 49 34 50 if ((fd = fopen(issue_file, "r"))) { 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; 35 fd = fopen(issue_file, "r"); 36 if (!fd) 37 return; 38 while ((c = fgetc(fd)) != EOF) { 39 outbuf = buf; 40 buf[0] = c; 41 buf[1] = '\0'; 42 if (c == '\n') { 43 buf[1] = '\r'; 44 buf[2] = '\0'; 45 } 46 if (c == '\\' || c == '%') { 47 c = fgetc(fd); 48 switch (c) { 49 case 's': 50 outbuf = uts.sysname; 51 break; 52 case 'n': 53 outbuf = uts.nodename; 54 break; 55 case 'r': 56 outbuf = uts.release; 57 break; 58 case 'v': 59 outbuf = uts.version; 60 break; 61 case 'm': 62 outbuf = uts.machine; 63 break; 64 case 'D': 65 case 'o': 66 c = getdomainname(buf, sizeof(buf) - 1); 67 buf[c >= 0 ? c : 0] = '\0'; 68 break; 69 case 'd': 70 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); 71 break; 72 case 't': 73 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); 74 break; 75 case 'h': 76 gethostname(buf, sizeof(buf) - 1); 77 buf[sizeof(buf) - 1] = '\0'; 78 break; 79 case 'l': 80 outbuf = tty; 81 break; 82 default: 83 buf[0] = c; 59 84 } 60 if (c == '\\' || c == '%') {61 c = fgetc(fd);62 switch (c) {63 case 's':64 outbuf = uts.sysname;65 break;66 67 case 'n':68 outbuf = uts.nodename;69 break;70 71 case 'r':72 outbuf = uts.release;73 break;74 75 case 'v':76 outbuf = uts.version;77 break;78 79 case 'm':80 outbuf = uts.machine;81 break;82 83 case 'D':84 case 'o':85 c = getdomainname(buf, sizeof(buf) - 1);86 buf[c >= 0 ? c : 0] = '\0';87 break;88 89 case 'd':90 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));91 break;92 93 case 't':94 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));95 break;96 97 case 'h':98 gethostname(buf, sizeof(buf) - 1);99 buf[sizeof(buf) - 1] = '\0';100 break;101 102 case 'l':103 outbuf = tty;104 break;105 106 default:107 buf[0] = c;108 }109 }110 fputs(outbuf, stdout);111 85 } 112 113 fclose(fd); 114 115 fflush(stdout); 86 fputs(outbuf, stdout); 116 87 } 88 fclose(fd); 89 fflush(stdout); 117 90 } 118 91 … … 121 94 char buf[MAXHOSTNAMELEN+1]; 122 95 123 if (gethostname(buf, MAXHOSTNAMELEN) == 0)96 if (gethostname(buf, MAXHOSTNAMELEN) == 0) 124 97 fputs(buf, stdout); 125 98 … … 127 100 fflush(stdout); 128 101 } 129
Note:
See TracChangeset
for help on using the changeset viewer.