Home | History | Annotate | Line # | Download | only in stdio
      1  1.24  christos /*	$NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos 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.1       cgd  *
     19  1.21       dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.21       dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.21       dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.21       dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.21       dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.21       dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.21       dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.21       dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.21       dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.21       dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.21       dsl  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32   1.9  christos #include <sys/cdefs.h>
     33   1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     34  1.24  christos __RCSID("$NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $");
     35   1.1       cgd #endif /* LIBC_SCCS and not lint */
     36   1.1       cgd 
     37   1.1       cgd #include <sys/types.h>
     38   1.1       cgd #include <sys/stat.h>
     39  1.17     lukem 
     40  1.22    kleink #include "namespace.h"
     41  1.17     lukem #include <assert.h>
     42  1.17     lukem #include <errno.h>
     43   1.1       cgd #include <fcntl.h>
     44   1.1       cgd #include <stdio.h>
     45   1.1       cgd #include <stdlib.h>
     46  1.19   thorpej #include "reentrant.h"
     47   1.1       cgd #include "local.h"
     48   1.1       cgd 
     49   1.1       cgd /*
     50   1.1       cgd  * Seek the given file to the given offset.
     51  1.21       dsl  * Zero extend the offset if SEEK_SET to allow access to 4GB files
     52   1.1       cgd  */
     53   1.7       jtc int
     54  1.21       dsl fseek(FILE *fp, long l_offset, int whence)
     55   1.1       cgd {
     56  1.21       dsl 	off_t offset;
     57   1.1       cgd 
     58  1.24  christos #if 0
     59  1.24  christos 	/* This is a bad idea because makes fseek(fp, -6, SEEK_SET) work... */
     60   1.1       cgd 	if (whence == SEEK_SET)
     61  1.21       dsl 		offset = (unsigned long)l_offset;
     62  1.21       dsl 	else
     63  1.24  christos #endif
     64  1.21       dsl 		offset = l_offset;
     65  1.21       dsl 	return fseeko(fp, offset, whence);
     66   1.1       cgd }
     67