- struct stat lTDFStat; /* Trace data file status */
- ltt_subbuffer_header_t *header;
- int page_size = getpagesize();
-
- //open the file
- tf->long_name = g_quark_from_string(fileName);
- tf->fd = open(fileName, O_RDONLY);
- tf->buf_index = NULL;
- if(tf->fd < 0){
- g_warning("Unable to open input data file %s\n", fileName);
- goto end;
- }
-
- // Get the file's status
- if(fstat(tf->fd, &lTDFStat) < 0){
- g_warning("Unable to get the status of the input data file %s\n", fileName);
- goto close_file;
- }
-
- // Is the file large enough to contain a trace
- if(lTDFStat.st_size <
- (off_t)(ltt_subbuffer_header_size())){
- g_print("The input data file %s does not contain a trace\n", fileName);
- goto close_file;
- }
-
- /* Temporarily map the buffer start header to get trace information */
- /* Multiple of pages aligned head */
- tf->buffer.head = mmap(0,
- PAGE_ALIGN(ltt_subbuffer_header_size()), PROT_READ,
- MAP_PRIVATE, tf->fd, 0);
- if(tf->buffer.head == MAP_FAILED) {
- perror("Error in allocating memory for buffer of tracefile");
- goto close_file;
- }
- g_assert( ( (gulong)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
-
- header = (ltt_subbuffer_header_t *)tf->buffer.head;
-
-
- return header;
-
- /* Error */
-
-close_file:
- close(tf->fd);
-end:
- if (tf->buf_index)
- g_array_free(tf->buf_index, TRUE);
- return 0;
+ struct stat lTDFStat; /* Trace data file status */
+ ltt_subbuffer_header_t *header;
+ int page_size = getpagesize();
+
+ /* open the file */
+ tf->long_name = g_quark_from_string(fileName);
+ tf->fd = open(fileName, O_RDONLY);
+ if(tf->fd < 0){
+ g_warning("Unable to open input data file %s\n", fileName);
+ goto end;
+ }
+
+ /* Get the file's status */
+ if(fstat(tf->fd, &lTDFStat) < 0){
+ g_warning("Unable to get the status of the input data file %s\n", fileName);
+ goto close_file;
+ }
+
+ /* Is the file large enough to contain a trace */
+ if(lTDFStat.st_size < (off_t)(ltt_subbuffer_header_size())) {
+ g_print("The input data file %s does not contain a trace\n", fileName);
+ goto close_file;
+ }
+
+ /* Temporarily map the buffer start header to get trace information */
+ /* Multiple of pages aligned head */
+ tf->buffer.head = mmap(0,PAGE_ALIGN(ltt_subbuffer_header_size()), PROT_READ, MAP_PRIVATE, tf->fd, 0);
+
+ if(tf->buffer.head == MAP_FAILED) {
+ perror("Error in allocating memory for buffer of tracefile");
+ goto close_file;
+ }
+ g_assert( ( (gulong)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
+
+ header = (ltt_subbuffer_header_t *)tf->buffer.head;
+
+ return header;
+
+ close_file:
+ close(tf->fd);
+ end:
+ return 0;