Re: errno --> errno name ?

2013-03-20 Thread Bruce Korb
On 03/20/13 01:54, Thien-Thi Nguyen wrote:
>Polish, test, and finally submit the result here.
> 
> Is there still any interest in this work?
> 

This works.  Needs to be made portable.  Needs some sort of "module" thing.
It amused me to do, but I doubt I'd find time to so all the gnulib polishing.
Should build straight away on any Linux platform.


errno.txz
Description: application/xz-compressed-tar


Re: errno --> errno name ?

2013-03-20 Thread Thien-Thi Nguyen
() Bruno Haible 
() Wed, 8 Jun 2011 16:37:03 +0200

   > Accretion: the coral reef's algorithm.

   ;-)

   >Would you be willing to create a gnulib module from this, for Sam?
   > 
   > For Sam and anyone else interested, sure.  What needs to be done?

   Create a .h file with the specification of the function.  Create a .c
   file with the implementation.  Decide whether to copy the mksyms
   script into gnulib or use a different approach.  Create a module
   description.

   Polish, test, and finally submit the result here.

Is there still any interest in this work?

-- 
Thien-Thi Nguyen
GPG key: 4C807502


pgp5UkjD8xkec.pgp
Description: PGP signature


Re: errno --> errno name ?

2011-08-14 Thread Bruce Korb

Hi Bruno,

On 08/14/11 10:25, Bruno Haible wrote:

By the way, instead of defining a macro ERRNO_DISPLAY_FMT (that ends with
a newline - why?), it is more general to define a macro
   #define MAX_ERROR_NAME_LENGTH 15
Users who want to user columns can then do things like
   printf ("%.*s", MAX_ERROR_NAME_LENGTH + 1, ...)


"%-.*s", no?  Anyway, that is better.  There's enough to printf
that even after all these years, it isn't all at the tips of my fingers:)
Maybe it's *because* of all the years, I learned it in a predecessor
form and haven't gone back to learn all of what featuritis did to it. :-D


Please feel free to tweak it.  I think that might be easier than
seeing if I get exactly what you mean, retrying and cycling again.


But through this process of proposing, retrying, and listening to comments


