Re: [bug-gnulib] New GNULIB glob module?

2005-05-25 Thread Derek Price
Larry Jones wrote:

>Derek Price writes:
>  
>
>>Larry, can you tell us if defining
>>_POSIX_PTHREAD_SEMANTICS would work to get the POSIX version of
>>getpwnam_r on Solaris?
>>
>>
>
>It looks like it.
>  
>

I've committed Paul's patch to the CVS CVS tree, as well as removing the
associated glob.c changes, and I will install it in GNULIB if it passes
CVS nightly testing on Solaris.

Regards,

Derek



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


[bug-gnulib] Re: New getlogin_r module

2005-05-25 Thread Derek Price
Bruno Haible wrote:

>Derek Price wrote:
>  
>
>>This is what I installed.
>>
>>
>
>Note that lib/ and m4/ have ChangeLogs of their own. Only the top-level
>and modules/* modifications go into the top-level ChangeLog. Including
>the update of MODULES.html.sh (adding one line for each new module).
>  
>

Thank you.  I will use these ChangeLogs in the future.

>Three further remarks:
>
>- In the include file, you use size_t without including . Won't
>  work on platforms where unistd.h doesn't exist.
>  
>

Looks like Paul got ahead of me and installed this first.

>- The documentation: When a programmer wants to know what the function does,
>  he doesn't need/want to know how the function is implemented. Patch
>  appended.
>  
>

Installed.

>- The code in getlogin_r.c: Why do you save and restore errno? It's useless,
>  since 1. POSIX doesn't say that errno is preserved (generally it's the
>  caller's duty to save errno if he wants to), 
>

Section 7.1.4 of the C89 spec states, "The value of errno ... is never
set to zero by any library function."  I am assuming that getlogin_r and
probably most other GNULIB functions should act like library functions
when possible?

>2. you don't restore it
>  before "return errno;".
>  
>

I restore errno only when it was not set.  Otherwise, I am intentionally
allowing errno to be set.  This isn't POSIX compliant to the point of
not having side-effects not specified explicitly by POSIX, but this is
what the glibc getlogin_r function is doing and what it is documented to
do and I chose to emulate that behavior.

I was about to install the attached patch, which is more careful about
always restoring errno when it would have been set to zero, when Paul
beat me to the punch.  I am not adverse to always restoring errno and
will leave things as Paul set them if you wish, but I still object to
never restoring it.  (I would rather have no side-effects involving
errno rather than always setting it, sometimes to zero.)  Is there some
reason we shouldn't comply with the C89 errno specification for library
functions?

I've also added getlogin_r to the POSIX.2001 support section of
MODULES.html.sh.

2005-05-25  Derek Price  <[EMAIL PROTECTED]>

   * MODULES.html.sh: Add getlogin_r to POSIX.2001 support section.

2005-05-25  Bruno Haible  <[EMAIL PROTECTED]>
Derek Price  <[EMAIL PROTECTED]>

* lib/getlogin_r.h: Simplify API documentation.
* lib/getlogin_r.c: Be more careful about restoring errno when
reset.

Regards,

Derek
Index: lib/getlogin_r.c
===
RCS file: /cvsroot/gnulib/gnulib/lib/getlogin_r.c,v
retrieving revision 1.1
diff -u -p -r1.1 getlogin_r.c
--- lib/getlogin_r.c25 May 2005 14:21:20 -  1.1
+++ lib/getlogin_r.c25 May 2005 18:43:32 -
@@ -39,6 +39,7 @@ getlogin_r (char *name, size_t size)
 {
   char *n;
   int save_errno = errno;
+  int retval = -1;
 
   errno = 0;
   n = getlogin ();
@@ -48,12 +49,14 @@ getlogin_r (char *name, size_t size)
   if (nlen < size)
 {
   memcpy (name, n, nlen + 1);
-  return 0;
+  retval =  0;
 }
-  errno = ERANGE;
+  else
+retval = ERANGE;
 }
 
-  if (errno) return errno;
-  errno = save_errno;
-  return -1;
+  if (errno) retval = errno;
+  else errno = save_errno;
+
+  return retval;
 }
___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] New getlogin_r module

2005-05-25 Thread Paul Eggert
Derek Price <[EMAIL PROTECTED]> writes:

> It sets *and* returns errno since my local man pages make it sound
> like errno will be set by getlogin_r and others may already have
> code which checks errno and not getlogin_r's return value.

But glibc getlogin_r doesn't always set errno to the returned value,
and POSIX doesn't promise it, so such code is already broken.

> I would note that the opengroup POSIX spec you reference does not
> define an error return code for getlogin_r for the case where "the
> user's login name cannot be found".  I chose -1 arbitrarily.

We should return a valid errno value, since POSIX requires that
we return an error number, and -1 is not an error number.  Returning
ENOENT is fine.

A couple of other glitches I just noticed.  getlogin_r.h uses size_t
without necessarily defining it.  We shouldn't include 
without checking for HAVE_CONFIG_H.

I installed this change:

Index: lib/getlogin_r.h
===
RCS file: /cvsroot/gnulib/gnulib/lib/getlogin_r.h,v
retrieving revision 1.1
diff -p -u -r1.1 getlogin_r.h
--- lib/getlogin_r.h25 May 2005 14:21:20 -  1.1
+++ lib/getlogin_r.h25 May 2005 19:12:57 -
@@ -33,5 +33,6 @@
 
See .
  */
