Browse Source

Add Utils to curl struct

master
Kenneth Bruen 9 months ago
parent
commit
5d74b3a896
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 10
      src/curl.zig
  2. 8
      src/home.zig

10
src/curl.zig

@ -71,3 +71,13 @@ pub fn setopt(
) c_api.CURLcode { ) c_api.CURLcode {
return self.setopt_raw(@intFromEnum(option), args); 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;
}
};

8
src/home.zig

@ -4,12 +4,6 @@ const rl = raylib.rl;
const AppState = @import("state.zig"); const AppState = @import("state.zig");
const Curl = @import("curl.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 { fn fetchThread(state: *AppState) !void {
std.debug.print("[home/fetchThread] Started\n", .{}); std.debug.print("[home/fetchThread] Started\n", .{});
defer std.debug.print("[home/fetchThread] Ended\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); var result = std.ArrayList(u8).init(allocator);
defer result.deinit(); defer result.deinit();
_ = curl.setopt(.write_function, .{curlWriteHandler}); _ = curl.setopt(.write_function, .{Curl.Utils.array_list_append});
_ = curl.setopt(.write_data, .{&result}); _ = curl.setopt(.write_data, .{&result});
const code = curl.perform(); const code = curl.perform();

Loading…
Cancel
Save