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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [stdlib/] [getpt.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
   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Library General Public License as
7
   published by the Free Software Foundation; either version 2 of the
8
   License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Library General Public License for more details.
14
 
15
   You should have received a copy of the GNU Library General Public
16
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
17
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
   Boston, MA 02111-1307, USA.  */
19
 
20
#include <errno.h>
21
#include <fcntl.h>
22
#include <stdlib.h>
23
#include <unistd.h>
24
#include <paths.h>
25
 
26
#if !defined __ASSUME_DEVPTS__
27
# include <sys/statfs.h>
28
 
29
/* Constant that identifies the `devpts' filesystem.  */
30
# define DEVPTS_SUPER_MAGIC     0x1cd1
31
/* Constant that identifies the `devfs' filesystem.  */
32
# define DEVFS_SUPER_MAGIC      0x1373
33
#endif
34
 
35
/* Path to the master pseudo terminal cloning device.  */
36
#define _PATH_DEVPTMX _PATH_DEV "ptmx"
37
/* Directory containing the UNIX98 pseudo terminals.  */
38
#define _PATH_DEVPTS _PATH_DEV "pts"
39
 
40
#if !defined __UNIX98PTY_ONLY__
41
/* Prototype for function that opens BSD-style master pseudo-terminals.  */
42
int __bsd_getpt (void);
43
#endif
44
 
45
/* Open a master pseudo terminal and return its file descriptor.  */
46
int
47
getpt (void)
48
{
49
#if !defined __UNIX98PTY_ONLY__
50
  static int have_no_dev_ptmx;
51
#endif
52
  int fd;
53
 
54
#if !defined __UNIX98PTY_ONLY__
55
  if (!have_no_dev_ptmx)
56
#endif
57
    {
58
      fd = open (_PATH_DEVPTMX, O_RDWR);
59
      if (fd != -1)
60
        {
61
#if defined __ASSUME_DEVPTS__
62
          return fd;
63
#else
64
          struct statfs fsbuf;
65
          static int devpts_mounted;
66
 
67
          /* Check that the /dev/pts filesystem is mounted
68
             or if /dev is a devfs filesystem (this implies /dev/pts).  */
69
          if (devpts_mounted
70
              || (statfs (_PATH_DEVPTS, &fsbuf) == 0
71
                  && fsbuf.f_type == DEVPTS_SUPER_MAGIC)
72
              || (statfs (_PATH_DEV, &fsbuf) == 0
73
                  && fsbuf.f_type == DEVFS_SUPER_MAGIC))
74
            {
75
              /* Everything is ok.  */
76
              devpts_mounted = 1;
77
              return fd;
78
            }
79
 
80
          /* If /dev/pts is not mounted then the UNIX98 pseudo terminals
81
             are not usable.  */
82
          close (fd);
83
#if !defined __UNIX98PTY_ONLY__
84
          have_no_dev_ptmx = 1;
85
#endif
86
#endif
87
        }
88
      else
89
        {
90
#if !defined __UNIX98PTY_ONLY__
91
          if (errno == ENOENT || errno == ENODEV)
92
            have_no_dev_ptmx = 1;
93
          else
94
#endif
95
            return -1;
96
        }
97
    }
98
 
99
#if !defined __UNIX98PTY_ONLY__
100
  return __bsd_getpt ();
101
#endif
102
}
103
 
104
#if !defined __UNIX98PTY_ONLY__
105
# define PTYNAME1 "pqrstuvwxyzabcde";
106
# define PTYNAME2 "0123456789abcdef";
107
 
108
# define __getpt __bsd_getpt
109
# include "bsd_getpt.c"
110
#endif

powered by: WebSVN 2.1.0

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