comparison src/corefcn/getpwent.cc @ 15039:e753177cde93

maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory * __contourc__.cc, __dispatch__.cc, __lin_interpn__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bsxfun.cc, cellfun.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, det.cc, dlmread.cc, dot.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, filter.cc, find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, hess.cc, hex2num.cc, inv.cc, kron.cc, lookup.cc, lsode.cc, lu.cc, luinc.cc, matrix_type.cc, max.cc, md5sum.cc, mgorth.cc, nproc.cc, pinv.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, sub2ind.cc, svd.cc, syl.cc, time.cc, tril.cc, typecast.cc: Move functions from DLD-FUNCTIONS/ to corefcn/ directory. Include "defun.h", not "defun-dld.h". Change docstring to refer to these as "Built-in Functions". * build-aux/mk-opts.pl: Generate options code with '#include "defun.h"'. Change option docstrings to refer to these as "Built-in Functions". * corefcn/module.mk: List of functions to build in corefcn/ dir. * DLD-FUNCTIONS/config-module.awk: Update to new build system. * DLD-FUNCTIONS/module-files: Remove functions which are now in corefcn/ directory. * src/Makefile.am: Update to build "convenience library" in corefcn/. Octave program now links against all other libraries + corefcn libary. * src/find-defun-files.sh: Strip $srcdir from filename. * src/link-deps.mk: Add REGEX and FFTW link dependencies for liboctinterp. * type.m, which.m: Change failing tests to use 'amd', still a dynamic function, rather than 'dot', which isn't.
author Rik <rik@octave.org>
date Fri, 27 Jul 2012 15:35:00 -0700
parents src/DLD-FUNCTIONS/getpwent.cc@72c96de7a403
children
comparison
equal deleted inserted replaced
15038:ab18578c2ade 15039:e753177cde93
1 /*
2
3 Copyright (C) 1996-2012 John W. Eaton
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
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
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
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
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
31 #include "oct-passwd.h"
32
33 #include "defun.h"
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
44 mk_pw_map (const octave_passwd& pw)
45 {
46 octave_value retval;
47
48 if (pw)
49 {
50 octave_scalar_map m;
51
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 ());
59
60 retval = m;
61 }
62 else
63 retval = 0;
64
65 return retval;
66 }
67
68 DEFUN (getpwent, args, ,
69 "-*- texinfo -*-\n\
70 @deftypefn {Built-in Function} {@var{pw_struct} =} getpwent ()\n\
71 Return a structure containing an entry from the password database,\n\
72 opening it if necessary. Once the end of the data has been reached,\n\
73 @code{getpwent} returns 0.\n\
74 @end deftypefn")
75 {
76 octave_value_list retval;
77
78 retval(1) = std::string ();
79 retval(0) = 0;
80
81 int nargin = args.length ();
82
83 if (nargin == 0)
84 {
85 std::string msg;
86
87 retval(1) = msg;
88 retval(0) = mk_pw_map (octave_passwd::getpwent (msg));
89 }
90 else
91 print_usage ();
92
93 return retval;
94 }
95
96 DEFUN (getpwuid, args, ,
97 "-*- texinfo -*-\n\
98 @deftypefn {Built-in Function} {@var{pw_struct} =} getpwuid (@var{uid}).\n\
99 Return a structure containing the first entry from the password database\n\
100 with the user ID @var{uid}. If the user ID does not exist in the\n\
101 database, @code{getpwuid} returns 0.\n\
102 @end deftypefn")
103 {
104 octave_value_list retval;
105
106 retval(1) = std::string ();
107 retval(0) = 0;
108
109 int nargin = args.length ();
110
111 if (nargin == 1)
112 {
113 double dval = args(0).double_value ();
114
115 if (! error_state)
116 {
117 if (D_NINT (dval) == dval)
118 {
119 uid_t uid = static_cast<uid_t> (dval);
120
121 std::string msg;
122
123 retval(1) = msg;
124 retval(0) = mk_pw_map (octave_passwd::getpwuid (uid, msg));
125 }
126 else
127 error ("getpwuid: UID must be an integer");
128 }
129 }
130 else
131 print_usage ();
132
133 return retval;
134 }
135
136 DEFUN (getpwnam, args, ,
137 "-*- texinfo -*-\n\
138 @deftypefn {Built-in Function} {@var{pw_struct} =} getpwnam (@var{name})\n\
139 Return a structure containing the first entry from the password database\n\
140 with the user name @var{name}. If the user name does not exist in the\n\
141 database, @code{getpwname} returns 0.\n\
142 @end deftypefn")
143 {
144 octave_value_list retval;
145
146 retval(1) = std::string ();
147 retval(0) = 0.0;
148
149 int nargin = args.length ();
150
151 if (nargin == 1)
152 {
153 std::string s = args(0).string_value ();
154
155 if (! error_state)
156 {
157 std::string msg;
158
159 retval(1) = msg;
160 retval(0) = mk_pw_map (octave_passwd::getpwnam (s, msg));
161 }
162 }
163 else
164 print_usage ();
165
166 return retval;
167 }
168
169 DEFUN (setpwent, args, ,
170 "-*- texinfo -*-\n\
171 @deftypefn {Built-in Function} {} setpwent ()\n\
172 Return the internal pointer to the beginning of the password database.\n\
173 @end deftypefn")
174 {
175 octave_value_list retval;
176
177 retval(1) = std::string ();
178 retval(0) = -1.0;
179
180 int nargin = args.length ();
181
182 if (nargin == 0)
183 {
184 std::string msg;
185
186 retval(1) = msg;
187 retval(0) = static_cast<double> (octave_passwd::setpwent (msg));
188 }
189 else
190 print_usage ();
191
192 return retval;
193 }
194
195 DEFUN (endpwent, args, ,
196 "-*- texinfo -*-\n\
197 @deftypefn {Built-in Function} {} endpwent ()\n\
198 Close the password database.\n\
199 @end deftypefn")
200 {
201 octave_value_list retval;
202
203 retval(1) = std::string ();
204 retval(0) = -1.0;
205
206 int nargin = args.length ();
207
208 if (nargin == 0)
209 {
210 std::string msg;
211
212 retval(1) = msg;
213 retval(0) = static_cast<double> (octave_passwd::endpwent (msg));
214 }
215 else
216 print_usage ();
217
218 return retval;
219 }