1*90275da6Sabs /* $NetBSD: tcgetsid.c,v 1.7 2012/06/25 22:32:46 abs Exp $ */
2722a21c4Sthorpej
3722a21c4Sthorpej /*-
4722a21c4Sthorpej * Copyright (c) 1989, 1993
5722a21c4Sthorpej * The Regents of the University of California. All rights reserved.
6722a21c4Sthorpej *
7722a21c4Sthorpej * Redistribution and use in source and binary forms, with or without
8722a21c4Sthorpej * modification, are permitted provided that the following conditions
9722a21c4Sthorpej * are met:
10722a21c4Sthorpej * 1. Redistributions of source code must retain the above copyright
11722a21c4Sthorpej * notice, this list of conditions and the following disclaimer.
12722a21c4Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
13722a21c4Sthorpej * notice, this list of conditions and the following disclaimer in the
14722a21c4Sthorpej * documentation and/or other materials provided with the distribution.
15eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
16722a21c4Sthorpej * may be used to endorse or promote products derived from this software
17722a21c4Sthorpej * without specific prior written permission.
18722a21c4Sthorpej *
19722a21c4Sthorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20722a21c4Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21722a21c4Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22722a21c4Sthorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23722a21c4Sthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24722a21c4Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25722a21c4Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26722a21c4Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27722a21c4Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28722a21c4Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29722a21c4Sthorpej * SUCH DAMAGE.
30722a21c4Sthorpej */
31722a21c4Sthorpej
32722a21c4Sthorpej #include <sys/cdefs.h>
33722a21c4Sthorpej #if defined(LIBC_SCCS) && !defined(lint)
34722a21c4Sthorpej #if 0
35722a21c4Sthorpej static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94";
36722a21c4Sthorpej #else
37*90275da6Sabs __RCSID("$NetBSD: tcgetsid.c,v 1.7 2012/06/25 22:32:46 abs Exp $");
38722a21c4Sthorpej #endif
39722a21c4Sthorpej #endif /* LIBC_SCCS and not lint */
40722a21c4Sthorpej
41722a21c4Sthorpej #include "namespace.h"
42722a21c4Sthorpej #include <sys/types.h>
43722a21c4Sthorpej #include <sys/ioctl.h>
44b48252f3Slukem
45b48252f3Slukem #include <assert.h>
46b48252f3Slukem #include <errno.h>
47722a21c4Sthorpej #include <termios.h>
48722a21c4Sthorpej #include <unistd.h>
49722a21c4Sthorpej
50722a21c4Sthorpej #ifdef __weak_alias
__weak_alias(tcgetsid,_tcgetsid)5160549036Smycroft __weak_alias(tcgetsid,_tcgetsid)
52722a21c4Sthorpej #endif
53722a21c4Sthorpej
54722a21c4Sthorpej pid_t
55*90275da6Sabs tcgetsid(int fd)
56722a21c4Sthorpej {
57722a21c4Sthorpej int s;
58722a21c4Sthorpej
59b48252f3Slukem _DIAGASSERT(fd != -1);
60b48252f3Slukem
61722a21c4Sthorpej if (ioctl(fd, TIOCGSID, &s) < 0)
62722a21c4Sthorpej return ((pid_t)-1);
63722a21c4Sthorpej
64722a21c4Sthorpej return ((pid_t)s);
65722a21c4Sthorpej }
66