Created
July 8, 2012 21:18
-
-
Save julp/3072838 to your computer and use it in GitHub Desktop.
Is given file stored on a RAM based file system ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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