1*11e36004Skn /* $OpenBSD: fchmod.c,v 1.3 2023/04/08 18:12:08 kn Exp $ */
2044dcf88Sderaadt /* $NetBSD: stat.c,v 1.3 1994/10/26 05:45:07 cgd Exp $ */
3044dcf88Sderaadt
4044dcf88Sderaadt /*-
5044dcf88Sderaadt * Copyright (c) 1993
6044dcf88Sderaadt * The Regents of the University of California. All rights reserved.
7044dcf88Sderaadt *
8044dcf88Sderaadt * Redistribution and use in source and binary forms, with or without
9044dcf88Sderaadt * modification, are permitted provided that the following conditions
10044dcf88Sderaadt * are met:
11044dcf88Sderaadt * 1. Redistributions of source code must retain the above copyright
12044dcf88Sderaadt * notice, this list of conditions and the following disclaimer.
13044dcf88Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
14044dcf88Sderaadt * notice, this list of conditions and the following disclaimer in the
15044dcf88Sderaadt * documentation and/or other materials provided with the distribution.
16044dcf88Sderaadt * 3. Neither the name of the University nor the names of its contributors
17044dcf88Sderaadt * may be used to endorse or promote products derived from this software
18044dcf88Sderaadt * without specific prior written permission.
19044dcf88Sderaadt *
20044dcf88Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21044dcf88Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22044dcf88Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23044dcf88Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24044dcf88Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25044dcf88Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26044dcf88Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27044dcf88Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28044dcf88Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29044dcf88Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30044dcf88Sderaadt * SUCH DAMAGE.
31044dcf88Sderaadt *
32044dcf88Sderaadt * @(#)stat.c 8.1 (Berkeley) 6/11/93
33044dcf88Sderaadt */
34044dcf88Sderaadt
35044dcf88Sderaadt #include "stand.h"
36044dcf88Sderaadt
37044dcf88Sderaadt int
fchmod(int fd,mode_t m)38044dcf88Sderaadt fchmod(int fd, mode_t m)
39044dcf88Sderaadt {
40044dcf88Sderaadt struct open_file *f = &files[fd];
41044dcf88Sderaadt
42044dcf88Sderaadt if (f->f_ops->fchmod == NULL) {
43044dcf88Sderaadt errno = EOPNOTSUPP;
44044dcf88Sderaadt return (-1);
45044dcf88Sderaadt }
46044dcf88Sderaadt if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
47044dcf88Sderaadt errno = EBADF;
48044dcf88Sderaadt return (-1);
49044dcf88Sderaadt }
50044dcf88Sderaadt
51044dcf88Sderaadt /* operation not defined on raw devices */
52044dcf88Sderaadt if (f->f_flags & F_RAW) {
53044dcf88Sderaadt errno = EOPNOTSUPP;
54044dcf88Sderaadt return (-1);
55044dcf88Sderaadt }
5671b09c73Skettenis /* writing is broken or unsupported */
5771b09c73Skettenis if (f->f_flags & F_NOWRITE) {
5871b09c73Skettenis errno = EOPNOTSUPP;
5971b09c73Skettenis return (-1);
6071b09c73Skettenis }
61044dcf88Sderaadt
62*11e36004Skn if ((errno = (f->f_ops->fchmod)(f, m)))
63*11e36004Skn return (-1);
64044dcf88Sderaadt return (0);
65044dcf88Sderaadt }
66