aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c102
1 files changed, 4 insertions, 98 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 7c5c144fa8c..bc4dc91509f 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -101,7 +101,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
101#define _P_WAIT 0 101#define _P_WAIT 0
102int _cdecl _spawnlp (int, const char *, const char *, ...); 102int _cdecl _spawnlp (int, const char *, const char *, ...);
103int _cdecl _getpid (void); 103int _cdecl _getpid (void);
104extern char *getwd (char *);
105#endif 104#endif
106 105
107#include "syssignal.h" 106#include "syssignal.h"
@@ -134,12 +133,12 @@ char*
134get_current_dir_name (void) 133get_current_dir_name (void)
135{ 134{
136 char *buf; 135 char *buf;
137 char *pwd; 136 char *pwd = getenv ("PWD");
138 struct stat dotstat, pwdstat; 137 struct stat dotstat, pwdstat;
139 /* If PWD is accurate, use it instead of calling getwd. PWD is 138 /* If PWD is accurate, use it instead of calling getcwd. PWD is
140 sometimes a nicer name, and using it may avoid a fatal error if a 139 sometimes a nicer name, and using it may avoid a fatal error if a
141 parent directory is searchable but not readable. */ 140 parent directory is searchable but not readable. */
142 if ((pwd = getenv ("PWD")) != 0 141 if (pwd
143 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) 142 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
144 && stat (pwd, &pwdstat) == 0 143 && stat (pwd, &pwdstat) == 0
145 && stat (".", &dotstat) == 0 144 && stat (".", &dotstat) == 0
@@ -155,7 +154,6 @@ get_current_dir_name (void)
155 return NULL; 154 return NULL;
156 strcpy (buf, pwd); 155 strcpy (buf, pwd);
157 } 156 }
158#ifdef HAVE_GETCWD
159 else 157 else
160 { 158 {
161 size_t buf_size = 1024; 159 size_t buf_size = 1024;
@@ -179,22 +177,6 @@ get_current_dir_name (void)
179 return NULL; 177 return NULL;
180 } 178 }
181 } 179 }
182#else
183 else
184 {
185 /* We need MAXPATHLEN here. */
186 buf = malloc (MAXPATHLEN + 1);
187 if (!buf)
188 return NULL;
189 if (getwd (buf) == NULL)
190 {
191 int tmp_errno = errno;
192 free (buf);
193 errno = tmp_errno;
194 return NULL;
195 }
196 }
197#endif
198 return buf; 180 return buf;
199} 181}
200#endif 182#endif
@@ -521,7 +503,7 @@ sys_subshell (void)
521 const char *sh = 0; 503 const char *sh = 0;
522 504
523#ifdef DOS_NT /* MW, Aug 1993 */ 505#ifdef DOS_NT /* MW, Aug 1993 */
524 getwd (oldwd); 506 getcwd (oldwd, sizeof oldwd);
525 if (sh == 0) 507 if (sh == 0)
526 sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */ 508 sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
527#endif 509#endif
@@ -2238,82 +2220,6 @@ emacs_readlink (char const *filename, char initial_buf[READLINK_BUFSIZE])
2238 &emacs_norealloc_allocator, careadlinkatcwd); 2220 &emacs_norealloc_allocator, careadlinkatcwd);
2239} 2221}
2240 2222
2241#ifdef USG
2242/*
2243 * All of the following are for USG.
2244 *
2245 * On USG systems the system calls are INTERRUPTIBLE by signals
2246 * that the user program has elected to catch. Thus the system call
2247 * must be retried in these cases. To handle this without massive
2248 * changes in the source code, we remap the standard system call names
2249 * to names for our own functions in sysdep.c that do the system call
2250 * with retries. Actually, for portability reasons, it is good
2251 * programming practice, as this example shows, to limit all actual
2252 * system calls to a single occurrence in the source. Sure, this
2253 * adds an extra level of function call overhead but it is almost
2254 * always negligible. Fred Fish, Unisoft Systems Inc.
2255 */
2256
2257/*
2258 * Warning, this function may not duplicate 4.2 action properly
2259 * under error conditions.
2260 */
2261
2262#if !defined (HAVE_GETWD) || defined (BROKEN_GETWD)
2263
2264#ifndef MAXPATHLEN
2265/* In 4.1, param.h fails to define this. */
2266#define MAXPATHLEN 1024
2267#endif
2268
2269char *
2270getwd (char *pathname)
2271{
2272 char *npath, *spath;
2273 extern char *getcwd (char *, size_t);
2274
2275 block_input (); /* getcwd uses malloc */
2276 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
2277 if (spath == 0)
2278 {
2279 unblock_input ();
2280 return spath;
2281 }
2282 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2283 up to first slash. Should be harmless on other systems. */
2284 while (*npath && *npath != '/')
2285 npath++;
2286 strcpy (pathname, npath);
2287 free (spath); /* getcwd uses malloc */
2288 unblock_input ();
2289 return pathname;
2290}
2291
2292#endif /* !defined (HAVE_GETWD) || defined (BROKEN_GETWD) */
2293#endif /* USG */
2294
2295/* Directory routines for systems that don't have them. */
2296
2297#ifdef HAVE_DIRENT_H
2298
2299#include <dirent.h>
2300
2301#if !defined (HAVE_CLOSEDIR)
2302
2303int
2304closedir (DIR *dirp /* stream from opendir */)
2305{
2306 int rtnval;
2307
2308 rtnval = emacs_close (dirp->dd_fd);
2309 xfree (dirp);
2310
2311 return rtnval;
2312}
2313#endif /* not HAVE_CLOSEDIR */
2314#endif /* HAVE_DIRENT_H */
2315
2316
2317/* Return a struct timeval that is roughly equivalent to T. 2223/* Return a struct timeval that is roughly equivalent to T.
2318 Use the least timeval not less than T. 2224 Use the least timeval not less than T.
2319 Return an extremal value if the result would overflow. */ 2225 Return an extremal value if the result would overflow. */