.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;
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);
}
}
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;
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);
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;
#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 =
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);
}
*/
#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>
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);
/*
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);