Skip to content

Commit

Permalink
std.DynLib: open the fd with CLOEXEC
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jun 16, 2018
1 parent 48de57d commit 65d04cb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions std/dynamic_library.zig
Expand Up @@ -11,14 +11,9 @@ pub const DynLib = struct {
map_addr: usize,
map_size: usize,

/// Trusts the file
pub fn findAndOpen(allocator: *mem.Allocator, name: []const u8) !DynLib {
return open(allocator, name);
}

/// Trusts the file
pub fn open(allocator: *mem.Allocator, path: []const u8) !DynLib {
const fd = try std.os.posixOpen(allocator, path, 0, linux.O_RDONLY);
const fd = try std.os.posixOpen(allocator, path, 0, linux.O_RDONLY | linux.O_CLOEXEC);
errdefer std.os.close(fd);

const size = usize((try std.os.posixFStat(fd)).size);
Expand Down
2 changes: 1 addition & 1 deletion std/math/index.zig
Expand Up @@ -538,7 +538,7 @@ test "math.cast" {

pub const AlignCastError = error{UnalignedMemory};

/// Align cast a pointer but return an error if it's the wrong field
/// Align cast a pointer but return an error if it's the wrong alignment
pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@typeOf(@alignCast(alignment, ptr)) {
const addr = @ptrToInt(ptr);
if (addr % alignment != 0) {
Expand Down

0 comments on commit 65d04cb

Please sign in to comment.