[Top][All Lists]

[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 (X11/20090323)

I have some source code

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()

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

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.

long long my_atoll(char *instr){
  return atoll(instr);

long long my_atoll(char *instr)
  long long retval;
  int i;

  retval = 0;
  for (; *instr; instr++) {
    retval = 10*retval + (*instr - '0');
  return retval;

Is it as simple as that, or am I missing something? How would that be improved - I somewhat doubt my method is optimal.


reply via email to

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