[wiki] [sites] [dwmstatus] uptime informations || Thuban

From: <git_AT_suckless.org>
Date: Fri, 26 Apr 2013 22:14:41 +0200

commit 8dbfb2812cd8009447efd37fb34424725adda0c8
Author: Thuban <thuban_AT_singularity.fr>
Date: Fri Apr 26 22:14:32 2013 +0200

    [dwmstatus] uptime informations

diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md
index 063a691..52e0e8f 100644
--- a/dwm.suckless.org/dwmstatus/index.md
+++ b/dwm.suckless.org/dwmstatus/index.md
_AT_@ -39,6 +39,7 @@ add them here as file or as code example.
 * [Show line per line the content of a file](dynamic_info.c) : See
   tmpinfo function. It prints line after line the content of
   /tmp/dwmbuf.
+* [Simple function to have uptime](uptime.c)
 
 Questions
 ---------
diff --git a/dwm.suckless.org/dwmstatus/uptime.c b/dwm.suckless.org/dwmstatus/uptime.c
new file mode 100644
index 0000000..0379166
--- /dev/null
+++ b/dwm.suckless.org/dwmstatus/uptime.c
_AT_@ -0,0 +1,164 @@
+#define _BSD_SOURCE
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/time.h>
+#include <sys/sysinfo.h>
+#include <time.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/statvfs.h>
+
+
+#include <X11/Xlib.h>
+
+char *tzparis = "Europe/Paris";
+
+static Display *dpy;
+
+char *
+smprintf(char *fmt, ...)
+{
+ va_list fmtargs;
+ char *buf = NULL;
+
+ va_start(fmtargs, fmt);
+ if (vasprintf(&buf, fmt, fmtargs) == -1){
+ fprintf(stderr, "malloc vasprintf
");
+ exit(1);
+ }
+ va_end(fmtargs);
+
+ return buf;
+}
+
+char*
+runcmd(char* cmd) {
+ FILE* fp = popen(cmd, "r");
+ if (fp == NULL) return NULL;
+ char ln[50];
+ fgets(ln, sizeof(ln)-1, fp);
+ pclose(fp);
+ ln[strlen(ln)-1]='
Received on Fri Apr 26 2013 - 22:14:41 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 26 2013 - 22:24:11 CEST