From cdcb34cdf42fa3eb7a399106ccd57efc87643032 Mon Sep 17 00:00:00 2001 From: Tom Read Cutting Date: Mon, 4 Apr 2022 13:33:24 +0100 Subject: Pull elf magic string out to re-used constant --- lib/std/elf.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/std/elf.zig') diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 84001ec1c9..846bb8d11a 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -305,6 +305,8 @@ pub const STT_ARM_16BIT = STT_HIPROC; pub const VER_FLG_BASE = 0x1; pub const VER_FLG_WEAK = 0x2; +pub const MAGIC = "\x7fELF"; + /// File types pub const ET = enum(u16) { /// No file type @@ -367,7 +369,7 @@ pub const Header = struct { pub fn parse(hdr_buf: *align(@alignOf(Elf64_Ehdr)) const [@sizeOf(Elf64_Ehdr)]u8) !Header { const hdr32 = @ptrCast(*const Elf32_Ehdr, hdr_buf); const hdr64 = @ptrCast(*const Elf64_Ehdr, hdr_buf); - if (!mem.eql(u8, hdr32.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic; + if (!mem.eql(u8, hdr32.e_ident[0..4], MAGIC)) return error.InvalidElfMagic; if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; const endian: std.builtin.Endian = switch (hdr32.e_ident[EI_DATA]) { -- cgit v1.2.3