163272Smckusick /*- 2*63370Sbostic * Copyright (c) 1993 3*63370Sbostic * The Regents of the University of California. All rights reserved. 463272Smckusick * 563272Smckusick * This code is derived from software contributed to Berkeley by 663272Smckusick * The Mach Operating System project at Carnegie-Mellon University. 763272Smckusick * 863272Smckusick * %sccs.include.redist.c% 963272Smckusick * 10*63370Sbostic * @(#)close.c 8.1 (Berkeley) 06/11/93 1163272Smckusick * 1263272Smckusick * 1363272Smckusick * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University 1463272Smckusick * All Rights Reserved. 1563272Smckusick * 1663272Smckusick * Author: Alessandro Forin 1763272Smckusick * 1863272Smckusick * Permission to use, copy, modify and distribute this software and its 1963272Smckusick * documentation is hereby granted, provided that both the copyright 2063272Smckusick * notice and this permission notice appear in all copies of the 2163272Smckusick * software, derivative works or modified versions, and any portions 2263272Smckusick * thereof, and that both notices appear in supporting documentation. 2363272Smckusick * 2463272Smckusick * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 2563272Smckusick * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 2663272Smckusick * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 2763272Smckusick * 2863272Smckusick * Carnegie Mellon requests users of this software to return to 2963272Smckusick * 3063272Smckusick * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 3163272Smckusick * School of Computer Science 3263272Smckusick * Carnegie Mellon University 3363272Smckusick * Pittsburgh PA 15213-3890 3463272Smckusick * 3563272Smckusick * any improvements or extensions that they make and grant Carnegie the 3663272Smckusick * rights to redistribute these changes. 3763272Smckusick */ 3863272Smckusick 3963272Smckusick #include <stand/stand.h> 4063272Smckusick close(fd)4163272Smckusickclose(fd) 4263272Smckusick int fd; 4363272Smckusick { 4463272Smckusick register struct open_file *f = &files[fd]; 4563272Smckusick int err1, err2; 4663272Smckusick 4763272Smckusick if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) { 4863272Smckusick errno = EBADF; 4963272Smckusick return (-1); 5063272Smckusick } 5163272Smckusick if (!(f->f_flags & F_RAW)) 5263272Smckusick err1 = (f->f_ops->close)(f); 5363272Smckusick err2 = (f->f_dev->dv_close)(f); 5463272Smckusick f->f_flags = 0; 5563272Smckusick if (err1) { 5663272Smckusick errno = err1; 5763272Smckusick return (-1); 5863272Smckusick } 5963272Smckusick if (err2) { 6063272Smckusick errno = err2; 6163272Smckusick return (-1); 6263272Smckusick } 6363272Smckusick return (0); 6463272Smckusick } 65