Tools: Tune: Common: Add checks for file open failures

This patch adds checks and errors for fopen() failures. The check
is useful with setup scripts paths changes. Aborting the script
avoids the errors in blob exports to be missed.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2024-06-03 20:02:25 +03:00 committed by Kai Vehmanen
parent 7f212411cc
commit e4b4ac7b4c
5 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,10 @@ function alsactl_write(fn, blob8)
%% Write blob
check_create_dir(fn);
fh = fopen(fn, 'w');
if fh < 0
fprintf(1, 'Error: Could not open file %s\n', fn);
error("Failed.");
end
%% Pad blob length to multiple of four bytes
n_orig = length(blob8);

View File

@ -4,6 +4,11 @@ function blob_write(fn, blob8)
%% Write blob
check_create_dir(fn);
fh = fopen(fn, 'wb');
if fh < 0
fprintf(1, 'Error: Could not open file %s\n', fn);
error("Failed.");
end
fwrite(fh, blob8, 'uint8');
fclose(fh);

View File

@ -25,6 +25,11 @@ ublob8(9:end) = blob8;
%% Write blob
check_create_dir(fn);
fh = fopen(fn, 'wb');
if fh < 0
fprintf(1, 'Error: Could not open file %s\n', fn);
error("Failed.");
end
fwrite(fh, ublob8, 'uint8');
fclose(fh);

View File

@ -24,6 +24,10 @@ end
%% Write blob
fh = fopen(fn, 'w');
if fh < 0
fprintf(1, 'Error: Could not open file %s\n', fn);
error("Failed.");
end
nl = 8;
fprintf(fh, '# %s %s\n', comment, date());
if ~isempty(howto)

View File

@ -15,6 +15,10 @@ blob8_new(1:n_orig) = blob8;
%% Write blob
fh = fopen(fn, 'w');
if fh < 0
fprintf(1, 'Error: Could not open file %s\n', fn);
error("Failed.");
end
nl = 8;
fprintf(fh, '# %s %s\n', comment, date());
if ~isempty(howto)