os/ossrv/genericopenlibs/cstdlib/LSTDIO/FGETPOS.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * FUNCTION
    16 * <<fgetpos>>---record position in a stream or file
    17 * INDEX
    18 * fgetpos
    19 * ANSI_SYNOPSIS
    20 * #include <stdio.h>
    21 * int fgetpos(FILE *<[fp]>, fpos_t *<[pos]>);
    22 * TRAD_SYNOPSIS
    23 * #include <stdio.h>
    24 * int fgetpos(<[fp]>, <[pos]>)
    25 * FILE *<[fp]>;
    26 * fpos_t *<[pos]>;
    27 * Objects of type <<FILE>> can have a ``position'' that records how much
    28 * of the file your program has already read.  Many of the <<stdio>> functions
    29 * depend on this position, and many change it as a side effect.
    30 * You can use <<fgetpos>> to report on the current position for a file
    31 * identified by <[fp]>; <<fgetpos>> will write a value
    32 * representing that position at <<*<[pos]>>>.  Later, you can
    33 * use this value with <<fsetpos>> to return the file to this
    34 * position.
    35 * In the current implementation, <<fgetpos>> simply uses a character
    36 * count to represent the file position; this is the same number that
    37 * would be returned by <<ftell>>.
    38 * RETURNS
    39 * <<fgetpos>> returns <<0>> when successful.  If <<fgetpos>> fails, the
    40 * result is <<1>>.  Failure occurs on streams that do not support
    41 * positioning; the global <<errno>> indicates this condition with the
    42 * value <<ESPIPE>>.
    43 * PORTABILITY
    44 * <<fgetpos>> is required by the ANSI C standard, but the meaning of the
    45 * value it records is not specified beyond requiring that it be
    46 * acceptable as an argument to <<fsetpos>>.  In particular, other
    47 * conforming C implementations may return a different result from
    48 * <<ftell>> than what <<fgetpos>> writes at <<*<[pos]>>>.
    49 * No supporting OS subroutines are required.
    50 * 
    51 *
    52 */
    53 
    54 
    55 
    56 #include <stdio.h>
    57 /**
    58 Get position in a stream.
    59 @return 0 value indicates success. non-zero value indicates error.
    60 @param fp pointer to an open file. 
    61 @param pos pointer to a fpos_t object where the position will be stored. 
    62 */
    63 EXPORT_C int
    64 fgetpos (FILE * fp, fpos_t * pos)
    65 {
    66   *pos = ftell (fp);
    67 
    68   if (*pos != -1)
    69     return 0;
    70   return 1;
    71 }