diff options
author | Philip Van Hoof <philip@codeminded.be> | 2011-09-21 17:04:16 +0200 |
---|---|---|
committer | Philip Van Hoof <philip@codeminded.be> | 2011-09-23 12:34:37 +0200 |
commit | ff49c63c4e526b919cc97cc05b0fa81928b56ed6 (patch) | |
tree | a63e5c38447b3ec6683cdd29c0122c995e0dceee | |
parent | 98ef0bbc59a68f7035e03ae471b553d615c00aa1 (diff) | |
download | tracker-ff49c63c4e526b919cc97cc05b0fa81928b56ed6.tar.gz |
libtracker-common: Fix tracker_file_open, original had various problems
-rw-r--r-- | src/libtracker-common/tracker-file-utils.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c index 5a939cc7e..e6a02807e 100644 --- a/src/libtracker-common/tracker-file-utils.c +++ b/src/libtracker-common/tracker-file-utils.c @@ -55,32 +55,29 @@ tracker_file_open (const gchar *path, const gchar *how, gboolean sequential) { - FILE *file; - gboolean readonly; - int flags; + FILE *file; + gboolean readonly; + int fd; g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (how != NULL, NULL); - file = fopen (path, how); - if (!file) { - return NULL; - } + readonly = !strstr (how, "r+") && strchr (how, 'r'); - /* Are we opening for readonly? */ - readonly = !strstr (path, "r+") && strchr (path, 'r'); +#if defined(__linux__) + fd = g_open (path, (readonly ? O_RDONLY : O_RDWR) | O_NOATIME); +#else + fd = g_open (path, readonly ? O_RDONLY : O_RDWR); +#endif - if (readonly) { - int fd; + if (fd == -1) { + return NULL; + } - fd = fileno (file); + file = fdopen (fd, how); -#if defined(__linux__) - /* Make sure we set the NOATIME flag if we have permissions to */ - if ((flags = fcntl (fd, F_GETFL, 0)) != -1) { - fcntl (fd, F_SETFL, flags | O_NOATIME); - } -#endif + if (!file) { + return NULL; } return file; |