xref: /netbsd-src/lib/libc/stdio/fseek.c (revision 5988775b41e22ca71c0f657887fae5db6869c4bf)
1*5988775bSchristos /*	$NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $	*/
2255db7b2Sjtc 
361f28255Scgd /*-
47f902948Sdsl  * Copyright (c) 2005 The NetBSD Foundation, Inc.
57f902948Sdsl  * All rights reserved.
661f28255Scgd  *
77f902948Sdsl  * This code is derived from software contributed to The NetBSD Foundation
87f902948Sdsl  * by David Laight.
961f28255Scgd  *
1061f28255Scgd  * Redistribution and use in source and binary forms, with or without
1161f28255Scgd  * modification, are permitted provided that the following conditions
1261f28255Scgd  * are met:
1361f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1461f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1561f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1661f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1761f28255Scgd  *    documentation and/or other materials provided with the distribution.
1861f28255Scgd  *
197f902948Sdsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
207f902948Sdsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
217f902948Sdsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
227f902948Sdsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
237f902948Sdsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
247f902948Sdsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
257f902948Sdsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
267f902948Sdsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
277f902948Sdsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
287f902948Sdsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
297f902948Sdsl  * POSSIBILITY OF SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
3223312f88Schristos #include <sys/cdefs.h>
3361f28255Scgd #if defined(LIBC_SCCS) && !defined(lint)
34*5988775bSchristos __RCSID("$NetBSD: fseek.c,v 1.24 2014/11/16 20:32:52 christos Exp $");
3561f28255Scgd #endif /* LIBC_SCCS and not lint */
3661f28255Scgd 
3761f28255Scgd #include <sys/types.h>
3861f28255Scgd #include <sys/stat.h>
39b48252f3Slukem 
40464456b7Skleink #include "namespace.h"
41b48252f3Slukem #include <assert.h>
42b48252f3Slukem #include <errno.h>
4361f28255Scgd #include <fcntl.h>
4461f28255Scgd #include <stdio.h>
4561f28255Scgd #include <stdlib.h>
46da2013acSjtc #include "reentrant.h"
473fdac2b8Sthorpej #include "local.h"
4861f28255Scgd 
4961f28255Scgd /*
5061f28255Scgd  * Seek the given file to the given offset.
517f902948Sdsl  * Zero extend the offset if SEEK_SET to allow access to 4GB files
5261f28255Scgd  */
53255db7b2Sjtc int
fseek(FILE * fp,long l_offset,int whence)547f902948Sdsl fseek(FILE *fp, long l_offset, int whence)
5561f28255Scgd {
567f902948Sdsl 	off_t offset;
5761f28255Scgd 
58*5988775bSchristos #if 0
59*5988775bSchristos 	/* This is a bad idea because makes fseek(fp, -6, SEEK_SET) work... */
6061f28255Scgd 	if (whence == SEEK_SET)
617f902948Sdsl 		offset = (unsigned long)l_offset;
627f902948Sdsl 	else
63*5988775bSchristos #endif
647f902948Sdsl 		offset = l_offset;
657f902948Sdsl 	return fseeko(fp, offset, whence);
6661f28255Scgd }
67