[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to work around a missing library function?
From: |
Andrew W. Nosenko |
Subject: |
Re: How to work around a missing library function? |
Date: |
Thu, 26 Nov 2009 12:44:17 +0200 |
On Wed, Nov 25, 2009 at 19:13, Dr. David Kirkby <address@hidden> wrote:
> I have some source code
>
> http://magma.maths.usyd.edu.au/~watkins/sympow.tar.bz2
>
> which will not build on an old release of HP-UX as this lacks the atoll()
> (convert string to a long long) library function.
>
> It is relatively easy to test for this in a configure script. I also found
> on the web a 10-line bit of code, which implements my_atoll()
>
> http://p2p.wrox.com/c-programming/16319-string-long-long-without-using-atoll.html
>
> in a way which works on older HP-UX releases.
>
> I'm reluctant to use this code on every OS, as its not my code, and the
> author might not like that, as this does no error checking. But it would be
> good to implement it when atoll() is not in the library.
>
> I was thinking of:
>
> 1) Changing the code from isomg atoll() to using my_atoll()
>
> 2) Having in configure.ac
>
> AC_CHECK_FUNC (atoll, [], [])
>
> 3)Having something like the following in the source code. I think the
> 'AC_CHECK_FUNC' will have defined HAVE_ATOLL, though I might be wrong on
> that.
>
>
> #ifdef HAVE_ATOLL
> long long my_atoll(char *instr){
> return atoll(instr);
> }
>
> #else
> long long my_atoll(char *instr)
> {
> long long retval;
> int i;
>
> retval = 0;
> for (; *instr; instr++) {
> retval = 10*retval + (*instr - '0');
> }
> return retval;
> }
> #fi
>
> Is it as simple as that, or am I missing something? How would that be
> improved - I somewhat doubt my method is optimal.
>
What about
AC_CHECK_FUNC (atoll, [], [AC_LIBOBJ(atoll)])
and place your atoll() implementation into atoll.c ?
Also you will need to declare prototype somewere:
#ifndef HAVE_ATOLL
long long atoll(const char *nptr);
#endif
--
Andrew W. Nosenko <address@hidden>
- How to work around a missing library function?, Dr. David Kirkby, 2009/11/25
- Re: How to work around a missing library function?, Mike Frysinger, 2009/11/25
- Re: How to work around a missing library function?, Dr. David Kirkby, 2009/11/25
- Re: How to work around a missing library function?, Harlan Stenn, 2009/11/25
- Re: How to work around a missing library function?, Mike Frysinger, 2009/11/25
- Re: How to work around a missing library function?, Dr. David Kirkby, 2009/11/25
- Re: How to work around a missing library function?, Mike Frysinger, 2009/11/25
- Re: How to work around a missing library function?, Dr. David Kirkby, 2009/11/25
- Re: How to work around a missing library function?, Christian Egli, 2009/11/26
Re: How to work around a missing library function?,
Andrew W. Nosenko <=