Sure.  It depends somewhat on your (and others') patience, too.
This is kind-of a play time activity.  My focus this weekend is
actually deferred tax returns (due Monday night because I had
this employer who misrepresented my earnings and .)
The next two weekends are booked, then I go to Europe for a couple
of weeks and when I get back I suspect there will be some chores
around the house.  In other words, it might be a bit like the
libposix stuff.  With another hand, it goes faster.


It will not find the mk-err-names.sh script in the first place. The Makefile
rules are executed in the build directory.


OK, the invocation has to have a "where is it?" search.


Please, that's part of submitting a gnulib module: adding it to your
gnulib working directory, doing "./gnulib-tool --create-testdir ..." of it,
and optionally testing this testdir with "mkdir b; cd b; ../configure; make".


Whenever I have both time and inclination (a roundtuit).  Maybe this fall,
unless someone out there wants to play, too.

Cheers - Bruce



Re: errno --> errno name ?

2011-08-14 Thread Bruno Haible
Bruce Korb wrote:
> > Does the .h file need to be generated? It is much more convenient to
> > rely on a .h file that is platform independent.
> 
> The formatting string depends upon the maximum errno name length.
> If one can presume 16, then there's no need  It seems to be 15
> on Linux:

Then, I would
  1. define the macro with value 15 in the .h file,
  2. document that this value may be increased in future versions,
  3. add a warning to the mk-err-names.sh script when an error name
 is encountered on some platform that is longer than 15 columns.

By the way, instead of defining a macro ERRNO_DISPLAY_FMT (that ends with
a newline - why?), it is more general to define a macro
  #define MAX_ERROR_NAME_LENGTH 15
Users who want to user columns can then do things like
  printf ("%.*s", MAX_ERROR_NAME_LENGTH + 1, ...)

> > then retry "make", nothing will happen, because
> >1. err-names.c does not depend on mk-err-names.sh,
> 
> It depends upon the .h and the .h depends on the script.

Ah, ok, sorry. I was looking at one rule only.

> Please feel free to tweak it.  I think that might be easier than
> seeing if I get exactly what you mean, retrying and cycling again.

But through this process of proposing, retrying, and listening to comments
you (and others who read the mailing list) learn about the technique how
to design a usable, generic, and at the same time practical API; about the
considerations specific to gnulib; about the things to remember regarding
VPATH; and so on.

> > Also, the rule does not work in VPATH builds where $(srcdir) != ".".
> 
> Okay, need to pass through CC and srcdir both.  See above.  Note also
> that by changing the script so that the files get created in the
> source directory, you also make it possible to fail because the source
> directory isn't necessarily writable. I think the source ought
> to be generated in the "build" directory.

Yes, you are right, the $(srcdir) may be read-only. Actually Automake's
"make distcheck" rule verifies that you aren't writing into $(srcdir)
if $(srcdir) != ".". -- I didn't suggest to generate the files in
$(srcdir). All I said was that the Makefile rules would fail in the VPATH
case.

> I don't exactly see how the VPATH build fails.

It will not find the mk-err-names.sh script in the first place. The Makefile
rules are executed in the build directory.

Please, that's part of submitting a gnulib module: adding it to your
gnulib working directory, doing "./gnulib-tool --create-testdir ..." of it,
and optionally testing this testdir with "mkdir b; cd b; ../configure; make".

Bruno
-- 
In memoriam Maximilian Kolbe 



Re: errno --> errno name ?

2011-08-14 Thread Bruce Korb

On 08/14/11 03:35, Bruno Haible wrote:

Does the .h file need to be generated? It is much more convenient to
rely on a .h file that is platform independent.


The formatting string depends upon the maximum errno name length.
If one can presume 16, then there's no need  It seems to be 15
on Linux:

   93 (EPROTONOSUPPORT) == Protocol not supported
   94 (ESOCKTNOSUPPORT) == Socket type not supported
  131 (ENOTRECOVERABLE) == State not recoverable



Also, the rule is not very robust and lacks dependencies: If one some
platform, the generation of the file fails, then you change mk-err-names.sh,
then retry "make", nothing will happen, because
   1. err-names.c does not depend on mk-err-names.sh,


It depends upon the .h and the .h depends on the script.


   2. The "test -f $@ || ..." idiom will not rerun mk-err-names.sh.


Nope.  It gets re-run in the make of err-names.h.
This idiom will cause the script to run only if there is some
way that the .c rule fires after the .h rule.  The .h rule is the real rule.


Makefile.am:
GEN_ERRNO_FILES = err-names.c err-names.h
BUILT_SOURCES  += $(GEN_ERRNO_FILES)
MOSTLYCLEANFILES   += $(GEN_ERRNO_FILES)
nodist_include_HEADERS += err-names.h
ENV_FOR_ERRNO   = CC="$(CC) $(AM_CPPFLAGS) $(CPPFLAGS)" \
srcdir="$(srcdir)"

err-names.c : err-names.h
@test -f $@ || $(ENV_FOR_ERRNO) $(SHELL) mk-err-names.sh

err-names.h : mk-err-names.sh
$(ENV_FOR_ERRNO) $(SHELL) mk-err-names.sh



I would recommend to use the well-tested idiom for generated files, like in
modules/unistd and many other places.


Please feel free to tweak it.  I think that might be easier than
seeing if I get exactly what you mean, retrying and cycling again.


Also, the rule does not work in VPATH builds where $(srcdir) != ".".


Okay, need to pass through CC and srcdir both.  See above.  Note also
that by changing the script so that the files get created in the
source directory, you also make it possible to fail because the source
directory isn't necessarily writable.  I think the source ought
to be generated in the "build" directory.  I don't exactly see how
the VPATH build fails.  Build directory sources should be found,
even in VPATH builds.


err-names.h : mk-err-names.sh $(EXE).c
CC="$(CC)" $(SHELL) mk-err-names.sh


$(EXE) is undefined.


:)  cut-n-paste error.


errno.txz
Description: application/xz-compressed-tar


Re: errno --> errno name ?

2011-08-14 Thread Bruno Haible
Hi Bruce,

> This time the tarball includes a module file of sorts.

Good, this is what gnulib needs.

> Makefile.am:
> GEN_ERRNO_FILES = err-names.c err-names.h
> BUILT_SOURCES  += $(GEN_ERRNO_FILES)
> MOSTLYCLEANFILES   += $(GEN_ERRNO_FILES)
> nodist_include_HEADERS += err-names.h

Does the .h file need to be generated? It is much more convenient to
rely on a .h file that is platform independent.
  1) The user can look at the .h file to see whether it fits his needs,
 and can start to program before doing "gnulib-tool --add-import ...;
 ./configure; make".
  2) The user doesn't need to wonder whether the .h file contains different
 function declarations on different platforms.

> err-names.c : err-names.h
>   @test -f $@ || CC="$(CC)" $(SHELL) mk-err-names.sh

You need the C compiler for preprocessing, right? Then you shouldn't
forget about $(CPPFLAGS) and $(AM_CPPFLAGS). So change
  CC="$(CC)"
to
  CC="$(CC) $(AM_CPPFLAGS) $(CPPFLAGS)"

Also, the rule is not very robust and lacks dependencies: If one some
platform, the generation of the file fails, then you change mk-err-names.sh,
then retry "make", nothing will happen, because
  1. err-names.c does not depend on mk-err-names.sh,
  2. The "test -f $@ || ..." idiom will not rerun mk-err-names.sh.
I would recommend to use the well-tested idiom for generated files, like in
modules/unistd and many other places.

Also, the rule does not work in VPATH builds where $(srcdir) != ".".

> err-names.h : mk-err-names.sh $(EXE).c
>   CC="$(CC)" $(SHELL) mk-err-names.sh

$(EXE) is undefined.

Bruno
-- 
In memoriam Maximilian Kolbe 



Re: errno --> errno name ?

2011-08-13 Thread Bruce Korb


I had a few more minutes to play.

This time the tarball includes a module file of sorts.
Maybe I'm not looking at the right module for a template,
but I find this a bit different from the usual gnulib module.
Basically, it is a build script and a module file, with
some rules for running the script as part of any incorporating
project's build rule.  So you don't have to unpack, here's
the module file.  There's another copy in the tarball that,
again, will make a program on a gcc/gnu make system.


Description:
An error number to error name function

Files:
build-aux/mk-err-names.sh

Makefile.am:
GEN_ERRNO_FILES = err-names.c err-names.h
BUILT_SOURCES  += $(GEN_ERRNO_FILES)
MOSTLYCLEANFILES   += $(GEN_ERRNO_FILES)
nodist_include_HEADERS += err-names.h

err-names.c : err-names.h
@test -f $@ || CC="$(CC)" $(SHELL) mk-err-names.sh

err-names.h : mk-err-names.sh $(EXE).c
CC="$(CC)" $(SHELL) mk-err-names.sh

License:
LGPLv2+

Maintainer:
Bruce Korb


errno.txz
Description: application/xz-compressed-tar


Re: errno --> errno name ?

2011-08-06 Thread Thien-Thi Nguyen
() Eric Blake 
() Fri, 05 Aug 2011 08:00:06 -0600

   Not true.  Use of : is portable to all shells that support
   functions, which is pretty much every shell out there today
   (including Solaris /bin/sh).  Autoconf has already proved this
   point.

OK, i stand corrected.  I can let that memory fade now...



Re: errno --> errno name ?

2011-08-05 Thread Bruce Korb

Hi Stefano,

On 08/05/11 06:48, Stefano Lattarini wrote:

zsh stumbles on this:

  egrep -h "$grep_expr" $errno_list | \
  sed "$sed_cmd" | \
  awk '{ print $1 " " $2 }' | \
  sort -u -n -k2>  ${tmpd}/sorted.txt

so it is not Bourne-enough to count.


It's not by default; you just have to tell it explicitly to behave more
bourne-like.

   # Be more Bourne compatible
   DUALCASE=1; export DUALCASE # for MKS sh
   if test -n "${ZSH_VERSION+set}"&&  (emulate sh)>/dev/null 2>&1; then :
 emulate sh
 NULLCMD=:
 # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
 # is contrary to our usage.  Disable this feature.
 alias -g '${1+"$@"}'='"$@"'
 setopt NO_GLOB_SUBST


Now that I've seen that, I think it is not Bourne-enough to count. :(


It tries to run awk with
the $errno_list argument instead of just passing output through to it.
Hopeless.


Huh?  What it the precise error message?


Basically, the expansion of $errno_list was as if it were quoted, "$errno_list".
It only looked like it was being passed through to awk because the 
multi-threaded
printing was much more intermingled than I normally see.

No way around it, zsh is just being gratuitously weird.  If folks want to run
Bourne shell scripts with it, then they need to jigger it themselves.


ash:
  >  $ ash -x ./mk-err-names.sh
  >  ./mk-err-names.sh: 37: Syntax error: word unexpected (expecting ")")


Which version of ash?  It works ok on my Debian box with dash 0.5.5.1 and
dash 0.5.2.


"dash" works fine.  I have no idea which version of ash I have.
It won't tell me with any of --version --help -v or -V options.
So the version is whatever openSuSE currently ships with 11.4.



Re: errno --> errno name ?

2011-08-05 Thread Eric Blake

On 08/05/2011 07:58 AM, Thien-Thi Nguyen wrote:

() Bruce Korb
() Fri, 05 Aug 2011 06:19:03 -0700

  4 tmpd=`mktemp -d ${TMPDIR:-/tmp}/err-names-XX`

IIRC, constructs like:

   ${TMPDIR:-/tmp}

can be made more portable:

   ${TMPDIR-/tmp}

by removing the colon before the dash.


Not true.  Use of : is portable to all shells that support functions, 
which is pretty much every shell out there today (including Solaris 
/bin/sh).  Autoconf has already proved this point.


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



Re: errno --> errno name ?

2011-08-05 Thread Thien-Thi Nguyen
() Bruce Korb 
() Fri, 05 Aug 2011 06:19:03 -0700

 4 tmpd=`mktemp -d ${TMPDIR:-/tmp}/err-names-XX`

IIRC, constructs like:

  ${TMPDIR:-/tmp}

can be made more portable:

  ${TMPDIR-/tmp}

by removing the colon before the dash.



Re: errno --> errno name ?

2011-08-05 Thread Stefano Lattarini
Hi Bruce.

