Back to index

glibc  2.9
getutent_r.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996-1998,2000,2001,2002,2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@cygnus.com>
00004    and Paul Janzen <pcj@primenet.com>, 1996.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <bits/libc-lock.h>
00022 #include <stdlib.h>
00023 #include <utmp.h>
00024 
00025 #include "utmp-private.h"
00026 
00027 
00028 /* Functions defined here.  */
00029 static int setutent_unknown (void);
00030 static int getutent_r_unknown (struct utmp *buffer, struct utmp **result);
00031 static int getutid_r_unknown (const struct utmp *line, struct utmp *buffer,
00032                            struct utmp **result);
00033 static int getutline_r_unknown (const struct utmp *id, struct utmp *buffer,
00034                             struct utmp **result);
00035 static struct utmp *pututline_unknown (const struct utmp *data);
00036 static void endutent_unknown (void);
00037 
00038 /* Initial Jump table.  */
00039 const struct utfuncs __libc_utmp_unknown_functions =
00040 {
00041   setutent_unknown,
00042   getutent_r_unknown,
00043   getutid_r_unknown,
00044   getutline_r_unknown,
00045   pututline_unknown,
00046   endutent_unknown,
00047   NULL
00048 };
00049 
00050 /* Currently selected backend.  */
00051 const struct utfuncs *__libc_utmp_jump_table = &__libc_utmp_unknown_functions;
00052 
00053 /* We need to protect the opening of the file.  */
00054 __libc_lock_define_initialized (, __libc_utmp_lock attribute_hidden)
00055 
00056 
00057 static int
00058 setutent_unknown (void)
00059 {
00060   int result;
00061 
00062   result = (*__libc_utmp_file_functions.setutent) ();
00063   if (result)
00064     __libc_utmp_jump_table = &__libc_utmp_file_functions;
00065 
00066   return result;
00067 }
00068 
00069 
00070 static int
00071 getutent_r_unknown (struct utmp *buffer, struct utmp **result)
00072 {
00073   /* The backend was not yet initialized.  */
00074   if (setutent_unknown ())
00075     return (*__libc_utmp_jump_table->getutent_r) (buffer, result);
00076 
00077   /* Not available.  */
00078   *result = NULL;
00079   return -1;
00080 }
00081 
00082 
00083 static int
00084 getutid_r_unknown (const struct utmp *id, struct utmp *buffer,
00085                  struct utmp **result)
00086 {
00087   /* The backend was not yet initialized.  */
00088   if (setutent_unknown ())
00089     return (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
00090 
00091   /* Not available.  */
00092   *result = NULL;
00093   return -1;
00094 }
00095 
00096 
00097 static int
00098 getutline_r_unknown (const struct utmp *line, struct utmp *buffer,
00099                    struct utmp **result)
00100 {
00101   /* The backend was not yet initialized.  */
00102   if (setutent_unknown ())
00103     return (*__libc_utmp_jump_table->getutline_r) (line, buffer, result);
00104 
00105   /* Not available.  */
00106   *result = NULL;
00107   return -1;
00108 }
00109 
00110 
00111 static struct utmp *
00112 pututline_unknown (const struct utmp *data)
00113 {
00114   /* The backend was not yet initialized.  */
00115   if (setutent_unknown ())
00116     return (*__libc_utmp_jump_table->pututline) (data);
00117 
00118   /* Not available.  */
00119   return NULL;
00120 }
00121 
00122 
00123 static void
00124 endutent_unknown (void)
00125 {
00126   /* Nothing to do.  */
00127 }
00128 
00129 
00130 void
00131 __setutent (void)
00132 {
00133   __libc_lock_lock (__libc_utmp_lock);
00134 
00135   (*__libc_utmp_jump_table->setutent) ();
00136 
00137   __libc_lock_unlock (__libc_utmp_lock);
00138 }
00139 weak_alias (__setutent, setutent)
00140 
00141 
00142 int
00143 __getutent_r (struct utmp *buffer, struct utmp **result)
00144 {
00145   int retval;
00146 
00147   __libc_lock_lock (__libc_utmp_lock);
00148 
00149   retval = (*__libc_utmp_jump_table->getutent_r) (buffer, result);
00150 
00151   __libc_lock_unlock (__libc_utmp_lock);
00152 
00153   return retval;
00154 }
00155 weak_alias (__getutent_r, getutent_r)
00156 
00157 
00158 struct utmp *
00159 __pututline (const struct utmp *data)
00160 {
00161   struct utmp *buffer;
00162 
00163   __libc_lock_lock (__libc_utmp_lock);
00164 
00165   buffer = (*__libc_utmp_jump_table->pututline) (data);
00166 
00167   __libc_lock_unlock (__libc_utmp_lock);
00168 
00169   return buffer;
00170 }
00171 weak_alias (__pututline, pututline)
00172 
00173 
00174 void
00175 __endutent (void)
00176 {
00177   __libc_lock_lock (__libc_utmp_lock);
00178 
00179   (*__libc_utmp_jump_table->endutent) ();
00180   __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
00181 
00182   __libc_lock_unlock (__libc_utmp_lock);
00183 }
00184 weak_alias (__endutent, endutent)