OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [stdlib/] [grantpt.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
 
4
   The GNU C Library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public License as
6
   published by the Free Software Foundation; either version 2 of the
7
   License, or (at your option) any later version.
8
 
9
   The GNU C Library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
13
 
14
   You should have received a copy of the GNU Library General Public
15
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
16
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
   Boston, MA 02111-1307, USA.  */
18
 
19
#include <limits.h>
20
#include <stdlib.h>
21
 
22
/* If __ASSUME_DEVPTS__ is defined, grantpt() reduces to a stub since we
23
   assume that the devfs/devpts filesystem automatically manages the
24
   permissions. */
25
#if !defined __ASSUME_DEVPTS__
26
#include <sys/statfs.h>
27
 
28
/* Constant that identifies the `devpts' filesystem.  */
29
#define DEVPTS_SUPER_MAGIC      0x1cd1
30
/* Constant that identifies the `devfs' filesystem.  */
31
#define DEVFS_SUPER_MAGIC       0x1373
32
 
33
/* Prototype for function that changes ownership and access permission
34
   for slave pseudo terminals that do not live on a `devpts'
35
   filesystem.  */
36
int __unix_grantpt (int fd);
37
 
38
/* Prototype for private function that gets the name of the slave
39
   pseudo terminal in a safe way.  */
40
static int pts_name (int fd, char **pts, size_t buf_len);
41
 
42
#endif
43
 
44
/* Change the ownership and access permission of the slave pseudo
45
   terminal associated with the master pseudo terminal specified
46
   by FD.  */
47
int
48
grantpt (int fd)
49
{
50
#if !defined __ASSUME_DEVPTS__
51
  struct statfs fsbuf;
52
# ifdef PATH_MAX
53
  char _buf[PATH_MAX];
54
# else
55
  char _buf[512];
56
# endif
57
  char *buf = _buf;
58
 
59
  if (pts_name (fd, &buf, sizeof (_buf)))
60
    return -1;
61
 
62
  if (statfs (buf, &fsbuf) < 0)
63
    return -1;
64
 
65
  /* If the slave pseudo terminal lives on a `devpts' filesystem, the
66
     ownership and access permission are already set.  */
67
  if (fsbuf.f_type != DEVPTS_SUPER_MAGIC && fsbuf.f_type != DEVFS_SUPER_MAGIC)
68
  return __unix_grantpt (fd);
69
#endif
70
  return 0;
71
}
72
 
73
#if !defined __ASSUME_DEVPTS__
74
# define grantpt __unix_grantpt
75
# include "unix_grantpt.c"
76
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.