How can I determine the mount path of a given file on Linux in C?

I have an arbitrary file for which I would like to determine the mount point. Let's say that it is /mnt/bar/foo.txt, where we have the following mount points in addition to the "normal" Linux mount points:

I've taken a look at stat() and statvfs(). statvfs() can give me the filesystem id, and stat can give me the id of the device, but neither of these can really correlate to the mount point.

I'm thinking that what I will have to do is call readlink() on the arbitrary file, and then read through /proc/mounts, figuring out which path most closely matches the filename. Is this a good approach, or is there some great libc function I'm missing out on to to this?

Note, for brevity there's no error checking there. Also getfsent is not a POSIX function, but it is a very widely used convention. It works here on OS X which doesn't even use /etc/fstab. It is also not thread safe.

Email codedump link for How can I determine the mount path of a given file on Linux in C?