Skip to content

Instantly share code, notes, and snippets.

@julp
Created July 8, 2012 21:18
Show Gist options
  • Save julp/3072838 to your computer and use it in GitHub Desktop.
Save julp/3072838 to your computer and use it in GitHub Desktop.
Is given file stored on a RAM based file system ?
bool is_file_on_ram(const char *path)
{
#ifdef HAVE_STATFS
# ifdef BSD
# include <sys/param.h>
# include <sys/mount.h>
# else
# include <sys/vfs.h>
# include <linux/magic.h>
# endif
# include <errno.h>
struct statfs buf;
if (0 == statfs(path, &buf))) {
# ifdef BSD
return 0 == strcmp(buf.f_fstypename, "tmp");
# else
return TMPFS_MAGIC == buf.f_type;
# endif
} else {
//fprintf(stderr, "statfs failed: %s\n", strerror(errno));
return FALSE; /* statfs failed */
}
#else
return FALSE;
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment