Created
November 1, 2019 16:34
-
-
Save SamTebbs33/abe4e544627e3dc1576aff29df1a6f50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const ChildProcess = std.ChildProcess; | |
const File = std.fs.File; | |
pub fn main() !void { | |
const args = std.os.argv; | |
if (args.len != 3) { | |
std.debug.warn("Usage: {} <elf file> <map file>\n", args[0][0..strlen(args[0])]); | |
return; | |
} | |
const elf_file_path = args[1][0..strlen(args[1])]; | |
const map_file_path = args[2][0..strlen(args[2])]; | |
const elf_file = try File.openRead(elf_file_path); | |
const map_file = try File.openWrite(map_file_path); | |
const allocator = std.heap.direct_allocator; | |
const readelf_proc = try ChildProcess.init([_][]const u8{ "readelf", "-s", elf_file_path }, allocator); | |
readelf_proc.stdout_behavior = ChildProcess.StdIo.Pipe; | |
readelf_proc.stdout = map_file; | |
_ = try readelf_proc.spawn(); | |
} | |
fn strlen(str: [*]u8) usize { | |
var i: usize = 0; | |
while (str[i] != 0) : (i += 1) {} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment