dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / libelf / common / flag.c
blob173d51724274699760d3b3ad9a8ada9a98770203
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) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include "libelf.h"
33 #include "decl.h"
34 #include "msg.h"
37 unsigned
38 elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned flags)
40 unsigned rc = 0;
41 Elf * elf;
42 Elf_Scn * scn;
43 Dnode * d;
45 if (data == 0)
46 return (0);
47 d = (Dnode *) data;
48 scn = d->db_scn;
49 elf = scn->s_elf;
51 READLOCKS(elf, scn)
53 if (cmd == ELF_C_SET) {
54 rc = d->db_uflags |= flags;
55 } else if (cmd == ELF_C_CLR) {
56 rc = d->db_uflags &= ~flags;
57 } else
58 _elf_seterr(EREQ_FLAG, 0);
59 READUNLOCKS(elf, scn)
60 return (rc);
64 unsigned int
65 elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
67 int rc;
68 if (elf == 0)
69 return (0);
70 if (cmd == ELF_C_SET) {
71 ELFWLOCK(elf)
72 rc = elf->ed_ehflags |= flags;
73 ELFUNLOCK(elf)
74 return (rc);
76 if (cmd == ELF_C_CLR) {
77 ELFWLOCK(elf)
78 rc = elf->ed_ehflags &= ~flags;
79 ELFUNLOCK(elf)
80 return (rc);
82 _elf_seterr(EREQ_FLAG, 0);
83 return (0);
87 unsigned
88 elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned flags)
90 int rc;
91 if (elf == 0)
92 return (0);
93 if (cmd == ELF_C_SET) {
94 ELFWLOCK(elf)
95 rc = elf->ed_uflags |= flags;
96 ELFUNLOCK(elf)
97 return (rc);
99 if (cmd == ELF_C_CLR) {
100 ELFWLOCK(elf)
101 rc = elf->ed_uflags &= ~flags;
102 ELFUNLOCK(elf)
103 return (rc);
105 _elf_seterr(EREQ_FLAG, 0);
106 return (0);
110 unsigned
111 elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
113 int rc;
114 if (elf == 0)
115 return (0);
116 if (cmd == ELF_C_SET) {
117 ELFWLOCK(elf);
118 rc = elf->ed_phflags |= flags;
119 ELFUNLOCK(elf);
120 return (rc);
122 if (cmd == ELF_C_CLR) {
123 ELFWLOCK(elf);
124 rc = elf->ed_phflags &= ~flags;
125 ELFUNLOCK(elf);
126 return (rc);
128 _elf_seterr(EREQ_FLAG, 0);
129 return (0);
133 unsigned
134 elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
136 unsigned rc;
137 Elf * elf;
139 if (scn == 0)
140 return (0);
142 elf = scn->s_elf;
143 if (cmd == ELF_C_SET) {
144 READLOCKS(elf, scn)
145 rc = scn->s_uflags |= flags;
146 READUNLOCKS(elf, scn)
147 return (rc);
149 if (cmd == ELF_C_CLR) {
150 READLOCKS(elf, scn)
151 rc = scn->s_uflags &= ~flags;
152 READUNLOCKS(elf, scn)
153 return (rc);
155 _elf_seterr(EREQ_FLAG, 0);
156 return (0);
160 unsigned
161 elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
163 unsigned rc;
164 Elf * elf;
165 if (scn == 0)
166 return (0);
168 elf = scn->s_elf;
169 if (cmd == ELF_C_SET) {
170 READLOCKS(elf, scn)
171 rc = scn->s_shflags |= flags;
172 READUNLOCKS(elf, scn)
173 return (rc);
175 if (cmd == ELF_C_CLR) {
176 READLOCKS(elf, scn)
177 rc = scn->s_shflags &= ~flags;
178 READUNLOCKS(elf, scn)
179 return (rc);
181 _elf_seterr(EREQ_FLAG, 0);
182 return (0);