diff options
| author | Tom Read Cutting <moosichu@users.noreply.github.com> | 2022-04-04 13:33:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-04 15:33:24 +0300 |
| commit | cdcb34cdf42fa3eb7a399106ccd57efc87643032 (patch) | |
| tree | dfe6f49534679b4eb5aaae77292345e03db11b0a /lib/std/elf.zig | |
| parent | 6d04ab6d5be1eaa47a920aaa3989bd3515fec5d6 (diff) | |
| download | zig-cdcb34cdf42fa3eb7a399106ccd57efc87643032.tar.gz zig-cdcb34cdf42fa3eb7a399106ccd57efc87643032.zip | |
Pull elf magic string out to re-used constant
Diffstat (limited to 'lib/std/elf.zig')
| -rw-r--r-- | lib/std/elf.zig | 4 |
1 files changed, 3 insertions, 1 deletions
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]) { |