On Friday 05 August 2011, Bruce Korb wrote:
> On 08/04/11 17:39, Bruno Haible wrote:
> > Hi Bruce,
> >
> >> I fixed up the "mk" script to be more portable
> >
> > Indeed, that looks like most portability problems have been eliminated.
> >
> >> tho I haven't tried it on Solaris' /bin/sh.
> >> Probably won't work.  I don't have access.
> >
> > You can also test it with 'zsh', 'ksh', 'ash', and 'dash' on a glibc system.
> > If it works with these shells, it will likely also pass with /bin/sh on
> > various systems.
> 
> zsh stumbles on this:
> 
>  egrep -h "$grep_expr" $errno_list | \
>  sed "$sed_cmd" | \
>  awk '{ print $1 " " $2 }' | \
>  sort -u -n -k2 > ${tmpd}/sorted.txt
> 
> so it is not Bourne-enough to count.
>
It's not by default; you just have to tell it explicitly to behave more
bourne-like.  This is how it is done by the autoconf-generated configure
scripts (note that this code will also force bash and some Korn shells
to behave more "posixly"):

  # Be more Bourne compatible
  DUALCASE=1; export DUALCASE # for MKS sh
  if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
emulate sh
NULLCMD=:
# Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
# is contrary to our usage.  Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
  else
case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
  fi

> It tries to run awk with
> the $errno_list argument instead of just passing output through to it.
> Hopeless.
>
Huh?  What it the precise error message?

> ash:
>  > $ ash -x ./mk-err-names.sh
>  > ./mk-err-names.sh: 37: Syntax error: word unexpected (expecting ")")
>
Which version of ash?  It works ok on my Debian box with dash 0.5.5.1 and
dash 0.5.2.