+# include 
 int getlogin_r (char *name, size_t size);
 #endif
Index: lib/getlogin_r.c
===
RCS file: /cvsroot/gnulib/gnulib/lib/getlogin_r.c,v
retrieving revision 1.1
diff -p -u -r1.1 getlogin_r.c
--- lib/getlogin_r.c25 May 2005 14:21:20 -  1.1
+++ lib/getlogin_r.c25 May 2005 19:12:57 -
@@ -18,7 +18,9 @@
 
 /* written by Paul Eggert and Derek Price */
 
-#include 
+#if HAVE_CONFIG_H
+# include 
+#endif
 
 #include "getlogin_r.h"
 
@@ -38,22 +40,15 @@ int
 getlogin_r (char *name, size_t size)
 {
   char *n;
-  int save_errno = errno;
+  size_t nlen;
 
   errno = 0;
   n = getlogin ();
-  if (n)
-{
-  size_t nlen = strlen (n);
-  if (nlen < size)
-{
-  memcpy (name, n, nlen + 1);
-  return 0;
-}
-  errno = ERANGE;
-}
-
-  if (errno) return errno;
-  errno = save_errno;
-  return -1;
+  if (!n)
+return errno ? errno : ENOENT;
+  nlen = strlen (n);
+  if (size <= nlen)
+return ERANGE;
+  memcpy (name, n, nlen + 1);
+  return 0;
 }


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


[bug-gnulib] new modules for C# interoperability

2005-05-25 Thread Bruno Haible
After the modules for Java, here come the modules for C# interoperability.
C# is a language which lies between C++ and Java, nearer to Java than to C++.
It is ECMA standardized and has at least 2 free implementations (pnet and
mono). Like Java, it allows to write conceptually simple tasks - that
would require complex C programs - as simple programs.

The support comes in two modules:

  - csharpexec   - Execute a C# program.
  - csharpcomp   - Compile a C# program.

Here comes the first one. In use by GNU gettext for more than a year.

= modules/csharpexec =
Description:
Execute a C# program.

Files:
lib/csharpexec.h
lib/csharpexec.c
lib/csharpexec.sh.in
m4/csharpexec.m4
m4/csharp.m4

Depends-on:
stdbool
execute
classpath
xsetenv
sh-quote
xalloc
xallocsa
error
gettext

configure.ac:
gt_CSHARPEXEC

Makefile.am:
DEFS += -DEXEEXT=\"$(EXEEXT)\"
lib_SOURCES += csharpexec.h csharpexec.c
EXTRA_DIST += csharpexec.sh.in

Include:
"csharpexec.h"

License:
GPL

Maintainer:
Bruno Haible

 lib/csharpexec.sh.in 
#!/bin/sh
# Execute a C# program.

# Copyright (C) 2003 Free Software Foundation, Inc.
# Written by Bruno Haible <[EMAIL PROTECTED]>, 2003.
#
# This program 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, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# This uses the same choices as csharpexec.c, but instead of relying on the
# environment settings at run time, it uses the environment variables
# present at configuration time.
#
# This is a separate shell script, because the various C# interpreters have
# different command line options.
#
# Usage: /bin/sh csharpexec.sh [OPTION] program.exe [ARGUMENTS]
# Options:
#   -L DIRECTORY  search for C# libraries also in DIRECTORY

sed_quote_subst='s/\([|&;<>()$`"'"'"'*?[#~=%\\]\)/\\\1/g'
options_ilrun=
libdirs_mono=
prog=
while test $# != 0; do
  case "$1" in
