Check if binary is 64bit or 32bit

hello folk.
I have this code, and run OK, but tried detect if a binary input is of 32 bits or 64bit, Is posible check this whit cfg?. For example using let mut file = File::open("../data/vs_Community.exe").unwrap();?

#![allow(unused)]

fn main() {

let machine_kind = if cfg!(unix) {

    "x86"

} else if cfg!(windows) {

    "x86_64"

} else {

    "unknown"

};

println!("I'm running on a {} machine!", machine_kind);

}

regards.

You can use the target_arch config value to determine what kind of processor your program was compiled for, or target_pointer_width if you just want to know whether it is a 32-bit or 64-bit binary.

For example:

if cfg!(target_pointer_width = "32") {
    println!("32 bits")
} else if cfg!(target_pointer_width = "64") {
    println!("64 bits")
} else {
    println!("unknown")
}
4 Likes