Skip to content

Instantly share code, notes, and snippets.

@haze

haze/things.zig Secret

Created January 14, 2020 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haze/d7114588286456d7a34bff88328101e0 to your computer and use it in GitHub Desktop.
Save haze/d7114588286456d7a34bff88328101e0 to your computer and use it in GitHub Desktop.
fn saveBodyToBuffer(argContent: *c_void, size: usize, nmemb: usize, userData: ?*c_void) callconv(.C) usize {
var buffer = @ptrCast(*std.Buffer, @alignCast(8, userData));
var content: [*]u8 = @ptrCast([*]u8, blk: {
if (@alignOf(@TypeOf(argContent)) != 8)
break :blk @alignCast(8, argContent);
break :blk argContent;
});
buffer.replaceContents(@ptrCast([*]u8, content)[0 .. size * nmemb]) catch {
std.debug.warn("summ bad happened\n", .{});
return 0;
};
return size * nmemb;
}
// this would give me errors
fn saveBodyToBuffer(argContent: *c_void, size: usize, nmemb: usize, userData: ?*c_void) callconv(.C) usize {
var buffer = @ptrCast(*std.Buffer, @alignCast(8, userData));
var content: [*]u8 = @ptrCast([*]u8, blk: {
if (@alignOf(@TypeOf(argContent)) != 8)
break :blk @alignCast(8, argContent);
break :blk argContent;
});
buffer.replaceContents(@ptrCast([*]u8, @alignCast(8, content))[0 .. size * nmemb]) catch {
std.debug.warn("summ bad happened\n", .{});
return 0;
};
return size * nmemb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment