/* * pdc_convert_filename_ext converts a file name as string of name type * (see function pdc_convert_name) to a [EBCDIC-]UTF-8 string with or * without a BOM. If the compiler doesn't allow Unicode filenames * (see define PDC_UNICODE_FILENAME) the filename is Latin-1 encoded * if possible or an exception will be thrown. * */ const char * pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len, const char *paramname, pdc_encoding enc, int codepage, int flags) { char *fname = NULL; const char *outfilename = NULL; int i = 0; if (filename == NULL) pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0); fname = pdc_convert_name_ext(pdc, filename, len, enc, codepage, flags); if (fname == NULL || *fname == '\0') pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0); if (pdc_is_utf8_bytecode(fname)) { #if defined(PDC_UNICODE_FILENAME) i = 3; #else fname = pdc_check_filename(pdc, fname); #endif } outfilename = pdc_errprintf(pdc, "%s", &fname[i]); pdc_free(pdc, fname); return outfilename; }
/* * pdc_convert_filename_ext converts a file name as string of name type * (see function pdc_convert_name_ext) to a [EBCDIC-]UTF-8 string with or * without a BOM. If the compiler doesn't allow Unicode filenames * (see define PDC_UNICODE_FILENAME) the filename is Latin-1 encoded * if possible or an exception will be thrown. * * Returned string is temporary allocated. * */ const char * pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len, const char *paramname, pdc_encoding enc, int codepage, int flags) { char *fname = NULL; const char *outfilename = NULL; int i = 0; if (filename == NULL) pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0); /* temporary allocation will be enforced */ flags |= PDC_CONV_TMPALLOC; fname = pdc_convert_name_ext(pdc, filename, len, enc, codepage, flags); if (fname == NULL || *fname == '\0') pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0); if (pdc_is_utf8_bytecode(fname)) { #if defined(PDC_UNICODE_FILENAME) i = 3; #else fname = pdc_check_filename(pdc, fname); #endif } outfilename = &fname[i]; return outfilename; }