Deleted Added
full compact
lseek.c (38452) lseek.c (65470)
1/* $FreeBSD: head/lib/libstand/lseek.c 65470 2000-09-05 09:52:50Z msmith $ */
1/* $NetBSD: lseek.c,v 1.4 1997/01/22 00:38:10 cgd Exp $ */
2
3/*-
4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * The Mach Operating System project at Carnegie-Mellon University.

--- 53 unchanged lines hidden (view full) ---

62 *
63 * any improvements or extensions that they make and grant Carnegie the
64 * rights to redistribute these changes.
65 */
66
67#include "stand.h"
68
69off_t
2/* $NetBSD: lseek.c,v 1.4 1997/01/22 00:38:10 cgd Exp $ */
3
4/*-
5 * Copyright (c) 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * The Mach Operating System project at Carnegie-Mellon University.

--- 53 unchanged lines hidden (view full) ---

63 *
64 * any improvements or extensions that they make and grant Carnegie the
65 * rights to redistribute these changes.
66 */
67
68#include "stand.h"
69
70off_t
70lseek(fd, offset, where)
71 int fd;
72 off_t offset;
73 int where;
71lseek(int fd, off_t offset, int where)
74{
72{
75 register struct open_file *f = &files[fd];
73 struct open_file *f = &files[fd];
76
74
77 if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
78 errno = EBADF;
79 return (-1);
80 }
75 if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
76 errno = EBADF;
77 return (-1);
78 }
81
79
82 if (f->f_flags & F_RAW) {
83 /*
84 * On RAW devices, update internal offset.
85 */
86 switch (where) {
87 case SEEK_SET:
88 f->f_offset = offset;
89 break;
90 case SEEK_CUR:
91 f->f_offset += offset;
92 break;
93 case SEEK_END:
94 default:
95 errno = EOFFSET;
96 return (-1);
97 }
98 return (f->f_offset);
80 if (f->f_flags & F_RAW) {
81 /*
82 * On RAW devices, update internal offset.
83 */
84 switch (where) {
85 case SEEK_SET:
86 f->f_offset = offset;
87 break;
88 case SEEK_CUR:
89 f->f_offset += offset;
90 break;
91 case SEEK_END:
92 default:
93 errno = EOFFSET;
94 return (-1);
99 }
95 }
96 return (f->f_offset);
97 }
100
98
101 return (f->f_ops->fo_seek)(f, offset, where);
99 /*
100 * If this is a relative seek, we need to correct the offset for
101 * bytes that we have already read but the caller doesn't know
102 * about.
103 */
104 if (where == SEEK_CUR)
105 offset -= f->f_ralen;
106
107 /*
108 * Invalidate the readahead buffer.
109 */
110 f->f_ralen = 0;
111
112 return (f->f_ops->fo_seek)(f, offset, where);
102}
113}