Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 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/util-linux/readprofile.c

    r902 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 *  readprofile.c - used to read /proc/profile
     
    45 *  Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it)
    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.
    10  *
    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., 675 Mass Ave, Cambridge, MA 02139, USA.
     7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    198 */
    209
     
    4433 */
    4534
    46 #include <errno.h>
    47 #include <stdio.h>
    48 #include <fcntl.h>
    49 #include <stdlib.h>
    50 #include <unistd.h>
    51 #include <string.h>
    52 #include <sys/types.h>
    53 #include <sys/stat.h>
     35#include "libbb.h"
    5436#include <sys/utsname.h>
    5537
    56 #include "busybox.h"
    57 
    5838#define S_LEN 128
    5939
    6040/* These are the defaults */
    61 static const char defaultmap[]="/boot/System.map";
    62 static const char defaultpro[]="/proc/profile";
    63 
     41static const char defaultmap[] ALIGN1 = "/boot/System.map";
     42static const char defaultpro[] ALIGN1 = "/proc/profile";
     43
     44int readprofile_main(int argc, char **argv);
    6445int readprofile_main(int argc, char **argv)
    6546{
    6647    FILE *map;
    67     int proFd;
    68     const char *mapFile, *proFile, *mult=0;
    69     unsigned long len=0, indx=1;
    70     uint64_t add0=0;
     48    const char *mapFile, *proFile, *mult = 0;
     49    unsigned long indx = 1;
     50    size_t len;
     51    uint64_t add0 = 0;
    7152    unsigned int step;
    7253    unsigned int *buf, total, fn_len;
    73     unsigned long long fn_add, next_add;          /* current and next address */
     54    unsigned long long fn_add, next_add;     /* current and next address */
    7455    char fn_name[S_LEN], next_name[S_LEN];   /* current and next name */
     56    char mapline[S_LEN];
    7557    char mode[8];
    76     int c;
    77     int optAll=0, optInfo=0, optReset=0, optVerbose=0, optNative=0;
    78     int optBins=0, optSub=0;
    79     char mapline[S_LEN];
    80     int maplineno=1;
     58    int optAll = 0, optInfo = 0, optReset = 0;
     59    int optVerbose = 0, optNative = 0;
     60    int optBins = 0, optSub = 0;
     61    int maplineno = 1;
    8162    int header_printed;
    8263
     
    8667    mapFile = defaultmap;
    8768
    88     while ((c = getopt(argc, argv, "M:m:np:itvarVbs")) != -1) {
    89         switch(c) {
    90         case 'm':
    91             mapFile = optarg;
    92             break;
    93         case 'n':
    94             optNative++;
    95             break;
    96         case 'p':
    97             proFile = optarg;
    98             break;
    99         case 'a':
    100             optAll++;
    101             break;
    102         case 'b':
    103             optBins++;
    104             break;
    105         case 's':
    106             optSub++;
    107             break;
    108         case 'i':
    109             optInfo++;
    110             break;
    111         case 'M':
    112             mult = optarg;
    113             break;
    114         case 'r':
    115             optReset++;
    116             break;
    117         case 'v':
    118             optVerbose++;
    119             break;
    120         default:
    121             bb_show_usage();
    122         }
    123     }
     69    opt_complementary = "nn:aa:bb:ss:ii:rr:vv";
     70    getopt32(argv, "M:m:p:nabsirv",
     71            &mult, &mapFile, &proFile,
     72            &optNative, &optAll, &optBins, &optSub,
     73            &optInfo, &optReset, &optVerbose);
    12474
    12575    if (optReset || mult) {
     
    13181         */
    13282        if (mult) {
    133             multiplier = strtoul(mult, 0, 10);
     83            multiplier = xatoi_u(mult);
    13484            to_write = sizeof(int);
    13585        } else {
     
    13888        }
    13989
    140         fd = bb_xopen(defaultpro,O_WRONLY);
    141 
    142         if (write(fd, &multiplier, to_write) != to_write)
     90        fd = xopen(defaultpro, O_WRONLY);
     91
     92        if (full_write(fd, &multiplier, to_write) != to_write)
    14393            bb_perror_msg_and_die("error writing %s", defaultpro);
    14494
     
    150100     * Use an fd for the profiling buffer, to skip stdio overhead
    151101     */
    152 
    153     proFd = bb_xopen(proFile,O_RDONLY);
    154 
    155     if (((int)(len=lseek(proFd,0,SEEK_END)) < 0)
    156         || (lseek(proFd,0,SEEK_SET) < 0))
    157         bb_perror_msg_and_die(proFile);
    158 
    159     buf = xmalloc(len);
    160 
    161     if (read(proFd,buf,len) != len)
    162         bb_perror_msg_and_die(proFile);
    163 
    164     close(proFd);
    165 
     102    len = MAXINT(ssize_t);
     103    buf = xmalloc_open_read_close(proFile, &len);
    166104    if (!optNative) {
    167105        int entries = len/sizeof(*buf);
    168         int big = 0,small = 0,i;
     106        int big = 0, small = 0, i;
    169107        unsigned *p;
    170108
     
    176114        }
    177115        if (big > small) {
    178             bb_error_msg("Assuming reversed byte order. "
    179                 "Use -n to force native byte order.");
     116            bb_error_msg("assuming reversed byte order, "
     117                "use -n to force native byte order");
    180118            for (p = buf; p < buf+entries; p++)
    181119                for (i = 0; i < sizeof(*buf)/2; i++) {
     
    198136    total = 0;
    199137
    200     map = bb_xfopen(mapFile, "r");
    201 
    202     while (fgets(mapline,S_LEN,map)) {
    203         if (sscanf(mapline,"%llx %s %s",&fn_add,mode,fn_name) != 3)
     138    map = xfopen(mapFile, "r");
     139
     140    while (fgets(mapline, S_LEN, map)) {
     141        if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3)
    204142            bb_error_msg_and_die("%s(%i): wrong map line",
    205143                         mapFile, maplineno);
    206144
    207         if (!strcmp(fn_name,"_stext")) /* only elf works like this */ {
     145        if (!strcmp(fn_name, "_stext")) /* only elf works like this */ {
    208146            add0 = fn_add;
    209147            break;
     
    218156     * Main loop.
    219157     */
    220     while (fgets(mapline,S_LEN,map)) {
     158    while (fgets(mapline, S_LEN, map)) {
    221159        unsigned int this = 0;
    222160
    223         if (sscanf(mapline,"%llx %s %s",&next_add,mode,next_name) != 3)
     161        if (sscanf(mapline, "%llx %s %s", &next_add, mode, next_name) != 3)
    224162            bb_error_msg_and_die("%s(%i): wrong map line",
    225                          mapFile, maplineno);
     163                    mapFile, maplineno);
    226164
    227165        header_printed = 0;
     
    241179            if (optBins && (buf[indx] || optAll)) {
    242180                if (!header_printed) {
    243                     printf ("%s:\n", fn_name);
     181                    printf("%s:\n", fn_name);
    244182                    header_printed = 1;
    245183                }
    246                 printf ("\t%"PRIx64"\t%u\n", (indx - 1)*step + add0, buf[indx]);
     184                printf("\t%"PRIx64"\t%u\n", (indx - 1)*step + add0, buf[indx]);
    247185            }
    248186            this += buf[indx++];
     
    252190        if (optBins) {
    253191            if (optVerbose || this > 0)
    254                 printf ("  total\t\t\t\t%u\n", this);
     192                printf("  total\t\t\t\t%u\n", this);
    255193        } else if ((this || optAll) &&
    256194               (fn_len = next_add-fn_add) != 0) {
    257195            if (optVerbose)
    258196                printf("%016llx %-40s %6i %8.4f\n", fn_add,
    259                        fn_name,this,this/(double)fn_len);
     197                       fn_name, this, this/(double)fn_len);
    260198            else
    261199                printf("%6i %-40s %8.4f\n",
    262                        this,fn_name,this/(double)fn_len);
     200                       this, fn_name, this/(double)fn_len);
    263201            if (optSub) {
    264202                unsigned long long scan;
     
    277215
    278216        fn_add = next_add;
    279         strcpy(fn_name,next_name);
     217        strcpy(fn_name, next_name);
    280218
    281219        maplineno++;
     
    288226    if (optVerbose)
    289227        printf("%016x %-40s %6i %8.4f\n",
    290                0,"total",total,total/(double)(fn_add-add0));
     228               0, "total", total, total/(double)(fn_add-add0));
    291229    else
    292230        printf("%6i %-40s %8.4f\n",
    293                total,"total",total/(double)(fn_add-add0));
     231               total, "total", total/(double)(fn_add-add0));
    294232
    295233    fclose(map);
Note: See TracChangeset for help on using the changeset viewer.