-L)
  options_ilrun="$options_ilrun -L "`echo "$2" | sed -e "$sed_quote_subst"`
  libdirs_mono="${libdirs_mono:[EMAIL PROTECTED]@}$2"
  shift
  ;;
-*)
  echo "csharpexec: unknown option '$1'" 1>&2
  exit 1
  ;;
*)
  prog="$1"
  break
  ;;
  esac
  shift
done
if test -z "$prog"; then
  echo "csharpexec: no program specified" 1>&2
  exit 1
fi
case "$prog" in
  *.exe) ;;
  *)
echo "csharpexec: program is not a .exe" 1>&2
exit 1
;;
esac

if test -n "@HAVE_ILRUN@"; then
  test -z "$CSHARP_VERBOSE" || echo ilrun $options_ilrun "$@"
  exec ilrun $options_ilrun "$@"
else
  if test -n "@HAVE_MONO@"; then
CONF_MONO_PATH='@MONO_PATH@'
if test -n "$libdirs_mono"; then
  MONO_PATH="$libdirs_mono${CONF_MONO_PATH:[EMAIL 
PROTECTED]@$CONF_MONO_PATH}"
else
  MONO_PATH="$CONF_MONO_PATH"
fi
export MONO_PATH
test -z "$CSHARP_VERBOSE" || echo mono "$@"
exec mono "$@"
  else
echo 'C# virtual machine not found, try installing pnet, then reconfigure' 
1>&2
exit 1
  fi
fi
== lib/csharpexec.h ==
/* Execute a C# program.
   Copyright (C) 2003 Free Software Foundation, Inc.
   Written by Bruno Haible <[EMAIL PROTECTED]>, 2003.

   This program 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, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#ifndef _CSHARPEXEC_H
#define _CSHARPEXEC_H

#include 

typedef bool execute_fn (const char *progname,
 const char *prog_path, char **prog_argv,
 void *private_data);

/* Execute a C# program.
   assembly_path is the assembly's pathname (= program name with .exe).
   libdirs is a list of directories to be searched for libraries.
   args is a NULL terminated list of arguments to be passed to the program.
   If verbose, the command to b

Re: [bug-gnulib] New GNULIB glob module?

2005-05-25 Thread Larry Jones
Derek Price writes:
> 
> Larry, can you tell us if defining
> _POSIX_PTHREAD_SEMANTICS would work to get the POSIX version of
> getpwnam_r on Solaris?

It looks like it.

-Larry Jones

I never get to do anything fun. -- Calvin


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


[bug-gnulib] Re: New getlogin_r module

2005-05-25 Thread Bruno Haible
Derek Price wrote:
> This is what I installed.

Note that lib/ and m4/ have ChangeLogs of their own. Only the top-level
and modules/* modifications go into the top-level ChangeLog. Including
the update of MODULES.html.sh (adding one line for each new module).

Three further remarks:

- In the include file, you use size_t without including . Won't
  work on platforms where unistd.h doesn't exist.

- The documentation: When a programmer wants to know what the function does,
  he doesn't need/want to know how the function is implemented. Patch
  appended.

- The code in getlogin_r.c: Why do you save and restore errno? It's useless,
  since 1. POSIX doesn't say that errno is preserved (generally it's the
  caller's duty to save errno if he wants to), 2. you don't restore it
  before "return errno;".

Bruno


diff -c -3 -r1.1 getlogin_r.h
*** lib/getlogin_r.h25 May 2005 14:21:20 -  1.1
--- lib/getlogin_r.h25 May 2005 17:56:24 -
***
*** 18,23 
--- 18,25 
  
  /* Written by Paul Eggert and Derek Price.  */
  
+ #include 
+ 
  #if HAVE_UNISTD_H
  # include 
  #endif
***
*** 28,35 
  
 Returns 0 if successful.  Upon error, an error number is returned, or -1 in
 the case that the login name cannot be found but no specific error is
!provided by getlogin (getlogin returned NULL and did not set errno - this
!case is hopefully rare but is left open by the POSIX spec).
  
 See 
.
   */
--- 30,36 
  
 Returns 0 if successful.  Upon error, an error number is returned, or -1 in
 the case that the login name cannot be found but no specific error is
!provided (this case is hopefully rare but is left open by the POSIX spec).
  
 See 
.
   */
