~ubuntu-branches/ubuntu/trusty/linuxlogo/trusty

« back to all changes in this revision

Viewing changes to libsysinfo-0.1.0/all/random_stuff.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-06-20 09:19:00 UTC
  • mfrom: (4.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080620091900-4xzuv7c7ntxvs7wt
Tags: 5.03-4
* Adding patch to fix FTBFS on s390x.
* Updating to standards 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* sysinfo_common.h                                               *\
2
 
\* Just trying to cut back on overly-repeated code.  --vmw        */
3
 
 
4
 
#include "getsysinfo.h"
5
 
 
6
 
char *linux_get_proc_uptime () 
7
 
{            /* This code modeled on the linux sh-utils 1.16 uptime.c code */
8
 
    FILE *fff;
9
 
    float uptime_seconds;
10
 
    int up_days,up_hrs,up_mins;
11
 
    char temp_string[BUFSIZ];
12
 
   
13
 
    fff=fopen("/proc/uptime","r");
14
 
    if (fff!=NULL) {
15
 
       fscanf(fff,"%f",&uptime_seconds);
16
 
       fclose (fff);
17
 
    
18
 
       up_days=uptime_seconds/86400;
19
 
       up_hrs=(uptime_seconds-(up_days*86400))/3600;
20
 
       up_mins=(uptime_seconds-(up_days*86400)-(up_hrs*3600))/60;
21
 
  
22
 
       if (up_days<=0) 
23
 
          sprintf(temp_string,"Uptime %d %s %d %s",
24
 
                  up_hrs,(up_hrs==1 ? "hour":"hours"),
25
 
                  up_mins,(up_mins==1 ? "minute":"minutes"));
26
 
       else 
27
 
          sprintf(temp_string,"Uptime %d %s %d %s %d %s",
28
 
                  up_days,(up_days==1 ? "day":"days"),
29
 
                  up_hrs,(up_hrs==1 ? "hour":"hours"),
30
 
                  up_mins,(up_mins==1 ? "minute":"minutes"));
31
 
       return strdup(temp_string);
32
 
    }
33
 
    return NULL;
34
 
}
35
 
 
36
 
    /* Code contributed by Anders Rundegren <anders@rundegren.com> */
37
 
char *linux_get_proc_loadavg()
38
 
{
39
 
    FILE *fff;
40
 
    float load_1;
41
 
    float load_5;
42
 
    float load_15;
43
 
    char temp_string[BUFSIZ];
44
 
   
45
 
    fff=fopen("/proc/loadavg","r");
46
 
    if (fff!=NULL) {
47
 
       fscanf(fff,"%f" "%f" "%f", &load_1, &load_5, &load_15);
48
 
       fclose (fff);
49
 
        
50
 
       sprintf(temp_string,"Load average %4.2f, %4.2f, %4.2f",
51
 
               load_1,load_5,load_15);
52
 
       return strdup(temp_string);
53
 
    }
54
 
    return NULL;
55
 
}
56
 
   
57
 
char *get_loadavg_noproc() 
58
 
{
59
 
    /* Unfortunately it seems getting the load-average is platform *\
60
 
    \* dependant.                                                  */
61
 
    return NULL;
62
 
}
63
 
 
64
 
char *utmp_get_uptime() 
65
 
{
66
 
    /* To implement uptime on architechtures w/o a /proc/uptime one *\
67
 
    \* has to scan the /var/utmp file.  Very annoying thing to do   */
68
 
    /* Check out the linux sh-utils uptime.c for a reference.       *\
69
 
    \* Currently not implemented here.                              */
70
 
    return NULL;
71
 
   
72
 
}
73
 
 
74
 
void clear_os_pointers(struct os_info_type *os_info) 
75
 
{
76
 
    os_info->os_name=NULL;
77
 
    os_info->os_version=NULL;
78
 
    os_info->os_revision=NULL;
79
 
    os_info->host_name=NULL;
80
 
    os_info->uptime=NULL;
81
 
    os_info->load_average=NULL; 
82
 
}
83
 
 
84
 
void clear_hw_pointers(struct hw_info_type *hw_info)
85
 
{
86
 
    hw_info->num_cpus=0;
87
 
    hw_info->bogo_total=NULL;
88
 
    hw_info->megahertz=NULL;
89
 
    hw_info->cpu_vendor=NULL;
90
 
    hw_info->cpu_type=NULL;
91
 
    hw_info->mem_size=NULL;
92
 
}