1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/getlogin.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,109 @@
1.4 +// getlogin.c
1.5 +//
1.6 +//
1.7 +/*
1.8 + * Copyright (c) 1988, 1993
1.9 + * The Regents of the University of California. All rights reserved.
1.10 + *
1.11 + * Redistribution and use in source and binary forms, with or without
1.12 + * modification, are permitted provided that the following conditions
1.13 + * are met:
1.14 + * 1. Redistributions of source code must retain the above copyright
1.15 + * notice, this list of conditions and the following disclaimer.
1.16 + * 2. Redistributions in binary form must reproduce the above copyright
1.17 + * notice, this list of conditions and the following disclaimer in the
1.18 + * documentation and/or other materials provided with the distribution.
1.19 + * 4. Neither the name of the University nor the names of its contributors
1.20 + * may be used to endorse or promote products derived from this software
1.21 + * without specific prior written permission.
1.22 + *
1.23 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1.24 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.25 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.26 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1.27 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.28 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.29 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.30 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.31 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.32 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.33 + * SUCH DAMAGE.
1.34 + */
1.35 +
1.36 + /* Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */
1.37 +
1.38 +#if defined(LIBC_SCCS) && !defined(lint)
1.39 +static char sccsid[] = "@(#)getlogin.c 8.1 (Berkeley) 6/4/93";
1.40 +#endif /* LIBC_SCCS and not lint */
1.41 +#include <sys/cdefs.h>
1.42 +__FBSDID("$FreeBSD: src/lib/libc/gen/getlogin.c,v 1.9 2003/10/29 10:45:01 tjr Exp $");
1.43 +
1.44 +#include <sys/param.h>
1.45 +#include <errno.h>
1.46 +#include <pwd.h>
1.47 +#include <utmp.h>
1.48 +#include <stdio.h>
1.49 +#include <string.h>
1.50 +#include <unistd.h>
1.51 +#include "namespace.h"
1.52 +#include <pthread.h>
1.53 +#include "un-namespace.h"
1.54 +
1.55 +#include "libc_private.h"
1.56 +
1.57 +#define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex)
1.58 +#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex)
1.59 +
1.60 +extern int _getlogin(char *, int);
1.61 +
1.62 +int _logname_valid; /* known to setlogin() */
1.63 +static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER;
1.64 +
1.65 +static char *
1.66 +getlogin_basic(int *status)
1.67 +{
1.68 + static char logname[MAXLOGNAME];
1.69 +
1.70 + if (_logname_valid == 0) {
1.71 + if (/*_getlogin(logname, sizeof(logname)) < 0*/ 1 ) {
1.72 + *status = errno;
1.73 + return (NULL);
1.74 + }
1.75 + _logname_valid = 1;
1.76 + }
1.77 + *status = 0;
1.78 + return (*logname ? logname : NULL);
1.79 +}
1.80 +
1.81 +char *
1.82 +getlogin(void)
1.83 +{
1.84 + char *result;
1.85 + int status;
1.86 +
1.87 + THREAD_LOCK();
1.88 + result = getlogin_basic(&status);
1.89 + THREAD_UNLOCK();
1.90 + return (result);
1.91 +}
1.92 +
1.93 +#ifndef __SYMBIAN32__
1.94 +int
1.95 +getlogin_r(char *logname, int namelen)
1.96 +{
1.97 + char *result;
1.98 + int len;
1.99 + int status;
1.100 +
1.101 + THREAD_LOCK();
1.102 + result = getlogin_basic(&status);
1.103 + if (status == 0) {
1.104 + if ((len = strlen(result) + 1) > namelen)
1.105 + status = ERANGE;
1.106 + else
1.107 + strncpy(logname, result, len);
1.108 + }
1.109 + THREAD_UNLOCK();
1.110 + return (status);
1.111 +}
1.112 +#endif //__SYMBIAN32__