Mercurial > octave-nkf
annotate scripts/io/fileread.m @ 19312:6ca096827123
Use tempname() rather than tmpnam() in core Octave.
* scripts/miscellaneous/tempname.m: Removed m-file as function is now C++.
* scripts/miscellaneous/tmpnam.m: New m-file is an alias that calls tempname.
* scripts/miscellaneous/module.mk: Add tmpnam.m to build system.
* io.txi: Place tempname, tempdir, P_tmpdir docstrings in section on temporary
files.
* system.txi: Remove tempname, tempdir, P_tmpdir docstrings from generic
system functions section of manual.
* dirfns.cc, dlmread.cc, md5sum.cc, ov-fcn-handle.cc: Replace instances
of tmpnam with tempname in BIST code.
* file-io.cc (Ftempname): Change DEFUNX for tmpnam to DEFUN for tempname.
Remove seealso links to tmpnam.
* ftp.m, playaudio.m, wavwrite.m, imformats.m, imread.m, imwrite.m, imageIO.m,
csvwrite.m, dlmwrite.m, fileread.m, importdata.m, textread.m, textscan.m,
genvarname.m, unpack.m, install.m, legend.m, __gnuplot_drawnow__.m,
copyobj.m, hgsave.m, print.m, __ghostscript__.m, __gnuplot_get_var__.m,
__gnuplot_ginput__.m, __gnuplot_print__.m: Replace tmpnam with tempname in
core code.
* build-sparse-tests.sh, io.tst, prefer.tst, system.tst: Replace tmpnam with
tempname in test code.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 22 Oct 2014 10:41:15 -0700 |
parents | d63878346099 |
children | 4197fc428c7d |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16974
diff
changeset
|
1 ## Copyright (C) 2010-2013 VZLU Prague |
10081 | 2 ## |
11104 | 3 ## This file is part of Octave. |
10081 | 4 ## |
11104 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
10081 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
11104 | 16 ## along with Octave; see the file COPYING. If not, see |
10081 | 17 ## <http://www.gnu.org/licenses/>. |
18 | |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10110
diff
changeset
|
20 ## @deftypefn {Function File} {@var{str} =} fileread (@var{filename}) |
12516
3d6584617da0
Add fileread to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
21 ## Read the contents of @var{filename} and return it as a string. |
3d6584617da0
Add fileread to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
22 ## @seealso{fread, textread, sscanf} |
10081 | 23 ## @end deftypefn |
24 | |
25 function str = fileread (filename) | |
26 | |
27 if (nargin != 1) | |
28 print_usage (); | |
29 endif | |
30 | |
31 if (! ischar (filename)) | |
13767
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
32 error ("fileread: FILENAME argument must be a string"); |
10081 | 33 endif |
34 | |
35 fid = fopen (filename, "r"); | |
36 if (fid < 0) | |
37 error ("fileread: cannot open file"); | |
38 endif | |
39 | |
40 unwind_protect | |
14416
59e20a5e2ca8
fileread() should return a row vector.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
41 str = (fread (fid, "*char")).'; |
10081 | 42 unwind_protect_cleanup |
10110
c146b308739f
missing semicolon in fileread
Jaroslav Hajek <highegg@gmail.com>
parents:
10081
diff
changeset
|
43 fclose (fid); |
10081 | 44 end_unwind_protect |
45 | |
46 endfunction | |
47 | |
13767
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
48 |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
49 %!test |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
50 %! cstr = {"Hello World", "The answer is 42", "Goodbye World"}; |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
51 %! fname = tempname (); |
13944
c9c063c32f99
test: Fix failing test in fileread.m due to EOL issues (Bug #34897)
Rik <octave@nomad.inbox5.com>
parents:
13767
diff
changeset
|
52 %! fid = fopen (fname, "w"); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 %! fprintf (fid, "%s\n", cstr{:}); |
13767
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
54 %! fclose (fid); |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
55 %! str = fileread (fname); |
16974
221e71d2aef0
Unlink tmp files in %!tests before doing asserts so that file is always removed.
Rik <rik@octave.org>
parents:
14428
diff
changeset
|
56 %! unlink (fname); |
14428
099bd779466c
test: Fix failing %!test in fileread.m
Rik <octave@nomad.inbox5.com>
parents:
14416
diff
changeset
|
57 %! assert (str, [cstr{1} "\n" cstr{2} "\n" cstr{3} "\n"]); |
13767
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
58 |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
59 %% Test input validation |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
60 %!error fileread () |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
61 %!error fileread (1, 2) |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
62 %!error <FILENAME argument must be a string> fileread (1) |
2b98014771b4
fileread.m: Add functional test.
Rik <octave@nomad.inbox5.com>
parents:
12516
diff
changeset
|
63 |