XINU
Functions
xsh_uptime.c File Reference
#include <xinu.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for xsh_uptime.c:

Go to the source code of this file.

Functions

shellcmd xsh_uptime (int nargs, char *args[])
 

Function Documentation

◆ xsh_uptime()

shellcmd xsh_uptime ( int  nargs,
char *  args[] 
)

Definition at line 11 of file xsh_uptime.c.

References clktime, fprintf(), printf(), stderr, and strncmp().

12 {
13  uint32 days, hrs, mins, secs; /* days, hours, minutes, and */
14  /* seconds since system boot */
15  uint32 secperday = 86400; /* seconds in a day */
16  uint32 secperhr = 3600; /* seconds in an hour */
17  uint32 secpermin = 60; /* seconds in a minute */
18 
19  /* For argument '--help', emit help about the 'uptime' command */
20 
21  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
22  printf("Use: %s\n\n", args[0]);
23  printf("Description:\n");
24  printf("\tDisplays time since the system booted\n");
25  printf("Options:\n");
26  printf("\t--help\t display this help and exit\n");
27  return 0;
28  }
29 
30  /* Check for valid number of arguments */
31 
32  if (nargs > 1) {
33  fprintf(stderr, "%s: too many arguments\n", args[0]);
34  fprintf(stderr, "Try '%s --help' for more information\n",
35  args[0]);
36  return 1;
37  }
38 
39  secs = clktime; /* total seconds since boot */
40 
41  /* subtract number of whole days */
42 
43  days = secs/secperday;
44  secs -= days*secperday;
45 
46  /* subtract number of hours */
47 
48  hrs = secs/secperhr;
49  secs -= hrs*secperhr;
50 
51  /* subtract number of minutes */
52 
53  mins = secs/secpermin;
54  secs -= mins*secpermin;
55 
56  printf("Xinu has been up ");
57  if (days > 0) {
58  printf(" %d day(s) ", days);
59  }
60 
61  if (hrs > 0) {
62  printf(" %d hour(s) ", hrs);
63  }
64 
65  if (mins > 0) {
66  printf(" %d minute(s) ", mins);
67  }
68 
69  if (secs > 0) {
70  printf(" %d second(s) ", secs);
71  }
72  printf("\n");
73 
74  return 0;
75 }
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
uint32 clktime
起動してからの現在の時間[s]
Definition: clkinit.c:5
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the call graph for this function: