source: rtems/cpukit/libcsupport/src/ttyname.c @ da154e14

4.115
Last change on this file since da154e14 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 1988, 1993
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34
35#if HAVE_CONFIG_H
36#include "config.h"
37#endif
38
39#ifndef HAVE_TTYNAME
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <fcntl.h>
44#include <dirent.h>
45#include <termios.h>
46#include <unistd.h>
47#include <string.h>
48#include <paths.h>
49#include <_syslist.h>
50#include <errno.h>
51
52#include <rtems/libio_.h>
53#include <rtems/seterr.h>
54
55static char ttyname_buf[sizeof (_PATH_DEV) + MAXNAMLEN];
56
57/*
58 *  ttyname_r() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name
59 */
60int ttyname_r(
61  int     fd,
62  char   *name,
63  size_t  namesize
64)
65{
66  struct stat sb;
67  struct termios tty;
68  struct dirent *dirp;
69  DIR *dp;
70  struct stat dsb;
71  char *rval;
72
73  /* Must be a terminal. */
74  if (tcgetattr (fd, &tty) < 0)
75    rtems_set_errno_and_return_minus_one(EBADF);
76
77  /* Must be a character device. */
78  if (fstat (fd, &sb) || !S_ISCHR (sb.st_mode))
79    rtems_set_errno_and_return_minus_one(EBADF);
80
81  if ((dp = opendir (_PATH_DEV)) == NULL)
82    rtems_set_errno_and_return_minus_one(EBADF);
83
84  /* Place the base directory in the path. */
85  strncpy (name, _PATH_DEV, namesize);
86
87  for (rval = NULL; (dirp = readdir (dp)) != NULL ;)
88    {
89      if (dirp->d_ino != sb.st_ino)
90        continue;
91      strcpy (name + sizeof (_PATH_DEV) - 1, dirp->d_name);
92      if (stat (name, &dsb) || sb.st_dev != dsb.st_dev ||
93          sb.st_ino != dsb.st_ino)
94        continue;
95      rval = name;
96      break;
97    }
98  (void) closedir (dp);
99  return 0;
100}
101
102/*
103 *  ttyname() - POSIX 1003.1b 4.7.2 - Determine Terminal Device Name
104 */
105
106char *ttyname(
107  int fd
108)
109{
110  if ( !ttyname_r( fd, ttyname_buf, sizeof(ttyname_buf) ) )
111    return ttyname_buf;
112  return NULL;
113}
114
115#endif
Note: See TracBrowser for help on using the repository browser.