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

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

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

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

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

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

198 bflags |= O_NDELAY;
199#endif
200
201 if (flags & bflags)
202 {
203 flags &= ~bflags;
204 return (fcntl (fd, F_SETFL, flags));
205 }
206#endif
207
208 return 0;
209}