perf tools: Use O_LARGEFILE to open perf data file
[safe/jmp/linux-2.6] / tools / perf / util / trace-event-read.c
index b12e490..ca3c26d 100644 (file)
@@ -83,7 +83,7 @@ static char *read_string(void)
        char *str = NULL;
        int size = 0;
        int i;
-       int r;
+       s64 r;
 
        for (;;) {
                r = read(input_fd, buf, BUFSIZ);
@@ -113,8 +113,11 @@ static char *read_string(void)
                }
        }
 
+       /* trailing \0: */
+       i++;
+
        /* move the file descriptor to the end of the string */
-       r = lseek(input_fd, -(r - (i+1)), SEEK_CUR);
+       r = lseek64(input_fd, -(r - i), SEEK_CUR);
        if (r < 0)
                die("lseek");
 
@@ -142,8 +145,9 @@ static void read_proc_kallsyms(void)
        if (!size)
                return;
 
-       buf = malloc_or_die(size);
+       buf = malloc_or_die(size + 1);
        read_or_die(buf, size);
+       buf[size] = '\0';
 
        parse_proc_kallsyms(buf, size);
 
@@ -455,29 +459,28 @@ struct record *trace_read_data(int cpu)
        return data;
 }
 
-void trace_report (void)
+void trace_report(int fd)
 {
-       const char *input_file = "trace.info";
        char buf[BUFSIZ];
        char test[] = { 23, 8, 68 };
        char *version;
+       int show_version = 0;
        int show_funcs = 0;
        int show_printk = 0;
 
-       input_fd = open(input_file, O_RDONLY);
-       if (input_fd < 0)
-               die("opening '%s'\n", input_file);
+       input_fd = fd;
 
        read_or_die(buf, 3);
        if (memcmp(buf, test, 3) != 0)
-               die("not an trace data file");
+               die("no trace data in the file");
 
        read_or_die(buf, 7);
        if (memcmp(buf, "tracing", 7) != 0)
-               die("not a trace file (missing tracing)");
+               die("not a trace file (missing 'tracing' tag)");
 
        version = read_string();
-       printf("version = %s\n", version);
+       if (show_version)
+               printf("version = %s\n", version);
        free(version);
 
        read_or_die(buf, 1);