diff -c -3 -r1.1 getlogin_r.c
*** lib/getlogin_r.c25 May 2005 14:21:20 -  1.1
--- lib/getlogin_r.c25 May 2005 17:56:24 -
***
*** 38,44 
  getlogin_r (char *name, size_t size)
  {
char *n;
-   int save_errno = errno;
  
errno = 0;
n = getlogin ();
--- 38,43 
***
*** 53,59 
errno = ERANGE;
  }
  
!   if (errno) return errno;
!   errno = save_errno;
!   return -1;
  }
--- 52,56 
errno = ERANGE;
  }
  
!   return (errno ? errno : -1);
  }



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


[bug-gnulib] Re: New getlogin_r module

2005-05-25 Thread Bruno Haible
Derek Price wrote:
> How about something like the attached patch to the modules/memcpy file?

That's a bit redundant. It's already mentioned in MODULES.html.

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] New GNULIB glob module?

2005-05-25 Thread Derek Price
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Paul Eggert wrote:

>Derek Price <[EMAIL PROTECTED]> writes:
>
>>+# ifdef HAVE___POSIX_GETPWNAM_R
>>+ /* Solaris. */
>>+# define getpwnam_r(name, bufp, buf, len, res) \
>>+ __posix_getpwnam_r (name, bufp, buf, len, res)
>>+# endif
>
>
>I don't see why this is needed. The Solaris include files already
>contain the magic necessary to convert getpwnam_r to
>__posix_getpwnam_r, right? Or is it because that depends on
>_POSIX_PTHREAD_SEMANTICS? If so, why not define that, as follows? I
>don't see why any gnulib-using application would want the nonstandard
>Solaris versions of the *_r functions.
>
>--- extensions.m4.~1.6.~ 2005-02-23 05:49:36 -0800
>+++ extensions.m4 2005-05-24 12:35:48 -0700
>@@ -21,6 +21,10 @@ AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [
> [/* Enable extensions on Solaris. */
> #ifndef __EXTENSIONS__
> # undef __EXTENSIONS__
>+#endif
>+#ifndef _POSIX_PTHREAD_SEMANTICS
>+# undef _POSIX_PTHREAD_SEMANTICS
> #endif])
> AC_DEFINE([__EXTENSIONS__])
>+ AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
> ])


I really have no idea.  Larry, can you tell us if defining
_POSIX_PTHREAD_SEMANTICS would work to get the POSIX version of
getpwnam_r on Solaris?

Regards,

Derek
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.0 (Cygwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFClKxWLD1OTBfyMaQRAot/AKDvKB48aoCE0kys6bB3zxx0KT06sACgijeV
z/hTtSVzW3MRjWbCzAZy7pg=
=4CER
-END PGP SIGNATURE-




___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] [bug-gnulib] New getlogin_r module

2005-05-25 Thread Derek Price
Bruno Haible wrote:

>Would you mind adding a bit of documentation? Something like
>

I've added the following to getlogin_r.h:

/* Copies the user's login name to NAME.
   The array pointed to by NAME has room for SIZE bytes.
 
   Returns 0 if successful.  Upon error, an error number is returned, or
-1 in
   the case that the login name cannot be found but no specific error is
   provided by getlogin (getlogin returned NULL and did not set errno - this
   case is hopefully rare but is left open by the POSIX spec).

   See
.
 */


>The return value is incorrect, and the getlogin () return conventions are
>ignored.
>
>http://www.opengroup.org/onlinepubs/009695399/functions/getlogin.html
>says:
>
>  "Upon successful completion, getlogin() shall return a pointer to the login
>   name or a null pointer if the user's login name cannot be found.
>   Otherwise, it shall return a null pointer and set errno to indicate the
>   error."
>
>Which means, you need to set errno = 0 before calling getlogin(), to
>distinguish two of the three cases.
>
>And
>
>  "If successful, the getlogin_r() function shall return zero; otherwise,
>   an error number shall be returned to indicate the error."
>
>So, instead of "errno = ERANGE; return -1; " you need to do "return ERANGE;".
>  
>

This is what I installed.  It sets *and* returns errno since my local
man pages make it sound like errno will be set by getlogin_r and others
may already have code which checks errno and not getlogin_r's return
value.  I would note that the opengroup POSIX spec you reference does
not define an error return code for getlogin_r for the case where "the
user's login name cannot be found".  I chose -1 arbitrarily.  Glancing
at the code in glibc-2.3.5, it looks like it also sets and returns
errno, though they return ENOENT as an extension to the POSIX spec when
the login name cannot be found.

