New utility to get home directory of user.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/tools/make/trunk@12887 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-02-28 15:01:51 +00:00
parent ba5043927b
commit 6ed46fa8e1
6 changed files with 286 additions and 48 deletions

View file

@ -1,3 +1,9 @@
2002-02-28 Richard Frith-Macdonald <rfm@gnu.org>
* user_home.c: new utility to report users home directory.
* configure.in: check for password file stuff etc.
* GNUmakefile.in: build user_home
Thu Feb 28 14:35:27 2002 Nicola Pero <nicola@brainstorm.co.uk>
* Instance/rules.make (.PHONY): Declare here as .PHONY

View file

@ -102,10 +102,13 @@ INSTANCE_MAKE_FILES = \
INSTANCE_SHARED_MAKE_FILES = bundle.make headers.make java.make
all: generated-files which_lib$(EXEEXT)
all: generated-files which_lib$(EXEEXT) user_home$(EXEEXT)
which_lib$(EXEEXT): which_lib.c
$(CC) @CFLAGS@ -Wall -I. -o $@ $^
which_lib$(EXEEXT): which_lib.c config.h
$(CC) @CFLAGS@ -Wall -I. -o $@ which_lib.c
user_home$(EXEEXT): user_home.c config.h
$(CC) @CFLAGS@ -Wall -I. -o $@ user_home.c
install: all
@ -153,7 +156,10 @@ install: all
$(GNUSTEP_LOCAL_ROOT)/Users \
$(GNUSTEP_LOCAL_ROOT)/Users/Administrator \
$(GNUSTEP_NETWORK_ROOT)
$(INSTALL_PROGRAM) -m 755 which_lib$(EXEEXT) $(makedir)/$(GNUSTEP_TARGET_DIR)
$(INSTALL_PROGRAM) -m 755 which_lib$(EXEEXT) \
$(makedir)/$(GNUSTEP_TARGET_DIR)
$(INSTALL_PROGRAM) -m 755 user_home$(EXEEXT) \
$(makedir)/$(GNUSTEP_TARGET_DIR)
for f in config.guess config.sub install-sh mkinstalldirs \
clean_cpu.sh clean_os.sh \
clean_vendor.sh cpu.sh \
@ -198,6 +204,7 @@ install: all
uninstall:
rm -f $(makedir)/$(GNUSTEP_TARGET_DIR)/which_lib$(EXEEXT)
rm -f $(makedir)/$(GNUSTEP_TARGET_DIR)/user_home$(EXEEXT)
for f in config.guess config.sub install-sh mkinstalldirs \
clean_cpu.sh clean_os.sh \
clean_vendor.sh cpu.sh ld_lib_path.sh os.sh \
@ -217,7 +224,8 @@ uninstall:
rm -f $(makedir)/$(GNUSTEP_TARGET_DIR)/config.make
clean:
rm -f *~ which_lib$(EXEEXT) Master/*~ Instance/*~ Instance/Shared/*~
rm -f *~ which_lib$(EXEEXT) user_home$(EXEEXT) \
Master/*~ Instance/*~ Instance/Shared/*~
distclean: clean
rm -f GNUmakefile config.make config.h

View file

@ -1,32 +1,52 @@
#ifndef __config_h__
#define __config_h__
/* config.h.in. Generated automatically from configure.in by autoheader 2.13. */
/* Define if you have the <sys/param.h> header file */
#undef HAVE_SYS_PARAM_H
/* Define if you have the geteuid function. */
#undef HAVE_GETEUID
/* Define if you have the <sys/file.h> header file */
#undef HAVE_SYS_FILE_H
/* Define if you have the getlogin function. */
#undef HAVE_GETLOGIN
/* Define if you have the getpwnam function. */
#undef HAVE_GETPWNAM
/* Define if you have the getpwuid function. */
#undef HAVE_GETPWUID
/* Define if you have the <dir.h> header file. */
#undef HAVE_DIR_H
/* Define if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H
/* Define if you have the <ndir.h> header file. */
#undef HAVE_NDIR_H
/* Define if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
/* Define if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define if you have the <sys/dir.h> header file. */
#undef HAVE_SYS_DIR_H
/* Define if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H
/* Define if you have the <sys/stat.h> header file */
/* Define if you have the <sys/ndir.h> header file. */
#undef HAVE_SYS_NDIR_H
/* Define if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define if you have the <sys/errno.h> header file */
#undef HAVE_SYS_ERRNO_H
/* Define if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* The following macros deal with directory entries. */
#undef HAVE_DIRENT_H
#undef HAVE_SYS_NDIR_H
#undef HAVE_SYS_DIR_H
#undef HAVE_NDIR_H
#undef HAVE_DIR_H
#endif /* __config_h__ */
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

