[][src]Function solana_rbpf::helpers::strcmp

pub fn strcmp(
    arg1: u64,
    arg2: u64,
    arg3: u64,
    unused4: u64,
    unused5: u64,
    _context: &mut HelperContext,
    ro_regions: &[MemoryRegion],
    _rw_regions: &[MemoryRegion]
) -> Result<u64, Error>

C-like strcmp, return 0 if the strings are equal, and a non-null value otherwise.

Examples

use solana_rbpf::helpers;
use solana_rbpf::memory_region::MemoryRegion;

let foo = "This is a string.";
let bar = "This is another sting.";
let va_foo = 0x1000;
let va_bar = 0x2000;
let regions = [MemoryRegion::new_from_slice(foo.as_bytes(), va_foo)];
assert!(helpers::strcmp(va_foo, va_foo, 0, 0, 0, &mut None, &regions, &regions).unwrap() == 0);
let regions = [MemoryRegion::new_from_slice(foo.as_bytes(), va_foo),
               MemoryRegion::new_from_slice(bar.as_bytes(), va_bar)];
assert!(helpers::strcmp(va_foo, va_bar, 0, 0, 0, &mut None, &regions, &regions).unwrap() != 0);