1
0
mirror of https://github.com/simh/simh.git synced 2026-01-11 23:52:58 +00:00

SCP: Expose memory file functions to SCP private code

This commit is contained in:
Mark Pizzolato 2025-09-28 08:15:31 -10:00
parent bcdc992cca
commit 43bc996cdb
2 changed files with 37 additions and 10 deletions

31
scp.c
View File

@ -17007,14 +17007,10 @@ pclose(f);
return (0 == strcmp(response, "0"));
}
/* Memory File Support */
typedef struct MFILE {
char *buf;
size_t pos;
size_t size;
} MFILE;
static int Mprintf (MFILE *f, const char* fmt, ...)
int
Mprintf (MFILE *f, const char* fmt, ...)
{
va_list arglist;
int len;
@ -17047,7 +17043,7 @@ static int Mprintf (MFILE *f, const char* fmt, ...)
return 0;
}
static MFILE *
MFILE *
MOpen (void)
{
return (MFILE *)calloc (1, sizeof (MFILE));
@ -17059,7 +17055,7 @@ MFlush (MFILE *f)
f->pos = 0;
}
static int
int
FMwrite (FILE *fout, MFILE *fdata)
{
int ret = fwrite (fdata->buf, 1, fdata->pos, fout);
@ -17068,13 +17064,28 @@ MFlush (fdata);
return ret;
}
static void
void
MClose (MFILE *f)
{
free (f->buf);
free (f);
}
char *
MFileData (MFILE *f)
{
char *Data = NULL;
if (f != NULL) {
Data = malloc (f->pos + 1);
if (Data != NULL) {
memcpy (Data, f->buf, f->pos);
Data[f->pos] = '\0';
}
}
return Data;
}
/*
* This sanity check walks through the all of simulator's device registers
* to verify that each contains a reasonable description of a method to

View File

@ -404,11 +404,27 @@ struct SEND {
int32 extoff; /* extra offset */
};
/* Memory File */
typedef struct MFILE {
char *buf;
size_t pos;
size_t size;
} MFILE;
/* Private SCP only APIs */
t_stat _sim_os_putchar (int32 out);
t_bool _sim_running_as_root (void);
/* Memory File Support */
int Mprintf (MFILE *f, const char* fmt, ...) GCC_FMT_ATTR(2, 3);
MFILE *MOpen (void);
void MFlush (MFILE *f);
int FMwrite (FILE *fout, MFILE *fdata);
void MClose (MFILE *f);
char *MFileData (MFILE *f);
#endif /* defined(SIM_SCP_PRIVATE_DONT_REPEAT) */