GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pwd-wrappers.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2023-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 // pwd.h might set some preprocessor definitions that replace Octave functions
27 // in compilation units where it is included. Use these wrappers to avoid that.
28 
29 #if defined (HAVE_CONFIG_H)
30 # include "config.h"
31 #endif
32 
33 #if defined (HAVE_PWD_H)
34 # include <pwd.h>
35 #endif
36 
37 #include "pwd-wrappers.h"
38 
39 struct passwd *octave_getpwent_wrapper (void)
40 {
41 #if defined HAVE_GETPWENT
42  return getpwent ();
43 #else
44  return NULL;
45 #endif
46 }
47 
48 struct passwd *octave_getpwuid_wrapper (uid_t uid)
49 {
50 #if defined (HAVE_GETPWUID)
51  return getpwuid (uid);
52 #else
53  octave_unused_parameter (uid);
54 
55  return NULL;
56 #endif
57 }
58 
59 struct passwd *octave_getpwnam_wrapper (const char *nam)
60 {
61 #if defined (HAVE_GETPWNAM)
62  return getpwnam (nam);
63 #else
64  octave_unused_parameter (nam);
65 
66  return NULL;
67 #endif
68 }
69 
71 {
72 #if defined (HAVE_SETPWENT)
73  setpwent ();
74 #endif
75  return;
76 }
77 
79 {
80 #if defined (HAVE_ENDPWENT)
81  endpwent ();
82 #endif
83  return;
84 }
85 
86 void octave_from_passwd (const struct passwd *pw,
87  struct octave_passwd_wrapper *oct_pw)
88 {
89 #if defined (HAVE_PWD_H)
90  oct_pw->pw_name = pw->pw_name;
91  oct_pw->pw_passwd = pw->pw_passwd;
92  oct_pw->pw_uid = pw->pw_uid;
93  oct_pw->pw_gid = pw->pw_gid;
94  oct_pw->pw_gecos = pw->pw_gecos;
95  oct_pw->pw_dir = pw->pw_dir;
96  oct_pw->pw_shell = pw->pw_shell;
97 #else
98  octave_unused_parameter (pw);
99  octave_unused_parameter (oct_pw);
100 #endif
101  return;
102 }
void octave_setpwent_wrapper(void)
Definition: pwd-wrappers.c:70
struct passwd * octave_getpwnam_wrapper(const char *nam)
Definition: pwd-wrappers.c:59
void octave_endpwent_wrapper(void)
Definition: pwd-wrappers.c:78
struct passwd * octave_getpwent_wrapper(void)
Definition: pwd-wrappers.c:39
struct passwd * octave_getpwuid_wrapper(uid_t uid)
Definition: pwd-wrappers.c:48
void octave_from_passwd(const struct passwd *pw, struct octave_passwd_wrapper *oct_pw)
Definition: pwd-wrappers.c:86