os/ossrv/genericopenlibs/cstdlib/LSTDIO/LSTDIO.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/LSTDIO.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,74 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// STDIO functions implemented over EPOC32
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <_ansi.h>
    1.23 +#include <stdio_r.h>
    1.24 +
    1.25 +#define UNUSED_VAR(a) a = a
    1.26 +
    1.27 +extern "C" {
    1.28 +int e32cvt (char *buf, int buflen, double d, int width, int prec, int /*flags*/, int fchar)
    1.29 +	{
    1.30 +	TPtr8 res((TText8*)buf, buflen);
    1.31 +	TBuf8<0x50> fmt;
    1.32 +	TBool capitalE=EFalse;
    1.33 +	switch(fchar)
    1.34 +	{
    1.35 +	case 'f':
    1.36 +		fchar='f';
    1.37 +		break;
    1.38 +
    1.39 +	case 'E':
    1.40 +		capitalE=ETrue;	// and fallthrough
    1.41 +	case 'e':
    1.42 +		fchar='e';
    1.43 +		break;
    1.44 +
    1.45 +	case 'G':
    1.46 +		capitalE=ETrue;	// and fallthrough
    1.47 +	case 'g':
    1.48 +		fchar='g';
    1.49 +		break;
    1.50 +	default:
    1.51 +		return 0;
    1.52 +	}
    1.53 +	// construct a format string for use with TDes::Format - we can't use the
    1.54 +	// VFPRINTF original because it doesn't quite match and it might involve '*'
    1.55 +	// to read field widths from VFPRINTF arguments.
    1.56 +	fmt.Zero();
    1.57 +	fmt.Append('%');
    1.58 +	// flags?
    1.59 +	if (width)
    1.60 +		fmt.AppendNum(width);
    1.61 +	if (prec>=0)
    1.62 +		{
    1.63 +		fmt.Append('.');
    1.64 +		fmt.AppendNum(prec);
    1.65 +		}
    1.66 +	fmt.Append(fchar);
    1.67 +	TRAPD(r,res.Format(fmt,d));
    1.68 +    UNUSED_VAR(r);
    1.69 +	if (capitalE)
    1.70 +		{
    1.71 +		TInt pos=res.Locate('e');
    1.72 +		if (pos!=KErrNotFound)
    1.73 +			res[pos]='E';
    1.74 +		}
    1.75 +	return res.Length();
    1.76 +	}
    1.77 +}