-char *
-cpu_perc(const char *null)
-{
- int perc;
- long double a[4], b[4];
- FILE *fp;
-
- if (!(fp = fopen("/proc/stat","r"))) {
- fprintf(stderr, "Error opening stat file.\n");
- return smprintf(unknowntext);
- }
-
- fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2], &a[3]);
- fclose(fp);
-
- /* wait a second (for avg values) */
- sleep(1);
-
- if (!(fp = fopen("/proc/stat","r"))) {
- fprintf(stderr, "Error opening stat file.\n");
- return smprintf(unknowntext);
- }
-
- fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &b[0], &b[1], &b[2], &b[3]);
- fclose(fp);
- perc = 100 * ((b[0]+b[1]+b[2]) - (a[0]+a[1]+a[2])) / ((b[0]+b[1]+b[2]+b[3]) - (a[0]+a[1]+a[2]+a[3]));
- return smprintf("%d%%", perc);
-}
-
-char *
-datetime(const char *timeformat)
-{
- time_t tm;
- size_t bufsize = 64;
- char *buf = malloc(bufsize);
- if (buf == NULL) {
- fprintf(stderr, "Failed to get date/time.\n");
- return smprintf(unknowntext);
- }
-
- time(&tm);
- setlocale(LC_TIME, "");
- if (!strftime(buf, bufsize, timeformat, localtime(&tm))) {
- setlocale(LC_TIME, "C");
- free(buf);
- fprintf(stderr, "Strftime failed.\n");
- return smprintf(unknowntext);
- }
-
- setlocale(LC_TIME, "C");
- char *ret = smprintf("%s", buf);
- free(buf);
- return ret;
-}
-
-char *
-disk_free(const char *mountpoint)
-{
- struct statvfs fs;
-
- if (statvfs(mountpoint, &fs) < 0) {
- fprintf(stderr, "Could not get filesystem info.\n");
- return smprintf(unknowntext);
- }
- return smprintf("%f", (float)fs.f_bsize * (float)fs.f_bfree / 1024 / 1024 / 1024);
-}
-
-char *
-disk_perc(const char *mountpoint)
-{
- int perc = 0;
- struct statvfs fs;
-
- if (statvfs(mountpoint, &fs) < 0) {
- fprintf(stderr, "Could not get filesystem info.\n");
- return smprintf(unknowntext);
- }
-
- perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks));
- return smprintf("%d%%", perc);
-}
-
-char *
-disk_total(const char *mountpoint)
-{
- struct statvfs fs;
-
- if (statvfs(mountpoint, &fs) < 0) {
- fprintf(stderr, "Could not get filesystem info.\n");
- return smprintf(unknowntext);
- }
-
- return smprintf("%f", (float)fs.f_bsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
-}
-
-char *
-disk_used(const char *mountpoint)
-{
- struct statvfs fs;
-
- if (statvfs(mountpoint, &fs) < 0) {
- fprintf(stderr, "Could not get filesystem info.\n");
- return smprintf(unknowntext);
- }
-
- return smprintf("%f", (float)fs.f_bsize * ((float)fs.f_blocks - (float)fs.f_bfree) / 1024 / 1024 / 1024);
-}
-
-char *
-entropy(const char *null)
-{
- int entropy = 0;
- FILE *fp;
-
- if (!(fp = fopen("/proc/sys/kernel/random/entropy_avail", "r"))) {
- fprintf(stderr, "Could not open entropy file.\n");
- return smprintf(unknowntext);
- }
-
- fscanf(fp, "%d", &entropy);
- fclose(fp);
- return smprintf("%d", entropy);
-}
-
-char *
-gid(const char *null)
-{
- gid_t gid;
-
- if ((gid = getgid()) < 0) {
- fprintf(stderr, "Could no get gid.\n");
- return smprintf(unknowntext);
- } else
- return smprintf("%d", gid);
- return smprintf(unknowntext);
-}
-
-char *
-hostname(const char *null)
-{
- char hostname[HOST_NAME_MAX];
- FILE *fp;