Mercurial > octave
annotate libinterp/corefcn/getpwent.cc @ 20555:f90c8372b7ba
eliminate many more simple uses of error_state
* Cell.cc, __ichol__.cc, __ilu__.cc, balance.cc, bsxfun.cc, colloc.cc,
det.cc, dlmread.cc, dynamic-ld.cc, eig.cc, fft.cc, fft2.cc, fftn.cc,
gcd.cc, getgrent.cc, getpwent.cc, givens.cc, hess.cc, input.cc,
levenshtein.cc, load-path.cc, lookup.cc, ls-mat-ascii.cc, ls-mat4.cc,
lsode.cc, lu.cc, max.cc, md5sum.cc, mex.cc, pager.cc, pinv.cc,
pr-output.cc, qz.cc, schur.cc, sparse.cc, sqrtm.cc, str2double.cc,
strfns.cc, sub2ind.cc, sysdep.cc, time.cc, toplev.cc, tril.cc,
tsearch.cc, typecast.cc, __init_gnuplot__.cc, __magick_read__.cc,
__osmesa_print__.cc, amd.cc, audiodevinfo.cc, dmperm.cc, fftw.cc,
symrcm.cc, ov-base-diag.cc, ov-base-sparse.cc, ov-base.cc,
ov-bool-sparse.cc, ov-builtin.cc, ov-complex.cc, ov-cx-diag.cc,
ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc,
ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-lazy-idx.cc, ov-mex-fcn.cc,
ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, op-bm-b.cc, op-bm-bm.cc, op-sbm-b.cc,
op-sbm-bm.cc, op-str-m.cc, op-str-s.cc, oct-parse.in.yy, pt-cbinop.cc,
pt-colon.cc, pt-decl.cc, pt-exp.cc, pt-id.cc, pt-misc.cc,
pt-select.cc, pt-unop.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 19:29:36 -0400 |
parents | 4f45eaf83908 |
children | c22206c1a88f |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <string> | |
28 | |
29 #include <sys/types.h> | |
30 | |
2933 | 31 #include "oct-passwd.h" |
2928 | 32 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
33 #include "defun.h" |
2928 | 34 #include "error.h" |
35 #include "gripes.h" | |
36 #include "oct-map.h" | |
37 #include "ov.h" | |
38 #include "oct-obj.h" | |
39 #include "utils.h" | |
40 | |
41 // Password file functions. (Why not?) | |
42 | |
43 static octave_value | |
2933 | 44 mk_pw_map (const octave_passwd& pw) |
2928 | 45 { |
46 octave_value retval; | |
47 | |
48 if (pw) | |
49 { | |
11043
e9966851619b
getpwent.cc, getgrent.cc, getrusage.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
50 octave_scalar_map m; |
2928 | 51 |
4675 | 52 m.assign ("name", pw.name ()); |
53 m.assign ("passwd", pw.passwd ()); | |
54 m.assign ("uid", static_cast<double> (pw.uid ())); | |
55 m.assign ("gid", static_cast<double> (pw.gid ())); | |
56 m.assign ("gecos", pw.gecos ()); | |
57 m.assign ("dir", pw.dir ()); | |
58 m.assign ("shell", pw.shell ()); | |
2928 | 59 |
60 retval = m; | |
61 } | |
62 else | |
4233 | 63 retval = 0; |
2928 | 64 |
65 return retval; | |
66 } | |
67 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
68 DEFUN (getpwent, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
70 @deftypefn {Built-in Function} {@var{pw_struct} =} getpwent ()\n\ |
3301 | 71 Return a structure containing an entry from the password database,\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
72 opening it if necessary.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
73 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
74 Once the end of the data has been reached, @code{getpwent} returns 0.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
75 @seealso{setpwent, endpwent}\n\ |
3301 | 76 @end deftypefn") |
2928 | 77 { |
2937 | 78 octave_value_list retval; |
79 | |
3523 | 80 retval(1) = std::string (); |
4233 | 81 retval(0) = 0; |
2928 | 82 |
83 int nargin = args.length (); | |
84 | |
85 if (nargin == 0) | |
2937 | 86 { |
3523 | 87 std::string msg; |
2937 | 88 |
14022
de90542b7afc
Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
89 retval(1) = msg; |
2937 | 90 retval(0) = mk_pw_map (octave_passwd::getpwent (msg)); |
91 } | |
2928 | 92 else |
5823 | 93 print_usage (); |
2928 | 94 |
95 return retval; | |
96 } | |
97 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
98 DEFUN (getpwuid, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
100 @deftypefn {Built-in Function} {@var{pw_struct} =} getpwuid (@var{uid}).\n\ |
3301 | 101 Return a structure containing the first entry from the password database\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
102 with the user ID @var{uid}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
103 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
104 If the user ID does not exist in the database, @code{getpwuid} returns 0.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
105 @seealso{getpwnam}\n\ |
3301 | 106 @end deftypefn") |
2928 | 107 { |
2937 | 108 octave_value_list retval; |
109 | |
3523 | 110 retval(1) = std::string (); |
4233 | 111 retval(0) = 0; |
2928 | 112 |
113 int nargin = args.length (); | |
114 | |
115 if (nargin == 1) | |
116 { | |
117 double dval = args(0).double_value (); | |
118 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
119 if (D_NINT (dval) == dval) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
120 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
121 uid_t uid = static_cast<uid_t> (dval); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
122 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
123 std::string msg; |
2928 | 124 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
125 retval(1) = msg; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
126 retval(0) = mk_pw_map (octave_passwd::getpwuid (uid, msg)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
127 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
128 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
129 error ("getpwuid: UID must be an integer"); |
2928 | 130 } |
131 else | |
5823 | 132 print_usage (); |
2928 | 133 |
134 return retval; | |
135 } | |
136 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
137 DEFUN (getpwnam, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
139 @deftypefn {Built-in Function} {@var{pw_struct} =} getpwnam (@var{name})\n\ |
3301 | 140 Return a structure containing the first entry from the password database\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
141 with the user name @var{name}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
142 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
143 If the user name does not exist in the database, @code{getpwname} returns 0.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
144 @seealso{getpwuid}\n\ |
3301 | 145 @end deftypefn") |
2928 | 146 { |
2937 | 147 octave_value_list retval; |
148 | |
3523 | 149 retval(1) = std::string (); |
2937 | 150 retval(0) = 0.0; |
2928 | 151 |
152 int nargin = args.length (); | |
153 | |
154 if (nargin == 1) | |
155 { | |
3523 | 156 std::string s = args(0).string_value (); |
2928 | 157 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
158 std::string msg; |
2937 | 159 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
160 retval(1) = msg; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
161 retval(0) = mk_pw_map (octave_passwd::getpwnam (s, msg)); |
2928 | 162 } |
163 else | |
5823 | 164 print_usage (); |
2928 | 165 |
166 return retval; | |
167 } | |
168 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
169 DEFUN (setpwent, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
170 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
171 @deftypefn {Built-in Function} {} setpwent ()\n\ |
3301 | 172 Return the internal pointer to the beginning of the password database.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
173 @seealso{getpwent, endpwent}\n\ |
3301 | 174 @end deftypefn") |
2928 | 175 { |
2937 | 176 octave_value_list retval; |
177 | |
3523 | 178 retval(1) = std::string (); |
2937 | 179 retval(0) = -1.0; |
2928 | 180 |
181 int nargin = args.length (); | |
182 | |
183 if (nargin == 0) | |
2937 | 184 { |
3523 | 185 std::string msg; |
2937 | 186 |
14022
de90542b7afc
Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
187 retval(1) = msg; |
2937 | 188 retval(0) = static_cast<double> (octave_passwd::setpwent (msg)); |
189 } | |
2928 | 190 else |
5823 | 191 print_usage (); |
2928 | 192 |
193 return retval; | |
194 } | |
195 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
196 DEFUN (endpwent, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
198 @deftypefn {Built-in Function} {} endpwent ()\n\ |
3301 | 199 Close the password database.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
200 @seealso{getpwent, setpwent}\n\ |
3301 | 201 @end deftypefn") |
2928 | 202 { |
2937 | 203 octave_value_list retval; |
204 | |
3523 | 205 retval(1) = std::string (); |
2937 | 206 retval(0) = -1.0; |
2928 | 207 |
208 int nargin = args.length (); | |
209 | |
210 if (nargin == 0) | |
2937 | 211 { |
3523 | 212 std::string msg; |
2937 | 213 |
14022
de90542b7afc
Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
214 retval(1) = msg; |
2937 | 215 retval(0) = static_cast<double> (octave_passwd::endpwent (msg)); |
216 } | |
2928 | 217 else |
5823 | 218 print_usage (); |
2928 | 219 |
220 return retval; | |
221 } |