メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

oct-group.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #ifdef HAVE_SYS_TYPES_H
00028 #include <sys/types.h>
00029 #endif
00030 
00031 #ifdef HAVE_GRP_H
00032 #include <grp.h>
00033 #endif
00034 
00035 #include "lo-error.h"
00036 #include "oct-group.h"
00037 #include "str-vec.h"
00038 
00039 #define NOT_SUPPORTED(nm) \
00040   nm ": not supported on this system"
00041 
00042 std::string
00043 octave_group::name (void) const
00044 {
00045   if (! ok ())
00046     gripe_invalid ();
00047 
00048   return gr_name;
00049 }
00050 
00051 std::string
00052 octave_group::passwd (void) const
00053 {
00054   if (! ok ())
00055     gripe_invalid ();
00056 
00057   return gr_passwd;
00058 }
00059 
00060 gid_t
00061 octave_group::gid (void) const
00062 {
00063   if (! ok ())
00064     gripe_invalid ();
00065 
00066   return gr_gid;
00067 }
00068 
00069 string_vector
00070 octave_group::mem (void) const
00071 {
00072   if (! ok ())
00073     gripe_invalid ();
00074 
00075   return gr_mem;
00076 }
00077 
00078 octave_group
00079 octave_group::getgrent (void)
00080 {
00081   std::string msg;
00082   return getgrent (msg);
00083 }
00084 
00085 octave_group
00086 octave_group::getgrent (std::string& msg)
00087 {
00088 #if defined (HAVE_GETGRENT)
00089   msg = std::string ();
00090   return octave_group (::getgrent (), msg);
00091 #else
00092   msg = NOT_SUPPORTED ("getgrent");
00093   return octave_group ();
00094 #endif
00095 }
00096 
00097 octave_group
00098 octave_group::getgrgid (gid_t gid)
00099 {
00100   std::string msg;
00101   return getgrgid (gid, msg);
00102 }
00103 
00104 octave_group
00105 octave_group::getgrgid (gid_t gid, std::string& msg)
00106 {
00107 #if defined (HAVE_GETGRGID)
00108   msg = std::string ();
00109   return octave_group (::getgrgid (gid), msg);
00110 #else
00111   msg = NOT_SUPPORTED ("getgruid");
00112   return octave_group ();
00113 #endif
00114 }
00115 
00116 octave_group
00117 octave_group::getgrnam (const std::string& nm)
00118 {
00119   std::string msg;
00120   return getgrnam (nm, msg);
00121 }
00122 
00123 octave_group
00124 octave_group::getgrnam (const std::string& nm, std::string& msg)
00125 {
00126 #if defined (HAVE_GETGRNAM)
00127   msg = std::string ();
00128   return octave_group (::getgrnam (nm.c_str ()), msg);
00129 #else
00130   msg = NOT_SUPPORTED ("getgrnam");
00131   return octave_group ();
00132 #endif
00133 }
00134 
00135 int
00136 octave_group::setgrent (void)
00137 {
00138   std::string msg;
00139   return setgrent (msg);
00140 }
00141 
00142 int
00143 octave_group::setgrent (std::string& msg)
00144 {
00145 #if defined (HAVE_SETGRENT)
00146   msg = std::string ();
00147   ::setgrent ();
00148   return 0;
00149 #else
00150   msg = NOT_SUPPORTED ("setgrent");
00151   return -1;
00152 #endif
00153 }
00154 
00155 int
00156 octave_group::endgrent (void)
00157 {
00158   std::string msg;
00159   return endgrent (msg);
00160 }
00161 
00162 int
00163 octave_group::endgrent (std::string& msg)
00164 {
00165 #if defined (HAVE_ENDGRENT)
00166   msg = std::string ();
00167   ::endgrent ();
00168   return 0;
00169 #else
00170   msg = NOT_SUPPORTED ("endgrent");
00171   return -1;
00172 #endif
00173 }
00174 
00175 octave_group::octave_group (void *p, std::string& msg)
00176   : gr_name (), gr_passwd (), gr_gid (0), gr_mem (), valid (false)
00177 {
00178 #if defined (HAVE_GRP_H)
00179   msg = std::string ();
00180 
00181   if (p)
00182     {
00183       struct group *gr = static_cast<struct group *> (p);
00184 
00185       gr_name = gr->gr_name;
00186 
00187 #if defined (HAVE_GR_PASSWD)
00188       gr_passwd = gr->gr_passwd;
00189 #endif
00190 
00191       gr_gid = gr->gr_gid;
00192 
00193       // XXX FIXME XXX -- maybe there should be a string_vector
00194       // constructor that takes a NULL terminated list of C
00195       // strings.
00196 
00197       const char * const *tmp = gr->gr_mem;
00198 
00199       int k = 0;
00200       while (*tmp++)
00201         k++;
00202 
00203       if (k > 0)
00204         {
00205           tmp = gr->gr_mem;
00206 
00207           gr_mem.resize (k);
00208 
00209           for (int i = 0; i < k; i++)
00210             gr_mem[i] = tmp[i];
00211         }
00212 
00213       valid = true;
00214     }
00215 #else
00216   msg = NOT_SUPPORTED ("group functions");
00217 #endif
00218 }
00219 
00220 void
00221 octave_group::gripe_invalid (void) const
00222 {
00223   (*current_liboctave_error_handler) ("invalid group object");
00224 }
00225 
00226 /*
00227 ;;; Local Variables: ***
00228 ;;; mode: C++ ***
00229 ;;; End: ***
00230 */

Wed Dec 29 11:52:07 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送