]> www.infradead.org Git - users/dwmw2/ews-sync.git/commitdiff
Use portable glib functions instead of asprintf and strndup
authorFridrich Štrba <fridrich.strba@bluewin.ch>
Mon, 19 Jul 2010 08:20:52 +0000 (10:20 +0200)
committerDavid Woodhouse <dwmw2@infradead.org>
Mon, 19 Jul 2010 08:51:17 +0000 (09:51 +0100)
Makefile
ews2ical.c
ews_autodiscover.c

index b5f712075b11463fc565c9f6e50d8ce663c3526a..be1d402c642bbe786c65aed773f2a14a20f6779c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,17 +23,29 @@ ifeq ($(ICAL_LDFLAGS),)
 $(error "No libical support. Cannot continue");
 endif
 
-CFLAGS := $(OPT_FLAGS) $(XML2_CFLAGS)
+GLIB_CFLAGS += $(shell pkg-config glib-2.0 --cflags)
+GLIB_LDFLAGS += $(shell pkg-config glib-2.0 --libs)
+ifeq ($(GLIB_LDFLAGS),)
+$(error "No glib support. Cannot continue");
+endif
+
+
+CFLAGS := $(OPT_FLAGS) $(XML2_CFLAGS) $(GLIB_CFLAGS)
 CFLAGS_ews_autodiscover.o := $(SOUP_CFLAGS)
 CFLAGS_ews2ical.o := $(ICAL_CFLAGS)
 
 %.o: %.c
        $(CC) -c -o $@ $(CFLAGS) $(CFLAGS_$@) $< -MD -MF .$@.dep
 
-all: ews_autodiscover ews2ical
+PROGS := ews_autodiscover ews2ical
+
+all: $(PROGS)
+
+clean:
+       rm -f $(PROGS) *.o .*.o.dep
 
 ews2ical: ews2ical.o
-       $(CC) -o $@ $< $(LDFLAGS) $(XML2_LDFLAGS) $(ICAL_LDFLAGS)
+       $(CC) -o $@ $< $(LDFLAGS) $(XML2_LDFLAGS) $(ICAL_LDFLAGS) $(GLIB_LDFLAGS)
 
 ews_autodiscover: ews_autodiscover.o
-       $(CC) -o $@ $< $(LDFLAGS) $(XML2_LDFLAGS) $(SOUP_LDFLAGS)
+       $(CC) -o $@ $< $(LDFLAGS) $(XML2_LDFLAGS) $(SOUP_LDFLAGS) $(GLIB_LDFLAGS)
index b1918e18e90b191b01484ec83761bc3263545a4a..a0739e884f7feb1b87002fe64ed0c39d5c766a1b 100644 (file)
@@ -1,4 +1,3 @@
-#define _GNU_SOURCE /* for asprintf */
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
 #include <libical/icaltime.h>
 #include <libical/icalduration.h>
 #include <libical/icaltimezone.h>
+
+#include <glib.h>
+#include <glib/gprintf.h>
+
 FILE *calfile;
 
 int process_relativeyearlyrecurrence(xmlNode *xml_node, struct icalrecurrencetype *ical_recur);
@@ -271,7 +274,7 @@ int process_organizer(icalcomponent *comp, xmlNode *xml_node)
                        if (process_mailbox(xml_node, &name, &email))
                                return -1;
 
-                       asprintf(&mailtoname, "mailto:%s", email);
+                       mailtoname = g_strdup_printf("mailto:%s", email);
                        
                        prop = icalproperty_new_organizer(mailtoname);
                        free(mailtoname);
@@ -297,7 +300,7 @@ int process_attendee(icalcomponent *comp, xmlNode *xml_node, icalparameter_role
                        if (process_mailbox(xml_node, &name, &email))
                                return -1;
 
-                       asprintf(&mailtoname, "mailto:%s", email);
+                       mailtoname = g_strdup_printf("mailto:%s", email);
                        
                        prop = icalproperty_new_attendee(mailtoname);
                        free(mailtoname);
@@ -976,7 +979,7 @@ static int weekdays_to_recur_byday(const char *days, struct icalrecurrencetype *
        do {
                space = strchr(days, ' ');
                if (space)
-                       day = strndup(days, space - days);
+                       day = g_strndup(days, space - days);
                else
                        day = days;
 
index a0b5ff364655b52bd24a61d44f2af41d1c2f21aa..0514ba5475ef7ae709e384a12af1bd621d304178 100644 (file)
@@ -1,5 +1,3 @@
-#define _GNU_SOURCE
-
 #include <libsoup/soup.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -55,7 +53,7 @@ int main(int argc, char **argv)
        
         g_thread_init (NULL);
         g_type_init ();
-       asprintf(&url, "https://autodiscover.%s/autodiscover/autodiscover.xml", domain);
+       url = g_strdup_printf("https://autodiscover.%s/autodiscover/autodiscover.xml", domain);
 
        sess = soup_session_sync_new_with_options(SOUP_SESSION_USE_NTLM, TRUE, NULL);
        g_signal_connect (sess, "authenticate",