autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to work around a missing library function?


From: Dr. David Kirkby
Subject: How to work around a missing library function?
Date: Wed, 25 Nov 2009 17:13:56 +0000
User-agent: Thunderbird 2.0.0.21 (X11/20090323)

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.


Dave




reply via email to

[Prev in Thread] Current Thread [Next in Thread]