95
configure vendored
View file

@ -1776,7 +1776,7 @@ LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$gs_cv_objc_libdir"
export LD_LIBRARY_PATH
#--------------------------------------------------------------------
# Miscellaneous headers (only used for compiling which_lib.c)
# Miscellaneous headers (only used for compiling which_lib.c and user_home.c)
#--------------------------------------------------------------------
ac_header_dirent=no
for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h
@ -1903,7 +1903,7 @@ fi
fi
for ac_hdr in sys/param.h sys/file.h dir.h string.h stdlib.h sys/types.h sys/stat.h
for ac_hdr in sys/param.h sys/file.h dir.h string.h stdlib.h sys/types.h sys/stat.h pwd.h unistd.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
@ -1943,6 +1943,61 @@ else
fi
done
for ac_func in getpwnam getpwuid geteuid getlogin
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:1950: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1955 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
#include <assert.h>
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $ac_func();
int main() {
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
$ac_func();
#endif
; return 0; }
EOF
if { (eval echo configure:1978: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_func_$ac_func=no"
fi
rm -f conftest*
fi
if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
cat >> confdefs.h <<EOF
#define $ac_tr_func 1
EOF
else
echo "$ac_t""no" 1>&6
fi
done
#--------------------------------------------------------------------
# Check if libobjc was compiled with thread support.
@ -1960,7 +2015,7 @@ fi
echo $ac_n "checking whether objc has thread support""... $ac_c" 1>&6
echo "configure:1964: checking whether objc has thread support" >&5
echo "configure:2019: checking whether objc has thread support" >&5
extra_LIBS=""
case "${target_os}" in
solaris*)
@ -1979,11 +2034,11 @@ if test "$OBJC_THREAD" != ""; then
objc_threaded=""
else
cat > conftest.$ac_ext <<EOF
#line 1983 "configure"
#line 2038 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:1987: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2042: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="$OBJC_THREAD $extra_LIBS"
else
@ -2001,11 +2056,11 @@ elif test "$host_os" = linux-gnu; then
objc_threaded="-lpthread"
else
cat > conftest.$ac_ext <<EOF
#line 2005 "configure"
#line 2060 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:2009: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2064: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="-lpthread"
else
@ -2023,11 +2078,11 @@ elif test "`echo $host_os|sed 's/[0-9].*//'|sed s/elf//`" = freebsd; then
objc_threaded="-pthread"
else
cat > conftest.$ac_ext <<EOF
#line 2027 "configure"
#line 2082 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:2031: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2086: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="-pthread"
else
@ -2045,11 +2100,11 @@ fi
objc_threaded="-lpthread"
else
cat > conftest.$ac_ext <<EOF
#line 2049 "configure"
#line 2104 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:2053: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2108: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="-lpthread"
else
@ -2068,11 +2123,11 @@ fi
objc_threaded="-lpcthread"
else
cat > conftest.$ac_ext <<EOF
#line 2072 "configure"
#line 2127 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:2076: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2131: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="-lpcthread"
else
@ -2092,11 +2147,11 @@ elif test "$MINGW32" = yes; then
objc_threaded="works"
else
cat > conftest.$ac_ext <<EOF
#line 2096 "configure"
#line 2151 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:2100: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2155: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="works"
else
@ -2114,11 +2169,11 @@ else
objc_threaded=""
else
cat > conftest.$ac_ext <<EOF
#line 2118 "configure"
#line 2173 "configure"
#include "confdefs.h"
#include "config_thread.m"
EOF
if { (eval echo configure:2122: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:2177: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
objc_threaded="-lthread $extra_LIBS"
else
@ -2150,7 +2205,7 @@ ac_cv_objc_threaded="$objc_threaded"
#--------------------------------------------------------------------
echo $ac_n "checking if the compiler supports autodependencies""... $ac_c" 1>&6
echo "configure:2154: checking if the compiler supports autodependencies" >&5
echo "configure:2209: checking if the compiler supports autodependencies" >&5
# What we want to do: set AUTO_DEPENDENCIES to yes if gcc => 3.x
@ -2184,7 +2239,7 @@ fi
# Enable/disable warnings for deprecated #import directive as required
#---------------------------------------------------------------------
echo $ac_n "checking whether to disable compiler warnings about deprecated import""... $ac_c" 1>&6
echo "configure:2188: checking whether to disable compiler warnings about deprecated import" >&5
echo "configure:2243: checking whether to disable compiler warnings about deprecated import" >&5
#
# GCC recommends that you use `--disable-import' here, since #import
@ -2210,7 +2265,7 @@ fi
# Record the version
#--------------------------------------------------------------------
echo $ac_n "checking for the version of gnustep-make we are compiling""... $ac_c" 1>&6
echo "configure:2214: checking for the version of gnustep-make we are compiling" >&5
echo "configure:2269: checking for the version of gnustep-make we are compiling" >&5
. "$srcdir/Version"
echo "$ac_t""$GNUSTEP_MAKE_VERSION" 1>&6

View file

@ -320,11 +320,12 @@ LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$gs_cv_objc_libdir"
export LD_LIBRARY_PATH
#--------------------------------------------------------------------
# Miscellaneous headers (only used for compiling which_lib.c)
# Miscellaneous headers (only used for compiling which_lib.c and user_home.c)
#--------------------------------------------------------------------
AC_HEADER_DIRENT
AC_HAVE_HEADERS(sys/param.h sys/file.h dir.h string.h stdlib.h sys/types.h dnl
sys/stat.h)
sys/stat.h pwd.h unistd.h)
AC_CHECK_FUNCS(getpwnam getpwuid geteuid getlogin)
#--------------------------------------------------------------------
# Check if libobjc was compiled with thread support.

148
user_home.c Normal file
View file

@ -0,0 +1,148 @@
/*
user_home.c
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: February 2002
This file is part of the GNUstep Makefile Package.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h"
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_PWD_H
# include <pwd.h>
#endif
/* NOTE FOR DEVELOPERS.
* If you change the behavior of this method you must also change
* NSUser.m in the base library package to match.
*/
int main (int argc, char** argv)
{
#if defined(__MINGW__)
char buf0[1024];
char buf1[1024];
int len0;
int len1;
#else
struct passwd *pw;
#endif
const char *loginName = 0;
if (loginName == 0)
{
#if defined(__WIN32__)
/* The GetUserName function returns the current user name */
DWORD n = 1024;
len0 = GetEnvironmentVariable("LOGNAME", buf0, 1024);
if (len0 > 0 && len0 < 1024)
{
loginName = buf0;
loginName[len0] = '\0';
}
else if (GetUserName(buf0, &n))
{
loginName = buf0;
}
#else
loginName = getenv("LOGNAME");
#if HAVE_GETPWNAM
/*
* Check that LOGNAME contained legal name.
*/
if (loginName != 0 && getpwnam(loginName) == 0)
{
loginName = 0;
}
#endif /* HAVE_GETPWNAM */
#if HAVE_GETLOGIN
/*
* Try getlogin() if LOGNAME environmentm variable didn't work.
*/
if (loginName == 0)
{
loginName = getlogin();
}
#endif /* HAVE_GETLOGIN */
#if HAVE_GETPWUID
/*
* Try getting the name of the effective user as a last resort.
*/
if (loginName == 0)
{
#if HAVE_GETEUID
int uid = geteuid();
#else
int uid = getuid();
#endif /* HAVE_GETEUID */
struct passwd *pwent = getpwuid (uid);
loginName = pwent->pw_name;
}
#endif /* HAVE_GETPWUID */
#endif
if (loginName == 0)
{
fprintf(stderr, "Unable to determine current user name.\n");
return 1;
}
}
#if !defined(__MINGW__)
pw = getpwnam (loginName);
if (pw == 0)
{
fprintf(stderr, "Unable to locate home directory for '%s'\n", loginName);
return 1;
}
printf("%s", pw->pw_dir);
return 0;
#else
/* Then environment variable HOMEPATH holds the home directory
for the user on Windows NT; Win95 has no concept of home. */
len0 = GetEnvironmentVariable("HOMEPATH", buf0, 1024);
if (len0 > 0 && len0 < 1024)
{
buf0[len0] = '\0';
len1 = GetEnvironmentVariable("HOMEDRIVE", buf1, 1024);
if (len1 > 0 && len1 < 1024)
{
buf1[len1] = '\0';
printf("%s%s", buf0, buf1);
return 0;
}
}
fprintf(stderr, "Unable to determine HOMEDRIVE or HOMEPATH\n");
return 1;
#endif
}