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