@@ -154,7 +154,7 @@ int zusf_list_uss_file_path(ZUSF *zusf, string file, string &response)
154
154
*/
155
155
int zusf_read_from_uss_file (ZUSF *zusf, string file, string &response)
156
156
{
157
- ifstream in (file.c_str ());
157
+ ifstream in (file.c_str (), zusf-> data_type == DataType::Binary ? ios::in | ios::binary : ios::in );
158
158
if (!in.is_open ())
159
159
{
160
160
zusf->diag .e_msg_len = sprintf (zusf->diag .e_msg , " Could not open file '%s'" , file.c_str ());
@@ -174,13 +174,13 @@ int zusf_read_from_uss_file(ZUSF *zusf, string file, string &response)
174
174
char tagged_encoding[16 ] = {0 };
175
175
// ssize_t xattr_result = getxattr(file.c_str(), "system.filetag", &zusf->encoding);
176
176
177
- const bool encodingProvided = strlen (zusf->encoding ) > 0 ;
177
+ const bool encodingProvided = zusf-> data_type == DataType::Text && strlen (zusf->encoding ) > 0 ;
178
178
179
179
char *bufEnd;
180
180
if (encodingProvided /* && (*encoding != "IBM-1047" && *encoding != "01047") */ )
181
181
{
182
182
// const encoding = encodingProvided ? string(zusf->encoding) : string(tagged_encoding);
183
- char *outBuf = zut_encode_alloc (rawData, size, string (zusf->encoding ), zusf->diag , &bufEnd);
183
+ char *outBuf = zut_encode_alloc (rawData, size, " IBM-1047 " , string (zusf->encoding ), zusf->diag , &bufEnd);
184
184
if (outBuf)
185
185
{
186
186
response.clear ();
@@ -203,21 +203,21 @@ int zusf_read_from_uss_file(ZUSF *zusf, string file, string &response)
203
203
*
204
204
* @return RTNCD_SUCCESS on success, RTNCD_FAILURE on failure
205
205
*/
206
- int zds_write_to_uss_file (ZUSF *zusf, string file, string &data)
206
+ int zusf_write_to_uss_file (ZUSF *zusf, string file, string &data)
207
207
{
208
208
// TODO(zFernand0): Avoid overriding existing files
209
- const bool withEncoding = strlen (zusf->encoding ) > 0 ;
210
- ofstream out (file.c_str (), withEncoding ? ios::out | ios::binary : ios::out);
209
+ const bool hasEncoding = strlen (zusf->encoding ) > 0 ;
210
+ ofstream out (file.c_str (), zusf-> data_type == DataType::Binary ? ios::out | ios::binary : ios::out);
211
211
if (!out.is_open ())
212
212
{
213
213
zusf->diag .e_msg_len = sprintf (zusf->diag .e_msg , " Could not open '%s'" , file.c_str ());
214
214
return RTNCD_FAILURE;
215
215
}
216
216
217
- if (strlen (zusf-> encoding ) > 0 )
217
+ if (hasEncoding )
218
218
{
219
219
char *bufEnd;
220
- char *outBuf = zut_encode_alloc ((char *)data.c_str (), data.length (), string (zusf->encoding ), zusf->diag , &bufEnd);
220
+ char *outBuf = zut_encode_alloc ((char *)data.c_str (), data.length (), string (zusf->encoding ), " IBM-1047 " , zusf->diag , &bufEnd);
221
221
if (outBuf)
222
222
{
223
223
data.clear ();
@@ -241,7 +241,7 @@ int zds_write_to_uss_file(ZUSF *zusf, string file, string &data)
241
241
*
242
242
* @return RTNCD_SUCCESS on success, RTNCD_FAILURE on failure
243
243
*/
244
- int zds_chmod_uss_file_or_dir (ZUSF *zusf, string file, string mode)
244
+ int zusf_chmod_uss_file_or_dir (ZUSF *zusf, string file, string mode)
245
245
{
246
246
// TODO(zFernand0): Add recursive option for directories
247
247
struct stat file_stats;
0 commit comments