[wiki] [sites] Changed smprintf to use vasprintf. Remove french code. || Thuban
commit 978b81a2602be9e5549c01e0cbeaa6b92e3bd533
Author: Thuban <thuban_AT_singularity.fr>
Date: Mon Dec 24 10:06:13 2012 +0100
Changed smprintf to use vasprintf. Remove french code.
diff --git a/dwm.suckless.org/dwmstatus/mail_counter.c b/dwm.suckless.org/dwmstatus/mail_counter.c
index 69d0893..e044ab7 100644
--- a/dwm.suckless.org/dwmstatus/mail_counter.c
+++ b/dwm.suckless.org/dwmstatus/mail_counter.c
_AT_@ -3,6 +3,7 @@
// Dernière modification: 21 déc. 2012 16:25:16
#define _BSD_SOURCE
+#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
_AT_@ -23,25 +24,18 @@ char *
smprintf(char *fmt, ...)
{
va_list fmtargs;
- char *ret;
- int len;
+ char *buf = NULL;
va_start(fmtargs, fmt);
- len = vsnprintf(NULL, 0, fmt, fmtargs);
- va_end(fmtargs);
-
- ret = malloc(++len);
- if (ret == NULL) {
- perror("malloc");
+ if (vasprintf(&buf, fmt, fmtargs) == -1){
+ fprintf(stderr, "malloc vasprintf
");
exit(1);
- }
-
- va_start(fmtargs, fmt);
- vsnprintf(ret, len, fmt, fmtargs);
+ }
va_end(fmtargs);
- return ret;
+ return buf;
}
+
void
setstatus(char *str)
{
_AT_@ -51,9 +45,10 @@ setstatus(char *str)
char *get_nmail(char *directory, char *label)
{
- /* directory can be a Maildir as example */
- /* label is whet will be shown as title*/
-
+ /* directory : Maildir path
+ * return label : number_of_new_mails
+ */
+
int n = 0;
DIR* dir = NULL;
struct dirent* rf = NULL;
_AT_@ -81,7 +76,7 @@ int
main(void)
{
char *status;
- char *mail_laposte;
+ char *newmails;
if (!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "dwmstatus: cannot open display.
");
_AT_@ -89,12 +84,12 @@ main(void)
}
for (;;sleep(60)) {
- mail_laposte = get_nmail("/home/xavier/Maildir/laposte/new", "Laposte:");
+ newmails = get_nmail("/home/xavier/Maildir/laposte/new", "Mails:");
- status = smprintf("%s",mail_laposte);
+ status = smprintf("%s",newmails);
setstatus(status);
- free(mail_laposte);
+ free(newmails);
free(status);
}
Received on Mon Dec 24 2012 - 10:06:53 CET
This archive was generated by hypermail 2.3.0
: Mon Dec 24 2012 - 10:12:03 CET