/* See getlogin_r.h for documentation.  */
int
getlogin_r (char *name, size_t size)
{
  char *n;
  int save_errno = errno;

  errno = 0;
  n = getlogin ();
  if (n)
{
  size_t nlen = strlen (n);
  if (nlen < size)
{
  memcpy (name, n, nlen + 1);
  return 0;
}
  errno = ERANGE;
}

  if (errno) return errno;
  errno = save_errno;
  return -1;
}


2005-05-25  Derek Price  <[EMAIL PROTECTED]>
Paul Eggert  <[EMAIL PROTECTED]>

* lib/getlogin_r.c, lib/getlogin_r.h, m4/getlogin_r.m4,
modules/getlogin_r: New files.

Regards,

Derek



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] [bug-gnulib] New getlogin_r module

2005-05-25 Thread Derek Price
Bruno Haible wrote:

>Derek Price wrote:
>  
>
>>+Depends-on:
>>+memcpy
>>
>>
>
>Modules of the category "Support for systems lacking ANSI C 89" are not
>listed among dependencies. We assume that projects needing support for K&R C
>and SunOS 4 will collect these modules themselves.
>  
>

My bad, I didn't realize memcpy was C89.  How about something like the
attached patch to the modules/memcpy file?

Regards,

Derek
Index: modules/memcpy
===
RCS file: /cvsroot/gnulib/gnulib/modules/memcpy,v
retrieving revision 1.4
diff -u -p -r1.4 memcpy
--- modules/memcpy  22 Sep 2004 15:11:04 -  1.4
+++ modules/memcpy  25 May 2005 13:15:47 -
@@ -1,5 +1,5 @@
 Description:
-memcpy() function: copy memory area.
+memcpy() function: copy memory area.  Not known to be necessary on any system 
claiming conformance to C89.
 
 Files:
 lib/memcpy.c
___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] Re: [bug-gnulib] stat and lstat should define their replacements

2005-05-25 Thread Derek Price
Bruno Haible wrote:

>Derek Price <[EMAIL PROTECTED]> writes:
>  
>
>>As near as I can tell, stat and lstat do not define names for their
>>replacements as many of the other GNULIB modules do.
>>
>>
>
>Yes. The 'stat' and 'lstat' modules look incomplete. I think this should
>be added to make them usable out-of-the-box.
>
>diff -c -3 -r1.20 lstat.m4
>*** m4/lstat.m42 May 2005 07:00:50 -   1.20
>--- m4/lstat.m425 May 2005 11:17:55 -
>***
>*** 19,24 
>--- 19,25 
>  AC_DEFUN([gl_FUNC_LSTAT],
>  [
>AC_REQUIRE([AC_FUNC_LSTAT])
>+   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
>  
>

This last isn't necessary, at least with AC 2.59, AC_FUNC_LSTAT requires
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK.  As near as I can tell from the
autoconf CVS repository, this has been true since revision 1.1, in Aug
of 2000.  Don't know where 1.1 came from.  Glancing at the tags, it was
pre Autoconf 2.50, though.  Doesn't GNULIB require a more recent
Autoconf than that?

Other than that, the patch looks good by me.

Thanks,

Derek



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] Re: [bug-gnulib] stat and lstat should define their replacements

2005-05-25 Thread Bruno Haible
Derek Price <[EMAIL PROTECTED]> writes:
> As near as I can tell, stat and lstat do not define names for their
> replacements as many of the other GNULIB modules do.

Yes. The 'stat' and 'lstat' modules look incomplete. I think this should
be added to make them usable out-of-the-box.

diff -c -3 -r1.20 lstat.m4
*** m4/lstat.m4 2 May 2005 07:00:50 -   1.20
--- m4/lstat.m4 25 May 2005 11:17:55 -
***
*** 19,24 
--- 19,25 
  AC_DEFUN([gl_FUNC_LSTAT],
  [
AC_REQUIRE([AC_FUNC_LSTAT])
+   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
dnl Note: AC_FUNC_LSTAT does AC_LIBOBJ(lstat).
:
  ])
*** /dev/null   1970-01-01 01:00:00.0 +0100
--- lib/sys_stat.h  2005-05-25 13:16:45.0 +0200
***
*** 0 
--- 1,37 
+ /* Retrieving information about files.
+Copyright (C) 2005 Free Software Foundation, Inc.
+ 
+This program 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, or (at your option)
+any later version.
+ 
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+ 
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+ 
+ #include 
+ 
+ /* gl_stat() is a fixed version of stat().
+gl_lstat() is a fixed version of lstat().
+We cannot offer a stat() and lstat() function because on some hosts,
+a "#define stat stat64" and "#define lstat lstat64" is being used.  */
+ 
+ #if HAVE_STAT_EMPTY_STRING_BUG
+ extern int rpl_stat (const char *name, struct stat *buf);
+ # define gl_stat(name,buf) rpl_stat (name, buf)
+ #else
+ # define gl_stat(name,buf) stat (name, buf)
+ #endif
+ 
+ #if HAVE_LSTAT_EMPTY_STRING_BUG || !LSTAT_FOLLOWS_SLASHED_SYMLINK
+ extern int rpl_lstat (const char *name, struct stat *buf);
+ # define gl_lstat(name,buf) rpl_lstat (name, buf)
+ #else
+ # define gl_lstat(name,buf) lstat (name, buf)
+ #endif


Paul Eggert wrote:

> A big worry here is hosts that use something like "#define stat
> stat64" when compiled in large-file mode.

Yes. I've also seen this problem on Linux/x86 when a non-gcc compiler
(such as the Intel icc compiler) is used.

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] [bug-gnulib] New getlogin_r module

