os/ossrv/genericopenlibs/cstdlib/LSTDIO/LSTDIO.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// STDIO functions implemented over EPOC32
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <_ansi.h>
sl@0
    20
#include <stdio_r.h>
sl@0
    21
sl@0
    22
#define UNUSED_VAR(a) a = a
sl@0
    23
sl@0
    24
extern "C" {
sl@0
    25
int e32cvt (char *buf, int buflen, double d, int width, int prec, int /*flags*/, int fchar)
sl@0
    26
	{
sl@0
    27
	TPtr8 res((TText8*)buf, buflen);
sl@0
    28
	TBuf8<0x50> fmt;
sl@0
    29
	TBool capitalE=EFalse;
sl@0
    30
	switch(fchar)
sl@0
    31
	{
sl@0
    32
	case 'f':
sl@0
    33
		fchar='f';
sl@0
    34
		break;
sl@0
    35
sl@0
    36
	case 'E':
sl@0
    37
		capitalE=ETrue;	// and fallthrough
sl@0
    38
	case 'e':
sl@0
    39
		fchar='e';
sl@0
    40
		break;
sl@0
    41
sl@0
    42
	case 'G':
sl@0
    43
		capitalE=ETrue;	// and fallthrough
sl@0
    44
	case 'g':
sl@0
    45
		fchar='g';
sl@0
    46
		break;
sl@0
    47
	default:
sl@0
    48
		return 0;
sl@0
    49
	}
sl@0
    50
	// construct a format string for use with TDes::Format - we can't use the
sl@0
    51
	// VFPRINTF original because it doesn't quite match and it might involve '*'
sl@0
    52
	// to read field widths from VFPRINTF arguments.
sl@0
    53
	fmt.Zero();
sl@0
    54
	fmt.Append('%');
sl@0
    55
	// flags?
sl@0
    56
	if (width)
sl@0
    57
		fmt.AppendNum(width);
sl@0
    58
	if (prec>=0)
sl@0
    59
		{
sl@0
    60
		fmt.Append('.');
sl@0
    61
		fmt.AppendNum(prec);
sl@0
    62
		}
sl@0
    63
	fmt.Append(fchar);
sl@0
    64
	TRAPD(r,res.Format(fmt,d));
sl@0
    65
    UNUSED_VAR(r);
sl@0
    66
	if (capitalE)
sl@0
    67
		{
sl@0
    68
		TInt pos=res.Locate('e');
sl@0
    69
		if (pos!=KErrNotFound)
sl@0
    70
			res[pos]='E';
sl@0
    71
		}
sl@0
    72
	return res.Length();
sl@0
    73
	}
sl@0
    74
}