Back to index

glibc  2.9
getutid_r.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997, 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 <errno.h>
00023 #include <stdlib.h>
00024 #include <utmp.h>
00025 
00026 #include "utmp-private.h"
00027 
00028 
00029 /* We have to use the lock in getutent_r.c.  */
00030 __libc_lock_define (extern, __libc_utmp_lock attribute_hidden)
00031 
00032 
00033 int
00034 __getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
00035 {
00036 #if (_HAVE_UT_ID - 0) && (_HAVE_UT_TYPE - 0)
00037   int retval;
00038 
00039   /* Test whether ID has any of the legal types.  */
00040   if (id->ut_type != RUN_LVL && id->ut_type != BOOT_TIME
00041       && id->ut_type != OLD_TIME && id->ut_type != NEW_TIME
00042       && id->ut_type != INIT_PROCESS && id->ut_type != LOGIN_PROCESS
00043       && id->ut_type != USER_PROCESS && id->ut_type != DEAD_PROCESS)
00044     /* No, using '<' and '>' for the test is not possible.  */
00045     {
00046       __set_errno (EINVAL);
00047       *result = NULL;
00048       return -1;
00049     }
00050 
00051   __libc_lock_lock (__libc_utmp_lock);
00052 
00053   retval = (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
00054 
00055   __libc_lock_unlock (__libc_utmp_lock);
00056 
00057   return retval;
00058 #else  /* !_HAVE_UT_ID && !_HAVE_UT_TYPE */
00059   __set_errno (ENOSYS);
00060   return -1;
00061 #endif
00062 }
00063 weak_alias (__getutid_r, getutid_r)