X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ffacility.c;h=47db6b80c29c7108fc1e1b0e95162814b339bc39;hb=b37f012bdefea9d1817e15d85c2958bb2a50c81d;hp=55077aa3d1d713b529d8f561791bcfdd68e2827a;hpb=cf74a6f1dc8fdeb7f7216d1c22f89fff405f9df1;p=lttv.git diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index 55077aa3..47db6b80 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -19,12 +19,20 @@ #include #include #include +#include +#include +#include +#include + + #include "parser.h" #include #include "ltt-private.h" #include +#define g_close close + /* search for the (named) type in the table, if it does not exist create a new one */ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td); @@ -53,31 +61,36 @@ void freeLttNamedType(LttType * type); * pathname : the path name of the facility ****************************************************************************/ -void ltt_facility_open(LttTrace * t, char * pathname) +void ltt_facility_open(LttTrace * t, gchar * pathname) { - char *token; + gchar *token; parse_file in; - char buffer[BUFFER_SIZE]; + gsize length; facility_t * fac; LttFacility * f; LttChecksum checksum; + GError * error = NULL; + gchar buffer[BUFFER_SIZE]; - in.buffer = buffer; + in.buffer = &(buffer[0]); in.lineno = 0; in.error = error_callback; in.name = pathname; - in.fp = fopen(in.name, "r"); - if(!in.fp ) in.error(&in,"cannot open input file"); + in.fd = g_open(in.name, O_RDONLY, 0); + if(in.fd < 0 ) in.error(&in,"cannot open input file"); + + in.channel = g_io_channel_unix_new(in.fd); + in.pos = 0; while(1){ token = getToken(&in); if(in.type == ENDFILE) break; - if(strcmp(token, "<")) in.error(&in,"not a facility file"); + if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file"); token = getName(&in); - - if(strcmp("facility",token) == 0) { + + if(g_ascii_strcasecmp("facility",token) == 0) { fac = g_new(facility_t, 1); fac->name = NULL; fac->description = NULL; @@ -99,8 +112,8 @@ void ltt_facility_open(LttTrace * t, char * pathname) t->facility_number++; g_ptr_array_add(t->facilities,f); - free(fac->name); - free(fac->description); + g_free(fac->name); + g_free(fac->description); freeEvents(&fac->events); sequence_dispose(&fac->events); freeNamedType(&fac->named_types); @@ -111,7 +124,14 @@ void ltt_facility_open(LttTrace * t, char * pathname) } else in.error(&in,"facility token was expected"); } - fclose(in.fp); + + g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */ + if(error != NULL) { + g_warning("Can not close file: \n%s\n", error->message); + g_error_free(error); + } + + g_close(in.fd); } @@ -287,13 +307,13 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) { LttType * lttType = NULL; unsigned int i=0; - char * name; + gchar * name; if(td->type_name){ for(i=0;inamed_types_number; i++){ if(fac->named_types[i] == NULL) break; name = fac->named_types[i]->type_name; - if(strcmp(name, td->type_name)==0){ + if(g_ascii_strcasecmp(name, td->type_name)==0){ lttType = fac->named_types[i]; // if(lttType->element_name) g_free(lttType->element_name); // lttType->element_name = NULL; @@ -449,7 +469,7 @@ void freeLttField(LttField * fld) * char * : the facility's name ****************************************************************************/ -char *ltt_facility_name(LttFacility *f) +gchar *ltt_facility_name(LttFacility *f) { return f->name; } @@ -523,14 +543,14 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i) * LttEventType * : the event type required ****************************************************************************/ -LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name) +LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, gchar *name) { unsigned int i; LttEventType * ev = NULL; for(i=0;ievent_number;i++){ LttEventType *iter_ev = f->events[i]; - if(strcmp(iter_ev->name, name) == 0) { + if(g_ascii_strcasecmp(iter_ev->name, name) == 0) { ev = iter_ev; break; }