os/ossrv/genericopenlibs/cstdlib/LSTDIO/FSETPOS.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 * <<fsetpos>>---restore position of a stream or file
    17 * INDEX
    18 * fsetpos
    19 * ANSI_SYNOPSIS
    20 * #include <stdio.h>
    21 * int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>);
    22 * TRAD_SYNOPSIS
    23 * #include <stdio.h>
    24 * int fsetpos(<[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 <<fsetpos>> to return the file identified by <[fp]> to a previous
    31 * position <<*<[pos]>>> (after first recording it with <<fgetpos>>).
    32 * See <<fseek>> for a similar facility.
    33 * RETURNS
    34 * <<fgetpos>> returns <<0>> when successful.  If <<fgetpos>> fails, the
    35 * result is <<1>>.  The reason for failure is indicated in <<errno>>:
    36 * either <<ESPIPE>> (the stream identified by <[fp]> doesn't support
    37 * repositioning) or <<EINVAL>> (invalid file position).
    38 * PORTABILITY
    39 * ANSI C requires <<fsetpos>>, but does not specify the nature of
    40 * <<*<[pos]>>> beyond identifying it as written by <<fgetpos>>.
    41 * Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
    42 * <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
    43 * 
    44 *
    45 */
    46 
    47 
    48 
    49 #include <stdio.h>
    50 
    51 /**
    52 Reposition file pointer to a saved location.
    53 @return   If successful the function returns 0.
    54 Otherwise it returns nonzero and sets the global variable errno to a non-zero value.
    55 @param iop Pointer to an open file.
    56 @param pos Position value obtained from a previous call to fgetpos that indicates 
    57 the position of the file pointer at that moment.
    58 */
    59 EXPORT_C int
    60 fsetpos (FILE * iop, const fpos_t * pos)
    61 {
    62   int x = fseek (iop, *pos, SEEK_SET);
    63 
    64   if (x != 0)
    65     return 1;
    66   return 0;
    67 }