[tracker/tracker-0.12: 81/202] libtracker-common: Fix tracker_file_open, original had various problems
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.12: 81/202] libtracker-common: Fix tracker_file_open, original had various problems
- Date: Thu, 6 Oct 2011 17:55:16 +0000 (UTC)
commit 0c42cf6fb47b2a0ef3d2afbe1f5b8bd6b107f3b3
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Sep 21 17:04:16 2011 +0200
libtracker-common: Fix tracker_file_open, original had various problems
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 5a939cc..e6a0280 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]