user/lib/libc/src/file/fd/map.c
/**
 * Performs a lookup from file descriptor number to file stream struct.
 */
Performs a lookup from file descriptor number to file stream struct.
Performs a lookup from file descriptor number to file stream struct .
stream_t *ConvertFdToStream(int fd) {
    int err;
    err = mtx_lock(&gState.lock);
    if(err != thrd_success) abort();
    fd_map_entry_t info = {
        .key    = fd,
        .stream = NULL
    };
    fd_map_entry_t *found = hashmap_get(gState.entries, &info);
    mtx_unlock(&gState.lock);
    return (found ? found->stream : NULL);
}
stream_t * ConvertFdToStream ( int fd ) { int err ; err = mtx_lock ( & gState . lock ) ; if ( err != thrd_success ) abort ( ) ; fd_map_entry_t info = { . key = fd , . stream = NULL } ; fd_map_entry_t * found = hashmap_get ( gState . entries , & info ) ; mtx_unlock ( & gState . lock ) ; return ( found ? found -> stream : NULL ) ; }
Performs a lookup from file descriptor number to file stream struct.
Performs a lookup from file descriptor number to file stream struct .
// acquire lock // get it // unlock and return the file stream