2005-05-25 Thread Bruno Haible
Derek Price wrote:
> +int
> +getlogin_r (char *name, size_t size)
> +{
> +  char *n = getlogin ();
> +  if (n)
> +{
> +  size_t nlen = strlen (n);
> +  if (nlen < size)
> +{
> +  memcpy (name, n, nlen + 1);
> +  return 0;
> +}
> +  errno = ERANGE;
> +}
> +  return -1;
> +}

The return value is incorrect, and the getlogin () return conventions are
ignored.

http://www.opengroup.org/onlinepubs/009695399/functions/getlogin.html
says:

  "Upon successful completion, getlogin() shall return a pointer to the login
   name or a null pointer if the user's login name cannot be found.
   Otherwise, it shall return a null pointer and set errno to indicate the
   error."

Which means, you need to set errno = 0 before calling getlogin(), to
distinguish two of the three cases.

And

  "If successful, the getlogin_r() function shall return zero; otherwise,
   an error number shall be returned to indicate the error."

So, instead of "errno = ERANGE; return -1; " you need to do "return ERANGE;".

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] [bug-gnulib] New getlogin_r module

2005-05-25 Thread Bruno Haible
Derek Price wrote:
> +Depends-on:
> +memcpy

Modules of the category "Support for systems lacking ANSI C 89" are not
listed among dependencies. We assume that projects needing support for K&R C
and SunOS 4 will collect these modules themselves.

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] [bug-gnulib] New getlogin_r module

2005-05-25 Thread Bruno Haible
Derek Price wrote:
> +#if !HAVE_DECL_GETLOGIN_R
> +int getlogin_r (char *name, size_t size);
> +#endif

Would you mind adding a bit of documentation? Something like

/* Copies the user's login name to NAME.
   The array pointed to by NAME has room for SIZE bytes.
   Returns 0 if successful. Upon error, an error number is returned.
   See .
 */

Bruno



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: [bug-gnulib] stat and lstat should define their replacements

2005-05-25 Thread Paul Eggert
Derek Price <[EMAIL PROTECTED]> writes:

> +/* Get the system versions when something else was defined by config.h.  */
> +#undef lstat
> +#undef stat

A big worry here is hosts that use something like "#define stat
stat64" when compiled in large-file mode.  On such hosts, you can't
#undef 'stat' and 'lstat' as you'll then get the small-file functions.
This may help to explain the infelicity in this area of gnulib.

An example of such a system would be Solaris 10 compiled with GCC 3.

GCC 4 fixes the problem on Solaris 10 -- at least, that's how I read
the GCC source code and Solaris headers; I haven't tested it.  Support
for this was added on 2004-06-20 by Zack Weinberg, if you want to
peruse GCC's ChangeLog entries.

However, obviously we'd still need to support older Solaris
installations, , and I suspect that the problem persists on some
non-Solaris hosts.


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


[bug-gnulib] Re: New getlogin_r module

2005-05-25 Thread Paul Eggert
Derek Price <[EMAIL PROTECTED]> writes:

> Per your suggestion, Paul, I've attached a getlogin_r module for
> review.  It compiles and works here as gl_GETLOGIN_R or
> gl_GETLOGIN_R_SUBSTITUTE.

That looks good to me.  Can you please install it, along with
appropriate ChangeLog entries?  I added you to the gnulib project
member list.  Thanks.


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib