Skip to content

Commit 5f87867

Browse files
committed
refactor(curl): improve OS detection and type safety
- `libs/curl.zig`: Refactor `getCurlOS` to return an optional `[]const u8`. The logic for constructing the generic "arch-pc-os" system name for unknown platforms is now handled directly in the `create` function, rather than within `getCurlOS`. This makes `getCurlOS` responsible solely for identifying specific, known operating system names. - `src/MultiPart.zig`: Update the `offset` parameter in the `NonCopyingData.seek` callback to use `c.curl_off_t`. This improves type safety and aligns with the `curl` library's defined types for file offsets.
1 parent 274036d commit 5f87867

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

libs/curl.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui
201201
lib.root_module.addCMacro("USE_UNIX_SOCKETS", "1");
202202
lib.root_module.addCMacro("_FILE_OFFSET_BITS", "64");
203203

204-
const system_name = getCurlOS(b.allocator, target);
204+
const system_name = getCurlOS(target) orelse blk: {
205+
const arch = @tagName(target.result.cpu.arch);
206+
const os = @tagName(target.result.os.tag);
207+
break :blk std.fmt.allocPrint(b.allocator, "{s}-pc-{s}", .{ arch, os }) catch unreachable;
208+
};
205209
const curl_os = std.fmt.allocPrint(b.allocator, "\"{s}\"", .{system_name}) catch unreachable;
206210
lib.root_module.addCMacro("CURL_OS", curl_os);
207211

@@ -210,7 +214,7 @@ pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui
210214

211215
// define CURL_OS based on target platform
212216
// current unsupported platform : Itanium, RiscOS, OS/400
213-
fn getCurlOS(allocator: std.mem.Allocator, target: std.Build.ResolvedTarget) []const u8 {
217+
fn getCurlOS(target: std.Build.ResolvedTarget) ?[]const u8 {
214218
switch (target.result.os.tag) {
215219
.windows => {
216220
switch (target.result.cpu.arch) {
@@ -231,11 +235,7 @@ fn getCurlOS(allocator: std.mem.Allocator, target: std.Build.ResolvedTarget) []c
231235
.macos => return "mac",
232236
.freebsd => return "freebsd",
233237
else => {
234-
const arch = @tagName(target.result.cpu.arch);
235-
const os = @tagName(target.result.os.tag);
236-
237-
const system_name = std.fmt.allocPrint(allocator, "\"{s}-pc-{s}\"", .{ arch, os }) catch "\"unknown-pc-unknown\"";
238-
return system_name;
238+
return null;
239239
},
240240
}
241241
}

src/MultiPart.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub const NonCopyingData = struct {
7777
return to_read;
7878
}
7979

80-
pub fn seek(user_data: ?*anyopaque, offset: c_longlong, origin: c_int) callconv(.c) c_int {
80+
pub fn seek(user_data: ?*anyopaque, offset: c.curl_off_t, origin: c_int) callconv(.c) c_int {
8181
var source: *DataWithOffset = @ptrCast(@alignCast(user_data orelse return c.CURL_SEEKFUNC_FAIL));
8282
const new_pos = switch (origin) {
8383
c.SEEK_SET => offset,

0 commit comments

Comments
 (0)