openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/sys-utils/dmesg.c
static ssize_t mmap_file_buffer(struct dmesg_control* ctl, char** buf)
{
    struct stat st;
    int fd;

    if (!ctl->filename)
        return -1;

    fd = open(ctl->filename, O_RDONLY);
    if (fd < 0)
        err(EXIT_FAILURE, _("cannot open %s"), ctl->filename);
    if (fstat(fd, &st))
        err(EXIT_FAILURE, _("stat of %s failed"), ctl->filename);

    *buf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (*buf == MAP_FAILED)
        err(EXIT_FAILURE, _("cannot mmap: %s"), ctl->filename);
    ctl->mmap_buff = *buf;
    ctl->pagesize = getpagesize();
    close(fd);

    return st.st_size;
}
/*
 * Reads messages from regular file by mmap
 */
Reads messages from regular file by mmap
Reads messages from regular file by mmap
static ssize_t mmap_file_buffer(struct dmesg_control* ctl, char** buf)
{
    struct stat st;
    int fd;
    if (!ctl->filename)
        return -1;
    fd = open(ctl->filename, O_RDONLY);
    if (fd < 0)
        err(EXIT_FAILURE, _("cannot open %s"), ctl->filename);
    if (fstat(fd, &st))
        err(EXIT_FAILURE, _("stat of %s failed"), ctl->filename);
    *buf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (*buf == MAP_FAILED)
        err(EXIT_FAILURE, _("cannot mmap: %s"), ctl->filename);
    ctl->mmap_buff = *buf;
    ctl->pagesize = getpagesize();
    close(fd);
    return st.st_size;
}
static ssize_t mmap_file_buffer ( struct dmesg_control * ctl , char * * buf ) { struct stat st ; int fd ; if ( ! ctl -> filename ) return -1 ; fd = open ( ctl -> filename , O_RDONLY ) ; if ( fd < 0 ) err ( EXIT_FAILURE , _ ( " " ) , ctl -> filename ) ; if ( fstat ( fd , & st ) ) err ( EXIT_FAILURE , _ ( " " ) , ctl -> filename ) ; * buf = mmap ( NULL , st . st_size , PROT_READ , MAP_SHARED , fd , 0 ) ; if ( * buf == MAP_FAILED ) err ( EXIT_FAILURE , _ ( " " ) , ctl -> filename ) ; ctl -> mmap_buff = * buf ; ctl -> pagesize = getpagesize ( ) ; close ( fd ) ; return st . st_size ; }
Reads messages from regular file by mmap
Reads messages from regular file by mmap