import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / stdio / flockf.c
blob0d31d5649bd44bd1804fe657d63bc8d8eea34415
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 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include "lint.h"
33 #include "mtlib.h"
34 #include "file64.h"
35 #include <stdio.h>
36 #include <thread.h>
37 #include <synch.h>
38 #include <stdlib.h>
39 #include <errno.h>
40 #include <stdio_ext.h>
41 #include "stdiom.h"
43 #define _iob __iob
46 * _flockget and _flockrel are only called by the
47 * FLOCKFILE/FUNLOCKFILE macros in mtlib.h.
51 * compute the lock's position, acquire it and return its pointer
54 rmutex_t *
55 _flockget(FILE *iop)
57 rmutex_t *rl = IOB_LCK(iop);
59 if (rl != NULL)
60 cancel_safe_mutex_lock(rl);
61 return (rl);
64 int
65 ftrylockfile(FILE *iop)
67 rmutex_t *rl = IOB_LCK(iop);
69 if (rl != NULL)
70 return (mutex_trylock(rl));
71 return (0); /* can't happen? */
74 void
75 flockfile(FILE *iop)
77 rmutex_t *rl = IOB_LCK(iop);
79 if (rl != NULL)
80 (void) mutex_lock(rl);
83 void
84 funlockfile(FILE *iop)
86 rmutex_t *rl = IOB_LCK(iop);
88 if (rl != NULL)
89 (void) mutex_unlock(rl);
92 int
93 __fsetlocking(FILE *iop, int type)
95 int ret = 0;
97 ret = GET_IONOLOCK(iop) ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL;
99 switch (type) {
101 case FSETLOCKING_QUERY:
102 break;
104 case FSETLOCKING_INTERNAL:
105 CLEAR_IONOLOCK(iop);
106 break;
108 case FSETLOCKING_BYCALLER:
109 SET_IONOLOCK(iop);
110 break;
112 default:
113 errno = EINVAL;
114 return (-1);
117 return (ret);