Mercurial > octave-nkf
annotate libinterp/corefcn/md5sum.cc @ 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 | 95c804dcc76c |
children | 4197fc428c7d |
rev | line source |
---|---|
6375 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 2007-2013 David Bateman |
6375 | 4 |
5 | |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
6375 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
6375 | 21 |
22 */ | |
23 | |
10039
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
25 #include <config.h> |
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
26 #endif |
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
27 |
6375 | 28 #include <string> |
29 #include <vector> | |
30 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
31 #include "defun.h" |
6383 | 32 #include "file-stat.h" |
33 #include "file-ops.h" | |
34 #include "load-path.h" | |
35 #include "oct-env.h" | |
6375 | 36 #include "oct-md5.h" |
19064
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
37 #include "utils.h" |
6375 | 38 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
39 DEFUN (md5sum, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
41 @deftypefn {Built-in Function} {} md5sum (@var{file})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
42 @deftypefnx {Built-in Function} {} md5sum (@var{str}, @var{opt})\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
43 Calculate the MD5 sum of the file @var{file}. If the second parameter\n\ |
6383 | 44 @var{opt} exists and is true, then calculate the MD5 sum of the\n\ |
45 string @var{str}.\n\ | |
6375 | 46 @end deftypefn") |
47 { | |
48 octave_value retval; | |
49 int nargin = args.length (); | |
50 | |
6383 | 51 if (nargin != 1 && nargin != 2) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
52 print_usage (); |
6375 | 53 else |
54 { | |
6383 | 55 bool have_str = false; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 std::string str = args(0).string_value (); |
6375 | 57 |
6383 | 58 if (nargin == 2) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 have_str = args(1).bool_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
60 |
6375 | 61 if (!error_state) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
62 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
63 if (have_str) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
64 retval = oct_md5 (str); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
65 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
66 { |
19064
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
67 std::string fname = file_ops::tilde_expand (str); |
6383 | 68 |
19064
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
69 fname = find_data_file_in_load_path ("md5sum", fname); |
6383 | 70 |
19064
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
71 retval = oct_md5_file (fname); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
72 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
73 } |
6375 | 74 } |
75 | |
76 return retval; | |
77 } | |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
78 |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
79 /* |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
80 %!assert (md5sum ("abc\0", true), "147a664a2ca9410911e61986d3f0d52a"); |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
81 |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
82 %!test |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19167
diff
changeset
|
83 %! tfile = tempname (); |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
84 %! fid = fopen (tfile, "wb"); |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
85 %! fwrite (fid, "abc\0"); |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
86 %! fclose (fid); |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
87 %! assert (md5sum (tfile), "147a664a2ca9410911e61986d3f0d52a"); |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
88 %! unlink (tfile); |
19167
95c804dcc76c
md5sum.cc: Codesprint: add test for empty argument list
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19064
diff
changeset
|
89 |
95c804dcc76c
md5sum.cc: Codesprint: add test for empty argument list
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19064
diff
changeset
|
90 %!error md5sum (); |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
91 */ |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
92 |