init pos cleanup
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 6 May 2011 23:04:22 +0000 (19:04 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 6 May 2011 23:04:22 +0000 (19:04 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/types/float.c
formats/ctf/types/string.c
include/babeltrace/ctf/types.h
tests/test-dummytrace.c

index 8556055e8ab2f5f1b921068e237a67ccee79a69b..d214d1aae4f25c0bd4d0c9b027187aa9b1113abc 100644 (file)
@@ -76,7 +76,7 @@ struct format ctf_format = {
        .close_trace = ctf_close_trace,
 };
 
-void ctf_init_pos(struct ctf_stream_pos *pos, int fd)
+void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags)
 {
        pos->fd = fd;
        pos->mmap_offset = 0;
@@ -86,29 +86,29 @@ void ctf_init_pos(struct ctf_stream_pos *pos, int fd)
        pos->base = NULL;
        pos->offset = 0;
        pos->dummy = false;
-       pos->packet_index = g_array_new(FALSE, TRUE,
-                                       sizeof(struct packet_index));
        pos->cur_index = 0;
-       if (fd >= 0) {
-               int flags = fcntl(fd, F_GETFL, 0);
-
-               switch (flags & O_ACCMODE) {
-               case O_RDONLY:
-                       pos->prot = PROT_READ;
-                       pos->flags = MAP_PRIVATE;
-                       pos->parent.rw_table = read_dispatch_table;
-                       break;
-               case O_WRONLY:
-               case O_RDWR:
-                       pos->prot = PROT_WRITE; /* Write has priority */
-                       pos->flags = MAP_SHARED;
-                       pos->parent.rw_table = write_dispatch_table;
-                       ctf_move_pos_slow(pos, 0);      /* position for write */
-                       break;
-               default:
-                       assert(0);
-               }
+       if (fd >= 0)
+               pos->packet_index = g_array_new(FALSE, TRUE,
+                                               sizeof(struct packet_index));
+       else
+               pos->packet_index = NULL;
 
+       switch (open_flags & O_ACCMODE) {
+       case O_RDONLY:
+               pos->prot = PROT_READ;
+               pos->flags = MAP_PRIVATE;
+               pos->parent.rw_table = read_dispatch_table;
+               break;
+       case O_WRONLY:
+       case O_RDWR:
+               pos->prot = PROT_WRITE; /* Write has priority */
+               pos->flags = MAP_SHARED;
+               pos->parent.rw_table = write_dispatch_table;
+               if (fd >= 0)
+                       ctf_move_pos_slow(pos, 0);      /* position for write */
+               break;
+       default:
+               assert(0);
        }
 }
 
@@ -453,7 +453,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
        if (ret < 0)
                goto error;
        file_stream = g_new0(struct ctf_file_stream, 1);
-       ctf_init_pos(&file_stream->pos, ret);
+       ctf_init_pos(&file_stream->pos, ret, flags);
        ret = create_stream_packet_index(td, file_stream);
        if (ret)
                goto error_index;
index a30c3ea4903f025ad1ffaed31a3db1a230476747..8bb3f743be2a27bc0e79cbf8380093ce5a6797ef 100644 (file)
@@ -120,7 +120,7 @@ void ctf_float_read(struct stream_pos *ppos, struct definition *definition)
                container_of(tmpdef, struct definition_float, p);
        struct ctf_stream_pos destp;
 
-       ctf_init_pos(&destp, -1);
+       ctf_init_pos(&destp, -1, O_WRONLY);
        destp.base = (char *) u.bits;
 
        ctf_align_pos(pos, float_declaration->p.alignment);
@@ -144,7 +144,7 @@ void ctf_float_write(struct stream_pos *ppos, struct definition *definition)
                container_of(tmpdef, struct definition_float, p);
        struct ctf_stream_pos srcp;
 
-       ctf_init_pos(&srcp, -1);
+       ctf_init_pos(&srcp, -1, O_RDONLY);
        srcp.base = (char *) u.bits;
 
        u.v = float_definition->value;
index b19335e2b860d4418fde30cb0d4526726896e048..b648b817aecb4944e462e29c6726a77c918c12cb 100644 (file)
 #include <limits.h>            /* C99 limits */
 #include <string.h>
 
-void ctf_string_copy(struct stream_pos *pdest, struct stream_pos *psrc,
-                    const struct declaration_string *string_declaration)
-{
-       struct ctf_stream_pos *dest = ctf_pos(pdest);
-       struct ctf_stream_pos *src = ctf_pos(psrc);
-       size_t len;
-       char *destaddr, *srcaddr;
-
-       ctf_align_pos(src, string_declaration->p.alignment);
-       srcaddr = ctf_get_pos_addr(src);
-       len = strlen(srcaddr) + 1;
-       if (dest->dummy)
-               goto end;
-       ctf_align_pos(dest, string_declaration->p.alignment);
-       destaddr = ctf_get_pos_addr(dest);
-       strcpy(destaddr, srcaddr);
-end:
-       ctf_move_pos(dest, len);
-       ctf_move_pos(src, len);
-}
-
 void ctf_string_read(struct stream_pos *ppos, struct definition *definition)
 {
        struct definition_string *string_definition =
@@ -81,7 +60,7 @@ void ctf_string_write(struct stream_pos *ppos,
        if (pos->dummy)
                goto end;
        destaddr = ctf_get_pos_addr(pos);
-       strcpy(destaddr, string_definition->value);
+       memcpy(destaddr, string_definition->value, len);
 end:
        ctf_move_pos(pos, len);
 }
index 121beda575c401939248bc171673a60eb30ff074..9a1a4d41c4569015a2bd7b6cb812f5ba4165ed4f 100644 (file)
@@ -20,6 +20,9 @@
  */
 
 #include <babeltrace/types.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <sys/mman.h>
 #include <errno.h>
 #include <stdint.h>
@@ -84,7 +87,7 @@ void ctf_sequence_rw(struct stream_pos *pos, struct definition *definition);
 
 void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset);
 
-void ctf_init_pos(struct ctf_stream_pos *pos, int fd);
+void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags);
 void ctf_fini_pos(struct ctf_stream_pos *pos);
 
 /*
index ad0ff2041527d0e1fd3ecbcb56d066aba313b002..ca79115ff782e407c763295cfdc4683d5bf986c3 100644 (file)
@@ -126,7 +126,7 @@ void trace_text(FILE *input, int output)
        char *line = NULL, *nl;
        size_t linesize;
 
-       ctf_init_pos(&pos, output);
+       ctf_init_pos(&pos, output, O_WRONLY);
 
        write_packet_header(&pos, s_uuid);
        write_packet_context(&pos);
This page took 0.039917 seconds and 4 git commands to generate.