struct file_handle: Add new member file_name_encoding and an accessor function
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 9 Oct 2015 19:54:57 +0000 (21:54 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 9 Oct 2015 19:54:57 +0000 (21:54 +0200)
src/data/file-handle-def.c
src/data/file-handle-def.h

index db44cf701ccd30b9d1babe604e53bf7571cc8117..91300fed2b25df186fe74165a1a69dee517c9cb5 100644 (file)
@@ -50,6 +50,8 @@ struct file_handle
 
     /* FH_REF_FILE only. */
     char *file_name;           /* File name as provided by user. */
+    char *file_name_encoding;  /* The character encoding of file_name,
+                                  This is NOT the encoding of the file contents! */
     enum fh_mode mode;         /* File mode. */
     enum fh_line_ends line_ends; /* Line ends for text files. */
 
@@ -114,6 +116,7 @@ free_handle (struct file_handle *handle)
   free (handle->id);
   free (handle->name);
   free (handle->file_name);
+  free (handle->file_name_encoding);
   free (handle->encoding);
   free (handle);
 }
@@ -236,6 +239,7 @@ fh_create_file (const char *id, const char *file_name, const char *file_name_enc
   handle_name = id != NULL ? xstrdup (id) : xasprintf ("`%s'", file_name);
   handle = create_handle (id, handle_name, FH_REF_FILE, properties->encoding);
   handle->file_name = xstrdup (file_name);
+  handle->file_name_encoding = file_name_encoding ? xstrdup (file_name_encoding) : NULL;
   handle->mode = properties->mode;
   handle->line_ends = properties->line_ends;
   handle->record_width = properties->record_width;
@@ -314,6 +318,16 @@ fh_get_file_name (const struct file_handle *handle)
   return handle->file_name;
 }
 
+
+/* Returns the character encoding of the name of the file associated with HANDLE. */
+const char *
+fh_get_file_name_encoding (const struct file_handle *handle)
+{
+  assert (handle->referent == FH_REF_FILE);
+  return handle->file_name_encoding;
+}
+
+
 /* Returns the mode of HANDLE. */
 enum fh_mode
 fh_get_mode (const struct file_handle *handle)
index a57d3d72e5c50eed2112be2650b200f89c61d97b..ace0c6845bae170807a7f19fd80be0c1086b825c 100644 (file)
@@ -98,6 +98,7 @@ const char *fh_get_encoding (const struct file_handle *);
 
 /* Properties of FH_REF_FILE file handles. */
 const char *fh_get_file_name (const struct file_handle *);
+const char *fh_get_file_name_encoding (const struct file_handle *handle);
 enum fh_mode fh_get_mode (const struct file_handle *) ;
 enum fh_line_ends fh_get_line_ends (const struct file_handle *);