>1 #! /bin/sh
>2
>3 init() {
>4 tmpd=`mktemp -d ${TMPDIR:-/tmp}/err-names-XX`
>5 test -d "${tmpd}" || {
>6 tmpd=${TMPDIR:-/tmp}/err-names-$$
>7 rm -rf ${tmpd}
>8 mkdir ${tmpd}
>9 }
>   10 tmpf=${tmpd}/temp.c
>   11 trap "rm -rf ${tmpd}" EXIT
>   12 echo '#include ' > ${tmpf}
>   13
>   14 test -z "$CC" && {
>   15 CC=`command -v gcc 2>/dev/null`
>   16 test -x "$CC" || CC=`command -v cc`
>   17 }
>   18
>   19 errno_list=`
>   20   $CC -E ${tmpf} | \
>   21 sed -n -e 's/\.h[^-_a-zA-Z0-9/].*/.h/' \
>   22 -e 's@.*\(/usr/include.*/errno\)@\1@p' | \
>   23 sort -u `
>   24
>   25 grep_expr='^[   ]*#[]*define[   ]+E[A-Z_0-9]+[  
> ]*[0-9]'
>   26 sed_cmd='s/^[   ]*#[]*define[   ]*//'
>   27
>   28 egrep -h "$grep_expr" $errno_list | \
>   29 sed "$sed_cmd" | \
>   30 awk '{ print $1 " " $2 }' | \
>   31 sort -u -n -k2 > ${tmpd}/sorted.txt
>   32 }
>   33
>   34 compute_limits() {
>   35 max_val=`sed -n '$s/^[A-Z_0-9]*[]*//p' ${tmpd}/sorted.txt`
>   36 max_width=0
>   37 last_val=-1
>   38 offset=0
> 
> Not very Bourne-like either.  The others work.  It seems I have 'em all.
> Even Solaris' /bin/sh.  I still have access to one at U of Utah.  It works.
> 

Regards,
  Stefano



Re: errno --> errno name ?

2011-08-05 Thread Bruce Korb

On 08/04/11 17:39, Bruno Haible wrote:

Hi Bruce,


I fixed up the "mk" script to be more portable


Indeed, that looks like most portability problems have been eliminated.


tho I haven't tried it on Solaris' /bin/sh.
Probably won't work.  I don't have access.


You can also test it with 'zsh', 'ksh', 'ash', and 'dash' on a glibc system.
If it works with these shells, it will likely also pass with /bin/sh on
various systems.


zsh stumbles on this:

egrep -h "$grep_expr" $errno_list | \
sed "$sed_cmd" | \
awk '{ print $1 " " $2 }' | \
sort -u -n -k2 > ${tmpd}/sorted.txt

so it is not Bourne-enough to count.  It tries to run awk with
the $errno_list argument instead of just passing output through to it.
Hopeless.

ash:
> $ ash -x ./mk-err-names.sh
> ./mk-err-names.sh: 37: Syntax error: word unexpected (expecting ")")
  1 #! /bin/sh
  2
  3 init() {
  4 tmpd=`mktemp -d ${TMPDIR:-/tmp}/err-names-XX`
  5 test -d "${tmpd}" || {
  6 tmpd=${TMPDIR:-/tmp}/err-names-$$
  7 rm -rf ${tmpd}
  8 mkdir ${tmpd}
  9 }
 10 tmpf=${tmpd}/temp.c
 11 trap "rm -rf ${tmpd}" EXIT
 12 echo '#include ' > ${tmpf}
 13
 14 test -z "$CC" && {
 15 CC=`command -v gcc 2>/dev/null`
 16 test -x "$CC" || CC=`command -v cc`
 17 }
 18
 19 errno_list=`
 20   $CC -E ${tmpf} | \
 21 sed -n -e 's/\.h[^-_a-zA-Z0-9/].*/.h/' \
 22 -e 's@.*\(/usr/include.*/errno\)@\1@p' | \
 23 sort -u `
 24
 25 grep_expr='^[   ]*#[]*define[   ]+E[A-Z_0-9]+[  ]*[0-9]'
 26 sed_cmd='s/^[   ]*#[]*define[   ]*//'
 27
 28 egrep -h "$grep_expr" $errno_list | \
 29 sed "$sed_cmd" | \
 30 awk '{ print $1 " " $2 }' | \
 31 sort -u -n -k2 > ${tmpd}/sorted.txt
 32 }
 33
 34 compute_limits() {
 35 max_val=`sed -n '$s/^[A-Z_0-9]*[]*//p' ${tmpd}/sorted.txt`
 36 max_width=0
 37 last_val=-1
 38 offset=0

Not very Bourne-like either.  The others work.  It seems I have 'em all.
Even Solaris' /bin/sh.  I still have access to one at U of Utah.  It works.



Re: RE : Re: errno --> errno name ?

2011-08-05 Thread Bruce Korb

On 08/05/11 02:16, Bastien ROUCARIES wrote:

Does it work for cross compiling ?


As long as CPP can spit out the -E output correctly, but the
script may need tweaks anyway.  One good one might be to
pass through the definition of CC and use that.  Would you
try it out?  Thanks! - Bruce



Re: errno --> errno name ?

2011-08-05 Thread Bruce Korb

On 08/04/11 17:39, Bruno Haible wrote:

You can also test it with 'zsh', 'ksh', 'ash', and 'dash' on a glibc system.


IFF they're installed.


If it works with these shells, it will likely also pass with /bin/sh on
various systems.

Now, do you plan to convert this into a gnulib module?


Not real soon.  Tho with some infrastructure help, it would happen sooner.


One interesting thing I discovered:



132 (ERFKILL. . . . ) == Unknown error 132


It just means that your libc does not have the string for ERFKILL. This
string was added in glibc/sysdeps/gnu/errlist.c on 2009-11-14.


It seemed odd that it would be added to glibc's headers and not the .c file.

CHeers - Bruce



RE : Re: errno --> errno name ?

2011-08-05 Thread Bastien ROUCARIES
Does it work for cross compiling ?

Bastien

Le 5 août 2011 02:39, "Bruno Haible"  a écrit :

Hi Bruce,


> I fixed up the "mk" script to be more portable
Indeed, that looks like most portability problems have been eliminated.


> tho I haven't tried it on Solaris' /bin/sh.
> Probably won't work. I don't have access.
You can also test it with 'zsh', 'ksh', 'ash', and 'dash' on a glibc system.
If it works with these shells, it will likely also pass with /bin/sh on
various systems.

Now, do you plan to convert this into a gnulib module?


> One interesting thing I discovered:
>
> $ errno . | head -n4 ; echo '[...]';errno . | tail -n4
>...
It just means that your libc does not have the string for ERFKILL. This
string was added in glibc/sysdeps/gnu/errlist.c on 2009-11-14.

Bruno


Re: errno --> errno name ?

2011-08-04 Thread Bruno Haible
Hi Bruce,

> I fixed up the "mk" script to be more portable

Indeed, that looks like most portability problems have been eliminated.

> tho I haven't tried it on Solaris' /bin/sh.
> Probably won't work.  I don't have access.

You can also test it with 'zsh', 'ksh', 'ash', and 'dash' on a glibc system.
If it works with these shells, it will likely also pass with /bin/sh on
various systems.

Now, do you plan to convert this into a gnulib module?

> One interesting thing I discovered:
> 
> $ errno . | head -n4 ; echo '[...]';errno . | tail -n4
> looking for matches to:  '.'
>  1 (EPERM. . . . . ) == Operation not permitted
>  2 (ENOENT . . . . ) == No such file or directory
>  3 (ESRCH. . . . . ) == No such process
> [...]
>130 (EOWNERDEAD . . ) == Owner died
>131 (ENOTRECOVERABLE) == State not recoverable
>132 (ERFKILL. . . . ) == Unknown error 132

It just means that your libc does not have the string for ERFKILL. This
string was added in glibc/sysdeps/gnu/errlist.c on 2009-11-14.

Bruno



Re: errno --> errno name ?

2011-08-04 Thread Bruce Korb


Well, after some suggestions from Bruno, I fixed up the "mk" script
to be more portable, tho I haven't tried it on Solaris' /bin/sh.
Probably won't work.  I don't have access.  It might work.
It remains a program and not a library function, too.
One interesting thing I discovered:

$ errno . | head -n4 ; echo '[...]';errno . | tail -n4
looking for matches to:  '.'
1 (EPERM. . . . . ) == Operation not permitted
2 (ENOENT . . . . ) == No such file or directory
3 (ESRCH. . . . . ) == No such process
[...]
  130 (EOWNERDEAD . . ) == Owner died
  131 (ENOTRECOVERABLE) == State not recoverable
  132 (ERFKILL. . . . ) == Unknown error 132

Oops.


errno.txz
Description: application/xz-compressed-tar


Re: errno --> errno name ?

2011-08-02 Thread Bruce Korb

Hi Bruno,

On 08/02/11 15:49, Bruno Haible wrote:

Is the list of errno values meant to be extracted before a tarball is built, or
at build time?


Build time -- the script needs to be made portable.
The included Makefile has a dependency.  I included it as an example.


Also, what's the point of using the numeric values of the error numbers?
If you generate code like


For human eyeball reference.  It's all in one place, instead of scattered about 
in
almost a dozen different files.


then the code is not only more robust but also requires fewer relocations when
put into a shared library. In

 [  1] = "EPERM",
 [  2] = "ENOENT",

the shared library needs to relocate, during loading, as many pointers as there
are references to strings.


It wasn't written for a shared library.  It was written and twiddled exclusively
for command line use.  Still, it isn't rocket science to either emit an array
of offsets into a string with embedded NUL bytes, or to emit the switch
statement you noted above.  The real deal with the code was a mechanism
for finding errno information by number, name or a regular expression searching
of the errno descriptions.

Cheers - Bruce



Re: errno --> errno name ?

2011-08-02 Thread Bruno Haible
Hi Bruce,

> This isn't a library function, but a program that I needed to polish up a bit.
> Fiddling and tweaking can turn it into a library function without too much 
> trouble.
> The last file ("err-names.h") is a derived file that depends on the "mk" 
> script

Is the list of errno values meant to be extracted before a tarball is built, or
at build time?

If you want to create a distributable file, IMO Thien-Thi Nguyen's approach [1]
is good. The code would then look similar to lib/strerror-override.c, basically
like this:

  #ifdef ENOENT
  case ENOENT:
return "ENOENT";
  #endif
  #ifdef ENOTDIR
  case ENOTDIR:
return "ENOTDIR";
  #endif
  ...

If you want to create file at build time, then the mk-err-names.sh script needs
to be a /bin/sh script; you cannot assume that 'bash' is available. Also, what's
the point of using the numeric values of the error numbers? If you generate code
like

  case ENOENT:
return "ENOENT";
  case ENOTDIR:
return "ENOTDIR";
  ...

then the code is not only more robust but also requires fewer relocations when
put into a shared library. In

[  1] = "EPERM",
[  2] = "ENOENT",

the shared library needs to relocate, during loading, as many pointers as there
are references to strings. See Ulrich Drepper's writeup about how to code for
shared libraries ([2], section 2.4.3).

Bruno

[1] http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00057.html
[2] http://www.akkadia.org/drepper/dsohowto.pdf
-- 
In memoriam Amatore Sciesa 



Re: errno --> errno name ?

2011-08-02 Thread Bruce Korb

This isn't a library function, but a program that I needed to polish up a bit.
Fiddling and tweaking can turn it into a library function without too much 
trouble.
The last file ("err-names.h") is a derived file that depends on the "mk" script
that is unabashedly bash.  It is also c99.  That is pretty recent, too.

/**
 *  @file errno.c
 *
 *  Time-stamp:"2011-08-02 14:04:06 bkorb"
 *
 *  Print out error numbers and meanings
 *
 *  Copyright (c) 2002-2011 Bruce Korb - all rights reserved
 *
 * errno 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 3 of the License, or
 * (at your option) any later version.
 *
 * errno 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, see .
 */
#include 
#include 
#include 
#include 
#include 
#include 

#include "err-names.h"

static char const usage_text[] =
"USAGE: errno  [...]\n"
"For each argument, the program will find the error(s) that match\n"
"the name, error number or description pattern and print a line:\n"
"  nnn (ENAME. . . . . ) == Description\n"
"where 'nnn' is the numerical number, 'ENAME' is the #defined name,\n"
"and 'Description' may be plain text or a regular expression.\n";

#ifndef NUL
#define NUL '\0'
#endif

/**
 * Print usage and exit.  This is always a success procedure because
 * all command line arguments are presumed to be an error number
 * search expression.  This is only called when no arguments are provided.
 */
static void
usage(void)
{
fwrite(usage_text, sizeof(usage_text) - 1, 1, stdout);
exit(EXIT_SUCCESS);
}

/**
 * parse a number.  If there is any problem with the number, return -1.
 * The entire input string must be consumed.  If it looks like a number,
 * but is not a valid errno number, "print_errno()" will catch it and
 * return "false" to its caller.
 *
 * @param arg input string
 * @returns -1 or the number indicated by the string
 */
static int
parse_errno(char const * arg)
{
errno = 0;
char * end;
unsigned long val = strtoul(arg, &end, 0);
if ((errno != 0) || (*end != NUL)) return -1;
return (int)val;
}

/**
 * print the error number, name and description.
 * The error number must be in the error name table.
 *
 * @param err  the error number
 * @param desc the error description
 * @returns false if the error number is invalid, otherwise true.
 */
static bool
print_errno(int err, char const * desc)
{
if ((unsigned)err >= ERRNO_LIMIT)
return false;

char const * name = errno_names[err];
if (name == NULL)
return false;

char buf[1024];
int len = snprintf(buf, sizeof(buf), show_fmt, err, name, desc);
char * ps = strchr(buf, '(');
char * pe = strchr(ps,  ')');
if ((ps != NULL) && (pe != NULL)) {
for (;;) {
ps += 2;
if (ps >= pe)   break;
if (*ps == ' ') *ps = '.';
}
}
fwrite(buf, len, 1, stdout);
return true;
}

static int
re_find_err(regex_t * re)
{
int find_ct = 0;
for (int err = 1; err < 255; err++) {
char const * errstr = strerror(err);

if (regexec(re, errstr, 0, NULL, 0) == 0) {
find_ct++;
print_errno(err, errstr);
}
}
return find_ct;
}

static int
print_by_name(char const * ename)
{
for (int idx = 1; idx < ERRNO_LIMIT; idx++) {
char const * name = errno_names[idx];

if ((name != NULL) && (strcmp(ename, name) == 0)) {
char const * txt = strerror(idx);
print_errno(idx, txt);
return EXIT_SUCCESS;
}
}
fprintf(stderr, "no error is named '%s'\n", ename);
return EXIT_FAILURE;
}

static int
find_errno(char const * arg)
{
static char const not_name_chars[] =
" \t.,;/abcdefghijklmnopqrstuvwxyz";

if ((*arg == 'E') && (strpbrk(arg, not_name_chars) == NULL))
return print_by_name(arg);

regex_t re;
int err = regcomp(&re, arg, 0);
int match_ct = 0;

printf("looking for matches to:  '%s'\n", arg);

if (err ==  0) {
match_ct = re_find_err(&re);
regfree(&re);

} else {
for (err = 1; err < 255; err++) {
char const * errstr = strerror(err);

if (strstr(errstr, arg) != NULL) {
match_ct++;
print_errno(err, errstr);
}
}
}

if (match_ct == 0) {
fprintf(stderr, "no error descriptions match '%s'\n\n", arg);
return EXIT_FAILURE;
}

putc('\n', stdout);
return EXIT_SUCCESS;
}

int
main(int argc, char ** argv)
{
int r

Re: errno --> errno name ?

2011-06-08 Thread Bruno Haible
Hi Thien-Thi,

> Accretion: the coral reef's algorithm.

;-)

>Would you be willing to create a gnulib module from this, for Sam?
> 
> For Sam and anyone else interested, sure.  What needs to be done?

Create a .h file with the specification of the function.
Create a .c file with the implementation.
Decide whether to copy the mksyms script into gnulib or use a different
approach.
Create a module description.

Polish, test, and finally submit the result here.

Bruno
-- 
In memoriam Larisa Yudina 



Re: errno --> errno name ?

2011-06-08 Thread Thien-Thi Nguyen
() Bruno Haible 
() Wed, 8 Jun 2011 11:26:42 +0200

   Its list of errno values is pretty extensive, good.

Accretion: the coral reef's algorithm.

   Would you be willing to create a gnulib module from this, for Sam?

For Sam and anyone else interested, sure.  What needs to be done?



Re: errno --> errno name ?

2011-06-08 Thread Bruno Haible
Sam Steingold wrote:
> note that the windows version would have to operate on the values of
> GetLastError() instead of errno.

Native Windows programs have to deal with both GetLastError() and errno.
It would be wrong for an API to handle errno values on Unix but to not
handle errno values on mingw. Also, IMO it is wrong to mix two different
enumerations of values into one, as explained in [1].

Conclusion: If you want some code that deals with GetLastError() values,
it must be a different API than the code that deals with errno values.

Bruno

[1] http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00537.html
-- 
In memoriam Larisa Yudina 



Re: errno --> errno name ?

2011-06-08 Thread Paolo Bonzini

On 06/07/2011 12:38 AM, Sam Steingold wrote:

note that the windows version would have to operate on the values of
GetLastError() instead of errno.


At least this part does not belong in gnulib, I think, because gnulib 
tries to map Windows errors to errno values whenever necessary.  You 
would still mantain the Windows part and dispatch between it.


Paolo



Re: errno --> errno name ?

2011-06-08 Thread Bruno Haible
Thien-Thi Nguyen wrote:
> The referenced script mksyms is attached.

Its list of errno values is pretty extensive, good.

Would you be willing to create a gnulib module from this, for Sam?

Bruno
-- 
In memoriam Larisa Yudina 



Re: errno --> errno name ?

2011-06-06 Thread Thien-Thi Nguyen
() Sam Steingold 
() Mon, 06 Jun 2011 18:38:00 -0400

   Absolutely not.  The whole point of my request is that I will be
   maintaining _less_ code, not more.

Speaking of less, Guile 1.4.x is withering away, so this excerpt from
libguile/Makefile.am might merit a new home someday reformulated for gnulib.

errno-syms.c: $(top_builddir)/config.status
$(srcdir)/mksyms errno.h '^E.' > $@

signal-syms.c: $(top_builddir)/config.status
$(srcdir)/mksyms signal.h '^SIG[A-Z]' > $@
$(srcdir)/mksyms signal.h '^SA_' >> $@

The referenced script mksyms is attached.  Its core is the standard
header extraction (no big deal); the bonus is that it has a data area,
as well, to retain past learnings.

I post this in FWIW spirit.



mksyms
Description: Binary data


Re: errno --> errno name ?

2011-06-06 Thread Bruno Haible
Hi Sam, all,

> I think it would be a useful addition to the errno/strerror/whatever
> modules to be able to convert from the numeric errno to the symbolic
> one.
> e.g.,
> 
> char * errno_name () {
>   switch (errno) {
>   #ifdef ENOENT
>case ENOENT : return "ENOENT";
>   #endif
>default: return NULL;
>   }
> }
> 
> the idea is that the error "explanation" (returned by strerror) is
> different on different platforms (and especially if i18n is involved)
> and is hard to search for on the web and in docs, while strings like
> ENOENT et al are quite canonical and tell the expert everything they
> need to know.

Good point. The code for doing this is already present in clisp/src/errunix.d
and strace/**/errnoent.h.

Question to all: Are you interested in seeing such a function in gnulib?

Question to Sam: Are you willing to contribute such a module to gnulib
(and maintain it)?

Bruno
-- 
In memoriam Robert F. Kennedy 



Re: errno --> errno name ?

2011-06-06 Thread Sam Steingold
Hi Bruno,

> * Bruno Haible  [2011-06-06 22:52:14 +0200]:
>> I think it would be a useful addition to the errno/strerror/whatever
>> modules to be able to convert from the numeric errno to the symbolic
>> one.
>> e.g.,
>> 
>> char * errno_name () {
>>   switch (errno) {
>>   #ifdef ENOENT
>>case ENOENT : return "ENOENT";
>>   #endif
>>default: return NULL;
>>   }
>> }
>> 
>> the idea is that the error "explanation" (returned by strerror) is
>> different on different platforms (and especially if i18n is involved)
>> and is hard to search for on the web and in docs, while strings like
>> ENOENT et al are quite canonical and tell the expert everything they
>> need to know.
>
> Good point. The code for doing this is already present in
> clisp/src/errunix.d and strace/**/errnoent.h.

moreover, most of it can be easily generated from the list of all
possible errno values:
-
char * errno_name () {
  switch (errno) {
#include "errno_cases.h"
default: return NULL;
  }
}

and a simple awk command which would convert a file:
-
ENOENT
ENOTDIR
...
-
into "errno_cases.h"

note that the windows version would have to operate on the values of
GetLastError() instead of errno.

> Question to Sam: Are you willing to contribute such a module to gnulib
> (and maintain it)?

Absolutely not.  The whole point of my request is that I will be
maintaining _less_ code, not more.

-- 
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 
11.0.60900031
http://pmw.org.il http://palestinefacts.org http://openvotingconsortium.org
http://www.memritv.org http://iris.org.il http://thereligionofpeace.com
Just because you're paranoid doesn't mean they AREN'T after you.



errno --> errno name ?

2011-06-06 Thread Sam Steingold
I think it would be a useful addition to the errno/strerror/whatever
modules to be able to convert from the numeric errno to the symbolic
one.
e.g.,

char * errno_name () {
  switch (errno) {
  #ifdef ENOENT
   case ENOENT : return "ENOENT";
  #endif
   default: return NULL;
  }
}

the idea is that the error "explanation" (returned by strerror) is
different on different platforms (and especially if i18n is involved)
and is hard to search for on the web and in docs, while strings like
ENOENT et al are quite canonical and tell the expert everything they
need to know.

I am not proposing replacing strerror, of course; this is merely an
_addition_.

Thanks.

-- 
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 
11.0.60900031
http://jihadwatch.org http://dhimmi.com http://palestinefacts.org
http://www.PetitionOnline.com/tap12009/ http://thereligionofpeace.com
What was there first: the Compiler or its Source code?