Hex Artifact Content

Artifact 097c39a2a670ffec644a925a5cbee2006327ee78:


0000: 2f 2a 20 0a 20 2a 20 66 69 78 73 74 72 74 6f 64  /* . * fixstrtod
0010: 2e 63 20 2d 2d 0a 20 2a 0a 20 2a 09 53 6f 75 72  .c --. *. *.Sour
0020: 63 65 20 63 6f 64 65 20 66 6f 72 20 74 68 65 20  ce code for the 
0030: 22 66 69 78 73 74 72 74 6f 64 22 20 70 72 6f 63  "fixstrtod" proc
0040: 65 64 75 72 65 2e 20 20 54 68 69 73 20 70 72 6f  edure.  This pro
0050: 63 65 64 75 72 65 20 69 73 0a 20 2a 09 75 73 65  cedure is. *.use
0060: 64 20 69 6e 20 70 6c 61 63 65 20 6f 66 20 73 74  d in place of st
0070: 72 74 6f 64 20 75 6e 64 65 72 20 53 6f 6c 61 72  rtod under Solar
0080: 69 73 20 32 2e 34 2c 20 69 6e 20 6f 72 64 65 72  is 2.4, in order
0090: 20 74 6f 20 66 69 78 0a 20 2a 09 61 20 62 75 67   to fix. *.a bug
00a0: 20 77 68 65 72 65 20 74 68 65 20 22 65 6e 64 22   where the "end"
00b0: 20 70 6f 69 6e 74 65 72 20 67 65 74 73 20 73 65   pointer gets se
00c0: 74 20 69 6e 63 6f 72 72 65 63 74 6c 79 2e 0a 20  t incorrectly.. 
00d0: 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 28  *. * Copyright (
00e0: 63 29 20 31 39 39 35 20 53 75 6e 20 4d 69 63 72  c) 1995 Sun Micr
00f0: 6f 73 79 73 74 65 6d 73 2c 20 49 6e 63 2e 0a 20  osystems, Inc.. 
0100: 2a 0a 20 2a 20 53 65 65 20 74 68 65 20 66 69 6c  *. * See the fil
0110: 65 20 22 6c 69 63 65 6e 73 65 2e 74 65 72 6d 73  e "license.terms
0120: 22 20 66 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f  " for informatio
0130: 6e 20 6f 6e 20 75 73 61 67 65 20 61 6e 64 20 72  n on usage and r
0140: 65 64 69 73 74 72 69 62 75 74 69 6f 6e 0a 20 2a  edistribution. *
0150: 20 6f 66 20 74 68 69 73 20 66 69 6c 65 2c 20 61   of this file, a
0160: 6e 64 20 66 6f 72 20 61 20 44 49 53 43 4c 41 49  nd for a DISCLAI
0170: 4d 45 52 20 4f 46 20 41 4c 4c 20 57 41 52 52 41  MER OF ALL WARRA
0180: 4e 54 49 45 53 2e 0a 20 2a 0a 20 2a 20 53 43 43  NTIES.. *. * SCC
0190: 53 3a 20 40 28 23 29 20 66 69 78 73 74 72 74 6f  S: @(#) fixstrto
01a0: 64 2e 63 20 31 2e 35 20 39 36 2f 30 32 2f 31 35  d.c 1.5 96/02/15
01b0: 20 31 32 3a 30 38 3a 32 31 0a 20 2a 2f 0a 0a 23   12:08:21. */..#
01c0: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68  include <stdio.h
01d0: 3e 0a 0a 23 75 6e 64 65 66 20 73 74 72 74 6f 64  >..#undef strtod
01e0: 0a 0a 2f 2a 0a 20 2a 20 44 65 63 6c 61 72 65 20  ../*. * Declare 
01f0: 73 74 72 74 6f 64 20 65 78 70 6c 69 63 69 74 6c  strtod explicitl
0200: 79 20 72 61 74 68 65 72 20 74 68 61 6e 20 69 6e  y rather than in
0210: 63 6c 75 64 69 6e 67 20 73 74 64 6c 69 62 2e 68  cluding stdlib.h
0220: 2c 20 73 69 6e 63 65 20 69 6e 0a 20 2a 20 73 6f  , since in. * so
0230: 6d 65 73 20 73 79 73 74 65 6d 73 20 28 65 2e 67  mes systems (e.g
0240: 2e 20 53 75 6e 4f 53 20 34 2e 31 2e 34 29 20 73  . SunOS 4.1.4) s
0250: 74 64 6c 69 62 2e 68 20 64 6f 65 73 6e 27 74 20  tdlib.h doesn't 
0260: 64 65 63 6c 61 72 65 20 73 74 72 74 6f 64 2e 0a  declare strtod..
0270: 20 2a 2f 0a 0a 65 78 74 65 72 6e 20 64 6f 75 62   */..extern doub
0280: 6c 65 20 73 74 72 74 6f 64 28 29 3b 0a 0a 64 6f  le strtod();..do
0290: 75 62 6c 65 0a 66 69 78 73 74 72 74 6f 64 28 73  uble.fixstrtod(s
02a0: 74 72 69 6e 67 2c 20 65 6e 64 50 74 72 29 0a 20  tring, endPtr). 
02b0: 20 20 20 63 68 61 72 20 2a 73 74 72 69 6e 67 3b     char *string;
02c0: 0a 20 20 20 20 63 68 61 72 20 2a 2a 65 6e 64 50  .    char **endP
02d0: 74 72 3b 0a 7b 0a 20 20 20 20 64 6f 75 62 6c 65  tr;.{.    double
02e0: 20 64 3b 0a 20 20 20 20 64 20 3d 20 73 74 72 74   d;.    d = strt
02f0: 6f 64 28 73 74 72 69 6e 67 2c 20 65 6e 64 50 74  od(string, endPt
0300: 72 29 3b 0a 20 20 20 20 69 66 20 28 28 65 6e 64  r);.    if ((end
0310: 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 26 26 20  Ptr != NULL) && 
0320: 28 2a 65 6e 64 50 74 72 20 21 3d 20 73 74 72 69  (*endPtr != stri
0330: 6e 67 29 20 26 26 20 28 28 2a 65 6e 64 50 74 72  ng) && ((*endPtr
0340: 29 5b 2d 31 5d 20 3d 3d 20 30 29 29 20 7b 0a 09  )[-1] == 0)) {..
0350: 2a 65 6e 64 50 74 72 20 2d 3d 20 31 3b 0a 20 20  *endPtr -= 1;.  
0360: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 64    }.    return d
0370: 3b 0a 7d 0a                                      ;.}.