For an application in C I wanted to know if a provided path is a mountpoint, so that a drive is mounted at that path.

With the help of the mtab file, which include all the mounts, we can iterate over that list and see if provided path is actually a mount point.
See ‘cat /etc/mtab’ to see the content of this file.

#include <mntent.h>
#include <stdio.h>
#include <string.h>

static bool path_is_mountpoint( CHAR* path )
{
  // Return if path is mountpoint (true), or not (false)
  BOOLEAN mounted = false;

  // Open mtab file.
  FILE * mtab = setmntent ("/etc/mtab", "r");
  struct mntent* mountpoint = nullptr;

  // Return directly if we could not open the file.
  if ( mtab == nullptr) return mounted;

  // Iterate over each entry in mtab list, and check if path is present
  while ( ( mountpoint = getmntent(mtab) ) != nullptr) {
    if ( (mountpoint->mnt_fsname != nullptr ) &&
         (strcmp(mountpoint->mnt_fsname, path ) == 0) )
    {
      // We found path in mtab, so path is mountpoint.
      // Stop iterating.
      mounted = true;
      break;
    }
  }

  endmntent (mtab);

  printf("path: %s, Is mountpoint: %d", path, mounted);

  return mounted;
}