From be54f3fd7ac953c44df1a843a5b189eb5072f7e5 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 9 Oct 2015 21:54:57 +0200 Subject: [PATCH] struct file_handle: Add new member file_name_encoding and an accessor function --- src/data/file-handle-def.c | 14 ++++++++++++++ src/data/file-handle-def.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c index db44cf701c..91300fed2b 100644 --- a/src/data/file-handle-def.c +++ b/src/data/file-handle-def.c @@ -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) diff --git a/src/data/file-handle-def.h b/src/data/file-handle-def.h index a57d3d72e5..ace0c6845b 100644 --- a/src/data/file-handle-def.h +++ b/src/data/file-handle-def.h @@ -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 *); -- 2.30.2