Skip to content

Commit

Permalink
posix
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Jul 8, 2024
1 parent 48c4a45 commit db294b2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
exe.linkLibC();

// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
Expand Down
4 changes: 2 additions & 2 deletions src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn init(alloc: Allocator) !void {
}

pub fn config_file_path() []const u8 {
const home_path = std.os.getenv("HOME").?;
const home_path = std.posix.getenv("HOME").?;
const home_dir = std.fs.openDirAbsolute(home_path, .{}) catch unreachable;
const config_path = std.fs.path.join(allocator, &.{ home_path, ".config", "zootdeck" }) catch unreachable;
home_dir.makePath(config_path) catch unreachable;
Expand All @@ -121,7 +121,7 @@ pub fn readfile(filename: []const u8) !Settings {
cwd.access(filename, .{}) catch |err| switch (err) {
error.FileNotFound => {
warn("Warning: creating new {s}\n", .{filename});
try cwd.writeFile(filename, "{}\n");
try cwd.writeFile(.{ .sub_path = filename, .data = "{}\n" });
},
else => return err,
};
Expand Down
2 changes: 1 addition & 1 deletion src/db/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Allocator = std.mem.Allocator;
const cache_dir = "./cache";

pub fn init() !void {
std.os.mkdir(cache_dir, 0o644) catch |err| {
std.posix.mkdir(cache_dir, 0o644) catch |err| {
if (err != error.PathAlreadyExists) return err;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/db/lmdb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn init(allocator: Allocator) !void {
warn("mdb_env_set_mapsize failed {}\n", .{mdb_ret});
return error.BadValue;
}
std.os.mkdir(dbpath, 0o0755) catch {};
std.posix.mkdir(dbpath, 0o0755) catch {};
mdb_ret = c.mdb_env_open(env, util.sliceToCstr(allocator, dbpath), 0, 0o644);
if (mdb_ret != 0) {
warn("mdb_env_open failed {}\n", .{mdb_ret});
Expand Down
6 changes: 3 additions & 3 deletions src/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn sliceAddNull(allocator: Allocator, str: []const u8) []const u8 {

pub fn sliceToCstr(allocator: Allocator, str: []const u8) [*]u8 {
var str_null: []u8 = allocator.alloc(u8, str.len + 1) catch unreachable;
std.mem.copy(u8, str_null[0..], str);
std.mem.copyForwards(u8, str_null[0..], str);
str_null[str.len] = 0;
return str_null.ptr;
}
Expand All @@ -30,8 +30,8 @@ pub fn log(comptime msg: []const u8, args: anytype) void {
const tid = thread.self();
const tid_name = thread.name(tid);
//const tz = std.os.timezone.tz_minuteswest;
var tz = std.os.timezone{ .tz_minuteswest = 0, .tz_dsttime = 0 };
std.os.gettimeofday(null, &tz); // does not set tz
var tz = std.posix.timezone{ .tz_minuteswest = 0, .tz_dsttime = 0 };
std.posix.gettimeofday(null, &tz); // does not set tz
const time_str = "Z"; //std.fmt.allocPrint(alloc, "{d}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2}:{d:0>2}", .{ yday.year, mday.month.numeric(), mday.day_index + 1, dsec.getHoursIntoDay(), dsec.getMinutesIntoHour(), dsec.getSecondsIntoMinute() }) catch unreachable;
_ = time_str;
_ = tid_name;
Expand Down

0 comments on commit db294b2

Please sign in to comment.