aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert2012-11-21 13:06:52 -0800
committerPaul Eggert2012-11-21 13:06:52 -0800
commit9239d970523919dfcf7437f728f4976b3a9467f3 (patch)
treeb9fd9fb6de02ad291a462a8387cb04d3972114e5 /src/sysdep.c
parent954bba56c62e4e0637a933cf21626a55b873e144 (diff)
downloademacs-9239d970523919dfcf7437f728f4976b3a9467f3.tar.gz
emacs-9239d970523919dfcf7437f728f4976b3a9467f3.zip
Assume POSIX 1003.1-1988 or later for unistd.h.
* admin/CPP-DEFINES (BROKEN_GETWD, HAVE_GETCWD, HAVE_GETWD, HAVE_SIZE_T) (HAVE_UNISTD_H): Remove. * configure.ac: Do not check for getcwd or getwd. * lib-src/emacsclient.c (getcwd): Remove decl. (get_current_dir_name): Assume getcwd exists. * lib-src/etags.c (HAVE_GETCWD): Remove. (getcwd): Remove decl. (NO_LONG_OPTIONS): Remove this. All uses removed. Emacs always has GNU getopt. (etags_getcwd): Assume getcwd exists. * lib-src/movemail.c (F_OK, X_OK, W_OK, R_OK): Remove. * nt/config.nt (HAVE_GETCWD): Remove. * src/alloc.c: Assume unistd.h exists. * src/fileio.c (Fexpand_file_name) [DOS_NT]: Use getcwd, not getwd. * src/sysdep.c (get_current_dir_name): Assume getcwd exists. (getwd) [USG]: Remove; no longer needed. (sys_subshell) [DOS_NT]: Use getcwd, not getwd. * src/w32.c (getcwd): Rename from getwd, and switch to getcwd's API. * src/w32.h (getcwd): Remove decl. Fixes: debbugs:12945
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c80
1 files changed, 4 insertions, 76 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 7c5c144fa8c..3dd19685540 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,60 +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. */ 2223/* Directory routines for systems that don't have them. */
2296 2224
2297#ifdef HAVE_DIRENT_H 2225#ifdef HAVE_DIRENT_H