journal: catch err, add sliceifyKnown
This commit is contained in:
parent
6b78bb16d8
commit
f3b8196ac5
2 changed files with 12 additions and 4 deletions
|
@ -9,7 +9,7 @@ pub fn build(b: *Builder) void {
|
||||||
const source_files = [_][]const u8{"src/journal/main.c"};
|
const source_files = [_][]const u8{"src/journal/main.c"};
|
||||||
|
|
||||||
for (source_files) |source| {
|
for (source_files) |source| {
|
||||||
exe.addCSourceFile(source, [_][]const u8{"-W -O"});
|
exe.addCSourceFile(source, [_][]const u8{"-Wall"});
|
||||||
}
|
}
|
||||||
|
|
||||||
const zig_sources = [_][]const u8{"src/journal/journal.zig"};
|
const zig_sources = [_][]const u8{"src/journal/journal.zig"};
|
||||||
|
|
|
@ -16,6 +16,10 @@ fn sliceify(ptr: [*]u8) []u8 {
|
||||||
return ptr[0..c.strlen(ptr)];
|
return ptr[0..c.strlen(ptr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sliceifyKnown(slice: []u8) []u8 {
|
||||||
|
return slice[0..c.strlen(slice.ptr)];
|
||||||
|
}
|
||||||
|
|
||||||
export fn journal_open(topic_cptr: ?[*]u8) os.fd_t {
|
export fn journal_open(topic_cptr: ?[*]u8) os.fd_t {
|
||||||
const topic = sliceify(topic_cptr.?);
|
const topic = sliceify(topic_cptr.?);
|
||||||
|
|
||||||
|
@ -75,19 +79,23 @@ export fn journal_write_topic(
|
||||||
topic_cptr: ?[*]u8,
|
topic_cptr: ?[*]u8,
|
||||||
message_cptr: ?[*]u8,
|
message_cptr: ?[*]u8,
|
||||||
) void {
|
) void {
|
||||||
|
warn("zig uwu\n");
|
||||||
var topic = sliceify(topic_cptr.?);
|
var topic = sliceify(topic_cptr.?);
|
||||||
var message = sliceify(message_cptr.?);
|
var message = sliceify(message_cptr.?);
|
||||||
|
|
||||||
var tstamp_total = allocator.alloc(u8, 128);
|
var tstamp_total = allocator.alloc(u8, 128) catch |err| {
|
||||||
|
warn("failed to allocate string for timestamp\n");
|
||||||
|
return;
|
||||||
|
};
|
||||||
defer allocator.free(tstamp_total);
|
defer allocator.free(tstamp_total);
|
||||||
|
|
||||||
var rawtime: c.time_t = undefined;
|
var rawtime: c.time_t = undefined;
|
||||||
|
|
||||||
_ = c.time(&rawtime);
|
_ = c.time(&rawtime);
|
||||||
var cur_time: [*c]const c.struct_tm = c.gmtime(&rawtime);
|
var cur_time: [*c]const c.struct_tm = c.gmtime(&rawtime);
|
||||||
_ = c.strftime(tstamp_cstr.ptr, usize(128), c"%c", cur_time);
|
_ = c.strftime(tstamp_total.ptr, usize(128), c"%c", cur_time);
|
||||||
|
|
||||||
var tstamp = sliceify(tstamp_total);
|
var tstamp = sliceifyKnown(tstamp_total);
|
||||||
|
|
||||||
std.debug.warn("tstamp: {}\ntopic: {}\nmsg: {}\n", tstamp, topic, message);
|
std.debug.warn("tstamp: {}\ntopic: {}\nmsg: {}\n", tstamp, topic, message);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue