import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / posix_fadvise.c
bloba42d1a9e88298fe5f4922c0a10c4ffc4b5d5f0f9
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "lint.h"
30 #include <fcntl.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <errno.h>
36 * SUSv3 - file advisory information
38 * This function does nothing, but that's OK because the
39 * Posix specification doesn't require it to do anything
40 * other than return appropriate error numbers.
42 * In the future, a file system dependent fadvise() or fcntl()
43 * interface, similar to madvise(), should be developed to enable
44 * the kernel to optimize I/O operations based on the given advice.
47 /* ARGSUSED1 */
48 int
49 posix_fadvise(int fd, off_t offset, off_t len, int advice)
51 struct stat64 statb;
53 switch (advice) {
54 case POSIX_FADV_NORMAL:
55 case POSIX_FADV_RANDOM:
56 case POSIX_FADV_SEQUENTIAL:
57 case POSIX_FADV_WILLNEED:
58 case POSIX_FADV_DONTNEED:
59 case POSIX_FADV_NOREUSE:
60 break;
61 default:
62 return (EINVAL);
64 if (len < 0)
65 return (EINVAL);
66 if (fstat64(fd, &statb) != 0)
67 return (EBADF);
68 if (S_ISFIFO(statb.st_mode))
69 return (ESPIPE);
70 return (0);
73 #if !defined(_LP64)
75 /* ARGSUSED1 */
76 int
77 posix_fadvise64(int fd, off64_t offset, off64_t len, int advice)
79 struct stat64 statb;
81 switch (advice) {
82 case POSIX_FADV_NORMAL:
83 case POSIX_FADV_RANDOM:
84 case POSIX_FADV_SEQUENTIAL:
85 case POSIX_FADV_WILLNEED:
86 case POSIX_FADV_DONTNEED:
87 case POSIX_FADV_NOREUSE:
88 break;
89 default:
90 return (EINVAL);
92 if (len < 0)
93 return (EINVAL);
94 if (fstat64(fd, &statb) != 0)
95 return (EBADF);
96 if (S_ISFIFO(statb.st_mode))
97 return (ESPIPE);
98 return (0);
101 #endif