summaryrefslogtreecommitdiff
path: root/libcaja-private/caja-file.c
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-06-16 11:31:39 +0200
committerStefano Karapetsas <[email protected]>2012-06-16 11:31:39 +0200
commitcbbe010884fe1e3ad1deabbed7f89a77b0098a2f (patch)
treeab8700d7ffef178d2e720710b2756fafa0ef6a7b /libcaja-private/caja-file.c
parentdec2e9160bdc72ff9b44582d5484e673e60e27bb (diff)
downloadcaja-cbbe010884fe1e3ad1deabbed7f89a77b0098a2f.tar.bz2
caja-cbbe010884fe1e3ad1deabbed7f89a77b0098a2f.tar.xz
add diff button for text files in file conflict dialog
Diffstat (limited to 'libcaja-private/caja-file.c')
-rw-r--r--libcaja-private/caja-file.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/libcaja-private/caja-file.c b/libcaja-private/caja-file.c
index 7877f7d2..2f43eec2 100644
--- a/libcaja-private/caja-file.c
+++ b/libcaja-private/caja-file.c
@@ -7135,6 +7135,51 @@ caja_file_contains_text (CajaFile *file)
}
/**
+ * caja_file_is_binary
+ *
+ * Check if this file is a binary file.
+ * This is private and is used to decide whether or not to show the diff
+ * button in the file conflict dialog.
+ * @file: CajaFile representing the file in question.
+ *
+ * Returns: TRUE if @file is a binary file.
+ *
+ **/
+gboolean
+caja_file_is_binary (CajaFile *file)
+{
+ if (!caja_file_can_read(file))
+ {
+ return FALSE;
+ }
+
+ gboolean is_binary = FALSE;
+ int c;
+ int i;
+ FILE *fp;
+
+ /* Check the first 4096 bytes of the files. If these contains a 0,
+ * we can assume the file is binary.
+ * This idea is taken from python code of meld.
+ */
+
+ fp = g_fopen (g_file_get_path (caja_file_get_location (file)), "r");
+ for (i = 0; i < 4096; i++) {
+ c = fgetc(fp);
+ if (c == EOF) {
+ break;
+ }
+ else if (c == 0) {
+ is_binary = TRUE;
+ break;
+ }
+ }
+ fclose(fp);
+
+ return is_binary;
+}
+
+/**
* caja_file_is_executable
*
* Check if this file is executable at all.