rust-lang/libc

cannot find value `SETVAL` in crate `libc`

phil-skillwon opened this issue · 3 comments

when calling libc::semctl, rustc gives an error: error[E0425]: cannot find value SETVAL in crate libc

Please provide your target triple. And code show how you use libc::semctl.
The information you provided is very spared.

Please provide your target triple. And code show how you use libc::semctl. The information you provided is very spared.

sure, here is my code:

use libc::{c_int, c_ushort, semctl, SETVAL};

fn set_semaphore_value(sem_id: c_int, sem_num: c_int, value: c_int) -> Result<(), String> {
    let result = unsafe {
        semctl(sem_id, sem_num, SETVAL, value)	//  cannot find value SETVAL in crate libc
    };

    if result == -1 {
        Err(format!("Failed to set semaphore value. Error: {}", std::io::Error::last_os_error()))
    } else {
        Ok(())
    }
}

fn main() {
    let m_resp_sem_id = 15671;
    
    match set_semaphore_value(m_resp_sem_id, 0, 1) {
        Ok(_) => println!("Successfully set semaphore value to 1"),
        Err(e) => eprintln!("Error: {}", e),
    }
}

Why did you close this issue? I can see that libc misses <sem.h> constants.
While <semaphore.h> replaces most uses of <sem.h>, the former is missing some features.
You could open a PR to add those <sem.h> constants if you have their uses.