From: Fridrich Štrba Date: Mon, 19 Jul 2010 08:20:52 +0000 (+0200) Subject: Use portable glib functions instead of asprintf and strndup X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c2a139139af875a8b7463fda6329410a4698f304;p=users%2Fdwmw2%2Fews-sync.git Use portable glib functions instead of asprintf and strndup --- diff --git a/Makefile b/Makefile index b5f7120..be1d402 100644 --- 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) diff --git a/ews2ical.c b/ews2ical.c index b1918e1..a0739e8 100644 --- a/ews2ical.c +++ b/ews2ical.c @@ -1,4 +1,3 @@ -#define _GNU_SOURCE /* for asprintf */ #include #include @@ -14,6 +13,10 @@ #include #include #include + +#include +#include + 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; diff --git a/ews_autodiscover.c b/ews_autodiscover.c index a0b5ff3..0514ba5 100644 --- a/ews_autodiscover.c +++ b/ews_autodiscover.c @@ -1,5 +1,3 @@ -#define _GNU_SOURCE - #include #include #include @@ -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",