Skip to content

Commit

Permalink
More robust handling of file name argument to $fopen.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Jan 1, 2005
1 parent 307a971 commit d9cdbde
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions vpi/sys_fileio.c
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: sys_fileio.c,v 1.5 2004/08/24 16:16:23 steve Exp $"
#ident "$Id: sys_fileio.c,v 1.5.2.1 2005/01/01 20:07:41 steve Exp $"
#endif

# include "vpi_user.h"
Expand Down Expand Up @@ -52,38 +52,37 @@ static int sys_fopen_calltf(char *name)
argv = 0;
}

if (! is_constant(item)) {
vpi_printf("ERROR: %s parameter must be a constant\n", name);
vpi_free_object(argv);
return 0;
}

if (vpi_get(vpiConstType, item) != vpiStringConst) {
vpi_printf("ERROR: %s parameter must be a string.\n", name);
vpi_free_object(argv);
return 0;
}

if (mode) {
if (! is_constant(mode)) {
vpi_printf("ERROR: %s parameter must be a constant\n", name);
vpi_free_object(argv);
if (argv) vpi_free_object(argv);
return 0;
}

if (vpi_get(vpiConstType, mode) != vpiStringConst) {
vpi_printf("ERROR: %s parameter must be a string.\n", name);
vpi_free_object(argv);
if (argv) vpi_free_object(argv);
return 0;
}
value.format = vpiStringVal;
vpi_get_value(mode, &value);
mode_string = strdup(value.value.str);
}

/* Get the string form of the file name from the file name
argument. */
value.format = vpiStringVal;
vpi_get_value(item, &value);

if ((value.format != vpiStringVal) || !value.value.str) {
vpi_printf("ERROR: %s: File name argument (type=%d)"
" does not have a string value\n",
name, vpi_get(vpiType, item));
if (mode) free(mode_string);
if (argv) vpi_free_object(argv);
return 0;
}

value.format = vpiIntVal;
if (mode) {
value.value.integer = vpi_fopen(value.value.str, mode_string);
Expand Down Expand Up @@ -480,6 +479,9 @@ void sys_fileio_register()

/*
* $Log: sys_fileio.c,v $
* Revision 1.5.2.1 2005/01/01 20:07:41 steve
* More robust handling of file name argument to $fopen.
*
* Revision 1.5 2004/08/24 16:16:23 steve
* Fix read count passed to fgets.
*
Expand Down

0 comments on commit d9cdbde

Please sign in to comment.