Home | History | Annotate | Line # | Download | only in stdio
fseek.c revision 1.21.2.1
      1  1.21.2.1      tron /*	$NetBSD: fseek.c,v 1.21.2.1 2006/01/28 10:21:38 tron Exp $	*/
      2       1.7       jtc 
      3       1.1       cgd /*-
      4      1.21       dsl  * Copyright (c) 2005 The NetBSD Foundation, Inc.
      5      1.21       dsl  * All rights reserved.
      6       1.1       cgd  *
      7      1.21       dsl  * This code is derived from software contributed to The NetBSD Foundation
      8      1.21       dsl  * by David Laight.
      9       1.1       cgd  *
     10       1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11       1.1       cgd  * modification, are permitted provided that the following conditions
     12       1.1       cgd  * are met:
     13       1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14       1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15       1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17       1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18      1.21       dsl  * 3. Neither the name of The NetBSD Foundation nor the names of its
     19      1.21       dsl  *    contributors may be used to endorse or promote products derived
     20      1.21       dsl  *    from this software without specific prior written permission.
     21       1.1       cgd  *
     22      1.21       dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23      1.21       dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24      1.21       dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25      1.21       dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26      1.21       dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27      1.21       dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28      1.21       dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29      1.21       dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30      1.21       dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31      1.21       dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32      1.21       dsl  * POSSIBILITY OF SUCH DAMAGE.
     33       1.1       cgd  */
     34       1.1       cgd 
     35       1.9  christos #include <sys/cdefs.h>
     36       1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     37  1.21.2.1      tron __RCSID("$NetBSD: fseek.c,v 1.21.2.1 2006/01/28 10:21:38 tron Exp $");
     38       1.1       cgd #endif /* LIBC_SCCS and not lint */
     39       1.1       cgd 
     40       1.1       cgd #include <sys/types.h>
     41       1.1       cgd #include <sys/stat.h>
     42      1.17     lukem 
     43  1.21.2.1      tron #include "namespace.h"
     44      1.17     lukem #include <assert.h>
     45      1.17     lukem #include <errno.h>
     46       1.1       cgd #include <fcntl.h>
     47       1.1       cgd #include <stdio.h>
     48       1.1       cgd #include <stdlib.h>
     49      1.19   thorpej #include "reentrant.h"
     50       1.1       cgd #include "local.h"
     51       1.1       cgd 
     52       1.1       cgd /*
     53       1.1       cgd  * Seek the given file to the given offset.
     54      1.21       dsl  * Zero extend the offset if SEEK_SET to allow access to 4GB files
     55       1.1       cgd  */
     56       1.7       jtc int
     57      1.21       dsl fseek(FILE *fp, long l_offset, int whence)
     58       1.1       cgd {
     59      1.21       dsl 	off_t offset;
     60       1.1       cgd 
     61       1.1       cgd 	if (whence == SEEK_SET)
     62      1.21       dsl 		offset = (unsigned long)l_offset;
     63      1.21       dsl 	else
     64      1.21       dsl 		offset = l_offset;
     65      1.21       dsl 	return fseeko(fp, offset, whence);
     66       1.1       cgd }
     67