os/ossrv/genericopenlibs/cstdlib/LSTDIO/FSETPOS.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/FSETPOS.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +* FUNCTION
    1.19 +* <<fsetpos>>---restore position of a stream or file
    1.20 +* INDEX
    1.21 +* fsetpos
    1.22 +* ANSI_SYNOPSIS
    1.23 +* #include <stdio.h>
    1.24 +* int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>);
    1.25 +* TRAD_SYNOPSIS
    1.26 +* #include <stdio.h>
    1.27 +* int fsetpos(<[fp]>, <[pos]>)
    1.28 +* FILE *<[fp]>;
    1.29 +* fpos_t *<[pos]>;
    1.30 +* Objects of type <<FILE>> can have a ``position'' that records how much
    1.31 +* of the file your program has already read.  Many of the <<stdio>> functions
    1.32 +* depend on this position, and many change it as a side effect.
    1.33 +* You can use <<fsetpos>> to return the file identified by <[fp]> to a previous
    1.34 +* position <<*<[pos]>>> (after first recording it with <<fgetpos>>).
    1.35 +* See <<fseek>> for a similar facility.
    1.36 +* RETURNS
    1.37 +* <<fgetpos>> returns <<0>> when successful.  If <<fgetpos>> fails, the
    1.38 +* result is <<1>>.  The reason for failure is indicated in <<errno>>:
    1.39 +* either <<ESPIPE>> (the stream identified by <[fp]> doesn't support
    1.40 +* repositioning) or <<EINVAL>> (invalid file position).
    1.41 +* PORTABILITY
    1.42 +* ANSI C requires <<fsetpos>>, but does not specify the nature of
    1.43 +* <<*<[pos]>>> beyond identifying it as written by <<fgetpos>>.
    1.44 +* Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
    1.45 +* <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
    1.46 +* 
    1.47 +*
    1.48 +*/
    1.49 +
    1.50 +
    1.51 +
    1.52 +#include <stdio.h>
    1.53 +
    1.54 +/**
    1.55 +Reposition file pointer to a saved location.
    1.56 +@return   If successful the function returns 0.
    1.57 +Otherwise it returns nonzero and sets the global variable errno to a non-zero value.
    1.58 +@param iop Pointer to an open file.
    1.59 +@param pos Position value obtained from a previous call to fgetpos that indicates 
    1.60 +the position of the file pointer at that moment.
    1.61 +*/
    1.62 +EXPORT_C int
    1.63 +fsetpos (FILE * iop, const fpos_t * pos)
    1.64 +{
    1.65 +  int x = fseek (iop, *pos, SEEK_SET);
    1.66 +
    1.67 +  if (x != 0)
    1.68 +    return 1;
    1.69 +  return 0;
    1.70 +}