'How to detect mount warning as error in order to force fsck

I have this source code, and it works when an error detected on mounting filesystem ext4 and it is not mounted due to this error, but when filesystem is mounted with error mount function return 0 (even for mount command on shell return 0 (tested with $?))

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <blkid/blkid.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h
if (0 == mount(devname, _mount_point, type, 0, "")) {
    /* some function is called here*/
} else {
    /* run fsck.ext4 */
}

The problem the function returns 0 when we have this messsage on dmesg

[ 5.844532] EXT4-fs (mmcblk0p1): warning: mounting fs with errors, running e2fsck is recommended

How can I dectect warning or force to detect warining as error like is done on C compiler using -Wall



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source