suwako / farfetch アーカイブ

このリポジトリはアーカイブされています。読むだけで、プッシュやイシューの変更は出来ません。

master
ブランチ master
farfetch / src / uptime.c
957 B、41行 生 Blame 履歴
1#include "uptime.h"
2#include "common.h"
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8const char *display_days() {
9 const char *days = run_command_s("uptime | awk '{for (i=1; i<=NF; i++) "
10 "if ($i ~ /day/) print $(i-1), $i}'");
11
12 if (days == NULL || strlen(days) == 0) {
13 return strndup("0 days,", 7);
14 }
15
16 return days;
17}
18
19const char *display_time() {
20 const char *uptime = run_command_s("uptime");
21 if (uptime == NULL) {
22 return NULL;
23 }
24
25 char *days = strstr(uptime, "day");
26 int nodays = 0;
27 if (days == NULL) {
28 nodays = 1;
29 days = strstr(uptime, "days");
30 }
31
32 free((void *)uptime);
33
34 if (nodays) {
35 return run_command_s("uptime | awk '{print $3}' | sed 's/,//' | "
36 "sed 's/:/ hours, /' && echo \" mins\"");
37 }
38
39 return run_command_s("uptime | awk '{print $5}' | sed 's/,//' | "
40 "sed 's/:/ hours, /' && echo \" mins\"");
41}