Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/libbb/login.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/login.c

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * issue.c: issue printing code
     
    45 * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org>
    56 *
    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>
    108 *
    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.
    2110 */
    2211
    2312#include <sys/param.h>  /* MAXHOSTNAMELEN */
    24 #include <stdio.h>
    25 #include <unistd.h>
     13#include <sys/utsname.h>
    2614#include "libbb.h"
    27 
    28 #include <sys/utsname.h>
    29 #include <time.h>
    3015
    3116#define LOGIN " login: "
    3217
    33 static const char fmtstr_d[] = "%A, %d %B %Y";
    34 static const char fmtstr_t[] = "%H:%M:%S";
     18static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
     19static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
    3520
    3621void print_login_issue(const char *issue_file, const char *tty)
     
    4833    puts("\r"); /* start a new line */
    4934
    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;
    5984            }
    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);
    11185        }
    112 
    113         fclose(fd);
    114 
    115         fflush(stdout);
     86        fputs(outbuf, stdout);
    11687    }
     88    fclose(fd);
     89    fflush(stdout);
    11790}
    11891
     
    12194    char buf[MAXHOSTNAMELEN+1];
    12295
    123     if(gethostname(buf, MAXHOSTNAMELEN) == 0)
     96    if (gethostname(buf, MAXHOSTNAMELEN) == 0)
    12497        fputs(buf, stdout);
    12598
     
    127100    fflush(stdout);
    128101}
    129 
Note: See TracChangeset for help on using the changeset viewer.