user/lib/libc/src/file/fd/map.c
/**
 * Unregisters a previously registered file descriptor number.
 *
 * @return 0 if the stream was successfully removed, -1 if it was never registered.
 */
Unregisters a previously registered file descriptor number.
@return 0 if the stream was successfully removed, -1 if it was never registered.
Unregisters a previously registered file descriptor number . @return 0 if the stream was successfully removed - 1 if it was never registered .
int UnregisterFdStream(stream_t *stream) {
    int err;
    if(stream->fd < 0) return -1;
    err = mtx_lock(&gState.lock);
    if(err != thrd_success) abort();
    fd_map_entry_t info = {
        .key    = stream->fd,
        .stream = NULL
    };
    void *original = hashmap_delete(gState.entries, &info);
    mtx_unlock(&gState.lock);
    return (!original ? 0 : -1);
}
int UnregisterFdStream ( stream_t * stream ) { int err ; if ( stream -> fd < 0 ) return -1 ; err = mtx_lock ( & gState . lock ) ; if ( err != thrd_success ) abort ( ) ; fd_map_entry_t info = { . key = stream -> fd , . stream = NULL } ; void * original = hashmap_delete ( gState . entries , & info ) ; mtx_unlock ( & gState . lock ) ; return ( ! original ? 0 : -1 ) ; }
Unregisters a previously registered file descriptor number.
Unregisters a previously registered file descriptor number .
// validate the file descriptor number // acquire lock // remove it // unlock