Last active
October 3, 2024 13:38
-
-
Save pongo/425acd0286b529b628af308a8c7f1e00 to your computer and use it in GitHub Desktop.
Prevent HDD from going to sleep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
// zig build-exe hddnosleep.zig -O ReleaseSmall | |
// install as service via nssm.exe install hddnosleep | |
const FILENAME = "D:\\tmp\\hddnosleep.txt"; | |
pub fn main() anyerror!void { | |
// const allocator = std.heap.page_allocator; | |
// const stdout = std.io.getStdOut().writer(); | |
var buffer: [100]u8 = undefined; | |
var fba = std.heap.FixedBufferAllocator.init(&buffer); | |
const allocator = fba.allocator(); | |
const loop_duration = std.time.ns_per_s * 7; // 7 sec | |
while (true) { | |
const time = try std.time.Instant.now(); | |
const time_str = try std.fmt.allocPrint(allocator, "{}", .{time.timestamp}); | |
defer allocator.free(time_str); | |
{ | |
var file = try std.fs.cwd().createFile(FILENAME, .{}); | |
defer file.close(); | |
try file.writeAll(time_str); | |
} | |
// try stdout.writeAll(time_str); | |
std.time.sleep(loop_duration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment