You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: read_write_entire_textfile.m
    path of file: ./repos/DeepCO3/Lib/export_fig-master
    
    the code of the file until where you have to start completion: %READ_WRITE_ENTIRE_TEXTFILE Read or write a whole text file to/from memory
%
% R
    
function fstrm = read_write_entire_textfile(fname, fstrm)
modes = {'rt', 'wt'};
writing = nargin > 1;
fh = fopen(fname, modes{1+writing});
if fh == -1
    error('Unable to open file %s.', fname);
end