1/* proj.c file for GNU Fortran 2 Copyright (C) 1995 Free Software Foundation, Inc. 3 Contributed by James Craig Burley. 4 5This file is part of GNU Fortran. 6 7GNU Fortran is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GNU Fortran is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GNU Fortran; see the file COPYING. If not, write to 19the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 2002111-1307, USA. */ 21 22#include "proj.h" 23#include "glimits.j" 24 25#ifndef HAVE_STRTOUL 26unsigned long int 27strtoul (const char *nptr, char **endptr, int base) 28{ 29 unsigned long int number = 0; 30 unsigned long int old_number = 0; 31 32 assert (base == 10); 33 assert (endptr == NULL); 34 35 while (ISDIGIT (*nptr)) 36 { 37 number = old_number * 10 + (*(nptr++) - '0'); 38 if ((number <= old_number) && (old_number != 0)) 39 return ULONG_MAX; 40 old_number = number; 41 } 42 43 return number; 44} 45#endif 46 47#ifndef HAVE_BSEARCH 48void * 49bsearch (const void *key, const void *base, size_t nmemb, size_t size, 50 int (*compar) (const void *, const void *)) 51{ 52 size_t i; 53 int cmp; 54 55 /* We do a dumb incremental search, not a binary search, for now. */ 56 57 for (i = 0; i < nmemb; ++i) 58 { 59 if ((cmp = (*compar) (key, base)) == 0) 60 return base; 61 if (cmp < 0) 62 break; 63 base += size; 64 } 65 66 return NULL; 67} 68#endif 69