Deleted Added
sdiff udiff text old ( 136758 ) new ( 157188 )
full compact
1/* $FreeBSD: head/contrib/libreadline/shell.c 136758 2004-10-21 20:02:02Z peter $ */
2
3/* shell.c -- readline utility functions that are normally provided by
4 bash when readline is linked as part of the shell. */
5
6/* Copyright (C) 1997 Free Software Foundation, Inc.
7
8 This file is part of the GNU Readline Library, a library for
9 reading lines of text with interactive input and history editing.
10

--- 34 unchanged lines hidden (view full) ---

45#else
46# include <strings.h>
47#endif /* !HAVE_STRING_H */
48
49#if defined (HAVE_LIMITS_H)
50# include <limits.h>
51#endif
52
53#include <fcntl.h>
54#include <pwd.h>
55
56#include <stdio.h>
57
58#include "rlstdc.h"
59#include "rlshell.h"
60#include "xmalloc.h"
61
62#if !defined (HAVE_GETPW_DECLS)
63extern struct passwd *getpwuid PARAMS((uid_t));
64#endif /* !HAVE_GETPW_DECLS */
65
66#ifndef NULL
67# define NULL 0
68#endif
69
70#ifndef CHAR_BIT
71# define CHAR_BIT 8
72#endif

--- 46 unchanged lines hidden (view full) ---

119/* Set the environment variables LINES and COLUMNS to lines and cols,
120 respectively. */
121void
122sh_set_lines_and_columns (lines, cols)
123 int lines, cols;
124{
125 char *b;
126
127#if defined (HAVE_PUTENV)
128 b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1);
129 sprintf (b, "LINES=%d", lines);
130 putenv (b);
131
132 b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1);
133 sprintf (b, "COLUMNS=%d", cols);
134 putenv (b);
135#else /* !HAVE_PUTENV */
136# if defined (HAVE_SETENV)
137 b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1);
138 sprintf (b, "%d", lines);
139 setenv ("LINES", b, 1);
140 free (b);
141
142 b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1);
143 sprintf (b, "%d", cols);
144 setenv ("COLUMNS", b, 1);
145 free (b);
146# endif /* HAVE_SETENV */
147#endif /* !HAVE_PUTENV */
148}
149
150char *
151sh_get_env_value (varname)
152 const char *varname;
153{
154 return ((char *)getenv (varname));
155}
156
157char *
158sh_get_home_dir ()
159{
160 char *home_dir;
161 struct passwd *entry;
162
163 home_dir = (char *)NULL;
164 entry = getpwuid (getuid ());
165 if (entry)
166 home_dir = entry->pw_dir;
167 return (home_dir);
168}
169
170#if !defined (O_NDELAY)
171# if defined (FNDELAY)
172# define O_NDELAY FNDELAY
173# endif
174#endif
175
176int
177sh_unset_nodelay_mode (fd)
178 int fd;
179{
180 int flags, bflags;
181
182 if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
183 return -1;
184
185 bflags = 0;
186
187#ifdef O_NONBLOCK

--- 4 unchanged lines hidden (view full) ---

192 bflags |= O_NDELAY;
193#endif
194
195 if (flags & bflags)
196 {
197 flags &= ~bflags;
198 return (fcntl (fd, F_SETFL, flags));
199 }
200
201 return 0;
202}