xref: /freebsd/stand/libsa/preload.c (revision 7c43148a974877188a930e4078a164f83da8e652)
1*c25d9affSEmmanuel Vadot /*-
2*c25d9affSEmmanuel Vadot  * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
3*c25d9affSEmmanuel Vadot  *
4*c25d9affSEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
5*c25d9affSEmmanuel Vadot  * modification, are permitted provided that the following conditions
6*c25d9affSEmmanuel Vadot  * are met:
7*c25d9affSEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
8*c25d9affSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
9*c25d9affSEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
10*c25d9affSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
11*c25d9affSEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
12*c25d9affSEmmanuel Vadot  *
13*c25d9affSEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*c25d9affSEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*c25d9affSEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*c25d9affSEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*c25d9affSEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*c25d9affSEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*c25d9affSEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*c25d9affSEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*c25d9affSEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*c25d9affSEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*c25d9affSEmmanuel Vadot  * SUCH DAMAGE.
24*c25d9affSEmmanuel Vadot  *
25*c25d9affSEmmanuel Vadot  */
26*c25d9affSEmmanuel Vadot 
27*c25d9affSEmmanuel Vadot #include <sys/param.h>
28*c25d9affSEmmanuel Vadot #include "stand.h"
29*c25d9affSEmmanuel Vadot 
30*c25d9affSEmmanuel Vadot void
preload(int fd)31*c25d9affSEmmanuel Vadot preload(int fd)
32*c25d9affSEmmanuel Vadot {
33*c25d9affSEmmanuel Vadot 	struct open_file *f;
34*c25d9affSEmmanuel Vadot 
35*c25d9affSEmmanuel Vadot 	f = fd2open_file(fd);
36*c25d9affSEmmanuel Vadot 	if (f == NULL) {
37*c25d9affSEmmanuel Vadot 		errno = EBADF;
38*c25d9affSEmmanuel Vadot 		return;
39*c25d9affSEmmanuel Vadot 	}
40*c25d9affSEmmanuel Vadot 	if (f->f_ops->fo_preload)
41*c25d9affSEmmanuel Vadot 		(f->f_ops->fo_preload)(f);
42*c25d9affSEmmanuel Vadot }
43