10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * attropen -- C library extension routine
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
34*6812Sraf #pragma weak _attropen64 = attropen64
350Sstevel@tonic-gate #else
36*6812Sraf #pragma weak _attropen = attropen
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate
39*6812Sraf #include "lint.h"
40*6812Sraf #include <sys/types.h>
41*6812Sraf #include <sys/stat.h>
42*6812Sraf #include <fcntl.h>
43*6812Sraf #include <stdlib.h>
44*6812Sraf #include <errno.h>
45*6812Sraf #include <unistd.h>
46*6812Sraf #include <stdarg.h>
470Sstevel@tonic-gate
480Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
490Sstevel@tonic-gate
500Sstevel@tonic-gate int
attropen64(const char * file,const char * attr,int oflag,...)510Sstevel@tonic-gate attropen64(const char *file, const char *attr, int oflag, ...)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate int fd;
540Sstevel@tonic-gate int attrfd;
550Sstevel@tonic-gate int saverrno;
560Sstevel@tonic-gate va_list ap;
570Sstevel@tonic-gate
580Sstevel@tonic-gate va_start(ap, oflag);
590Sstevel@tonic-gate
600Sstevel@tonic-gate if ((fd = open64(file, O_RDONLY|O_NONBLOCK)) == -1) {
610Sstevel@tonic-gate va_end(ap);
620Sstevel@tonic-gate return (-1);
630Sstevel@tonic-gate }
640Sstevel@tonic-gate
650Sstevel@tonic-gate if ((attrfd = openat64(fd, attr, oflag | O_XATTR,
66*6812Sraf va_arg(ap, mode_t))) == -1) {
670Sstevel@tonic-gate saverrno = errno;
680Sstevel@tonic-gate (void) close(fd);
690Sstevel@tonic-gate errno = saverrno;
700Sstevel@tonic-gate va_end(ap);
710Sstevel@tonic-gate return (-1);
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
740Sstevel@tonic-gate (void) close(fd);
750Sstevel@tonic-gate va_end(ap);
760Sstevel@tonic-gate return (attrfd);
770Sstevel@tonic-gate }
780Sstevel@tonic-gate
790Sstevel@tonic-gate #else
800Sstevel@tonic-gate
810Sstevel@tonic-gate int
attropen(const char * file,const char * attr,int oflag,...)820Sstevel@tonic-gate attropen(const char *file, const char *attr, int oflag, ...)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate int fd;
850Sstevel@tonic-gate int attrfd;
860Sstevel@tonic-gate int saverrno;
870Sstevel@tonic-gate va_list ap;
880Sstevel@tonic-gate
890Sstevel@tonic-gate va_start(ap, oflag);
900Sstevel@tonic-gate
910Sstevel@tonic-gate if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
920Sstevel@tonic-gate va_end(ap);
930Sstevel@tonic-gate return (-1);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate if ((attrfd = openat(fd, attr, oflag | O_XATTR,
97*6812Sraf va_arg(ap, mode_t))) == -1) {
980Sstevel@tonic-gate saverrno = errno;
990Sstevel@tonic-gate (void) close(fd);
1000Sstevel@tonic-gate errno = saverrno;
1010Sstevel@tonic-gate va_end(ap);
1020Sstevel@tonic-gate return (-1);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate (void) close(fd);
1060Sstevel@tonic-gate va_end(ap);
1070Sstevel@tonic-gate return (attrfd);
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate #endif /* _FILE_OFFSET_BITS == 64 */
111