Skip to content

Commit

Permalink
added error information to file writing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ssandrews committed Dec 11, 2023
1 parent 95bd2f1 commit 58e9198
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/libSteve/SimCommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Library for runtime command interpreter used for various simulations.
Copyright 2004-2007 by Steven Andrews. This work is distributed under the terms
of the Gnu Lesser General Public License (LGPL). */

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -856,6 +857,7 @@ int scmdopenfiles(cmdssptr cmds,int overwrite) {
FILE *fptr;

if(!cmds) return 0;
errno=0;
for(fid=0;fid<cmds->nfile;fid++) {
if(cmds->fptr[fid] && strcmp(cmds->fname[fid],"stdout") && strcmp(cmds->fname[fid],"stderr"))
fclose(cmds->fptr[fid]);
Expand Down Expand Up @@ -887,7 +889,7 @@ int scmdopenfiles(cmdssptr cmds,int overwrite) {
if(cmds->fappend[fid]) cmds->fptr[fid]=fopen(str1,"a");
else cmds->fptr[fid]=fopen(str1,"w");
if(!cmds->fptr[fid]) {
SCMDPRINTF(cmds->simvd,7,"Failed to open file '%s' for writing\n",cmds->fname[fid]);
SCMDPRINTF(cmds->simvd,7,"Failed to open file '%s' for writing. Error number: %d.\n",cmds->fname[fid],errno);
return 1; }}}

return 0; }
Expand Down

0 comments on commit 58e9198

Please sign in to comment.