From 5d74b3a8968c8c14ad037040497ba9ce4e41a83e Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Sat, 17 Feb 2024 03:32:45 +0100 Subject: [PATCH] Add Utils to curl struct --- src/curl.zig | 10 ++++++++++ src/home.zig | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/curl.zig b/src/curl.zig index 25e57af..f28258c 100644 --- a/src/curl.zig +++ b/src/curl.zig @@ -71,3 +71,13 @@ pub fn setopt( ) c_api.CURLcode { return self.setopt_raw(@intFromEnum(option), args); } + +pub const Utils = struct { + const std = @import("std"); + + pub fn array_list_append(ptr: [*]u8, size: usize, nmemb: usize, userdata: *std.ArrayList(u8)) callconv(.C) usize { + _ = size; + userdata.appendSlice(ptr[0..nmemb]) catch return 0; + return nmemb; + } +}; diff --git a/src/home.zig b/src/home.zig index f945c80..a01fbfd 100644 --- a/src/home.zig +++ b/src/home.zig @@ -4,12 +4,6 @@ const rl = raylib.rl; const AppState = @import("state.zig"); const Curl = @import("curl.zig"); -fn curlWriteHandler(ptr: [*]u8, size: usize, nmemb: usize, userdata: *std.ArrayList(u8)) callconv(.C) usize { - _ = size; - userdata.appendSlice(ptr[0..nmemb]) catch return 0; - return nmemb; -} - fn fetchThread(state: *AppState) !void { std.debug.print("[home/fetchThread] Started\n", .{}); defer std.debug.print("[home/fetchThread] Ended\n", .{}); @@ -46,7 +40,7 @@ fn fetchThread(state: *AppState) !void { var result = std.ArrayList(u8).init(allocator); defer result.deinit(); - _ = curl.setopt(.write_function, .{curlWriteHandler}); + _ = curl.setopt(.write_function, .{Curl.Utils.array_list_append}); _ = curl.setopt(.write_data, .{&result}); const code = curl.perform();