From ee7ab95c9ced8d39a2d23e2c17c19e1080c70558 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 6 Apr 2021 01:28:13 -0700 Subject: [PATCH] SCP: Allow file names to be quoted in sim_fopen --- sim_fio.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/sim_fio.c b/sim_fio.c index fbd2b0e7..f162bff8 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -319,20 +319,35 @@ return rmdir (pathbuf); /* OS-dependent routines */ /* Optimized file open */ - -FILE *sim_fopen (const char *file, const char *mode) +FILE* sim_fopen (const char *file, const char *mode) { +FILE *f; char namebuf[PATH_MAX + 1]; +uint8 *without_quotes = NULL; +uint32 dsize = 0; +if (((*file == '"') && (file[strlen (file) - 1] == '"')) || + ((*file == '\'') && (file[strlen (file) - 1] == '\''))) { + without_quotes = (uint8*)malloc (strlen (file) + 1); + if (without_quotes == NULL) + return NULL; + if (SCPE_OK != sim_decode_quoted_string (file, without_quotes, &dsize)) { + errno = EINVAL; + return NULL; + } + file = (const char*)without_quotes; +} _sim_expand_homedir (file, namebuf, sizeof (namebuf)); #if defined (VMS) -return fopen (namebuf, mode, "ALQ=32", "DEQ=4096", - "MBF=6", "MBC=127", "FOP=cbt,tef", "ROP=rah,wbh", "CTX=stm"); +f = fopen (namebuf, mode, "ALQ=32", "DEQ=4096", + "MBF=6", "MBC=127", "FOP=cbt,tef", "ROP=rah,wbh", "CTX=stm"); #elif (defined (__linux) || defined (__linux__) || defined (__hpux) || defined (_AIX)) && !defined (DONT_DO_LARGEFILE) -return fopen64 (namebuf, mode); +f = fopen64 (namebuf, mode); #else -return fopen (namebuf, mode); +f = fopen (namebuf, mode); #endif +free (without_quotes); +return f; } #if !defined (DONT_DO_LARGEFILE)