* cygerrno.h: New file. Use this throughout whenever errno manipulation is

required.
* errno.cc: Use DWORD to hold Windows errors.
(geterrno_from_win_error): New function.
(seterrno_from_win_error): Use geterrno_from_win_error to convert supplied
windows error (suggested by Corinna Vinschen).
* path.cc (symlink_info): Add error element.
* path.cc (path_conv::check): Remove errno setting.  Use new symlink_info errno
element to set path_conv error, where appropriate.
(symlink_info::check): Set error element rather than attempting to manipulate
errno.  Add more checks for trailing / and /..  even though they are currently
useless.  Avoid setting EINVAL.
* path.cc (normalize_posix_path): Correct check for trailing /.
This commit is contained in:
Christopher Faylor 2000-08-22 03:58:47 +00:00
parent 6b85369f82
commit 9e2baf8dfa
45 changed files with 202 additions and 132 deletions

View File

@ -1,3 +1,22 @@
Mon Aug 21 23:49:05 2000 Christopher Faylor <cgf@cygnus.com>
* cygerrno.h: New file. Use this throughout whenever errno
manipulation is required.
* errno.cc: Use DWORD to hold Windows errors.
(geterrno_from_win_error): New function.
(seterrno_from_win_error): Use geterrno_from_win_error to convert
supplied windows error (suggested by Corinna Vinschen).
* path.cc (symlink_info): Add error element.
* path.cc (path_conv::check): Remove errno setting. Use new
symlink_info errno element to set path_conv error, where appropriate.
(symlink_info::check): Set error element rather than attempting to
manipulate errno. Add more checks for trailing / and /.. even though
they are currently useless. Avoid setting EINVAL.
Mon Aug 21 23:49:05 2000 Corinna Vinschen <corinna@vinschen.de>
* path.cc (normalize_posix_path): Correct check for trailing /.
2000-08-21 DJ Delorie <dj@redhat.com>
* include/cygwin/cygwin_dll.h (DECLARE_CYGWIN_DLL): hinstance,

34
winsup/cygwin/cygerrno.h Normal file
View File

@ -0,0 +1,34 @@
/* cygerrno.h: main Cygwin header file.
Copyright 2000 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
void __stdcall seterrno_from_win_error (const char *file, int line, DWORD code);
void __stdcall seterrno (const char *, int line);
int __stdcall geterrno_from_win_error (DWORD code, int deferrno);
#define __seterrno() seterrno (__FILE__, __LINE__)
#define __seterrno_from_win_error(val) seterrno_from_win_error (__FILE__, __LINE__, val)
#define set_errno(val) (_impure_ptr->_errno = (val))
#define get_errno() (_impure_ptr->_errno)
extern "C" void __stdcall set_sig_errno (int e);
class save_errno
{
int saved;
public:
save_errno () {saved = get_errno ();}
save_errno (int what) {saved = get_errno (); set_errno (what); }
void set (int what) {set_errno (what); saved = what;}
void reset () {saved = get_errno ();}
~save_errno () {set_errno (saved);}
};
extern const char *__sp_fn;
extern int __sp_ln;

View File

@ -18,6 +18,7 @@ details. */
#include <ctype.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
#define MAX_AT_FILE_LEVEL 10

View File

@ -14,6 +14,7 @@ details. */
#include <sys/stat.h>
#include <errno.h>
#include "pinfo.h"
#include "cygerrno.h"
#define _COMPILING_NEWLIB
#include "dirent.h"

View File

@ -10,6 +10,7 @@ details. */
#include <stdlib.h>
#include "exceptions.h"
#include "dll_init.h"
#include "cygerrno.h"
extern void __stdcall check_sanity_and_sync (per_process *);

View File

@ -22,6 +22,7 @@ details. */
#include <winsock.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
dtable fdtab;

View File

@ -14,6 +14,7 @@ details. */
#include <ctype.h>
#include <fcntl.h>
#include "pinfo.h"
#include "cygerrno.h"
extern BOOL allow_glob;
extern BOOL allow_ntea;

View File

@ -12,6 +12,7 @@ details. */
#define _REENT_ONLY
#include <stdio.h>
#include <errno.h>
#include "cygerrno.h"
/* Table to map Windows error codes to Errno values. */
/* FIXME: Doing things this way is a little slow. It's trivial to change
@ -21,7 +22,7 @@ details. */
static const struct
{
int w; /* windows version of error */
DWORD w; /* windows version of error */
const char *s; /* text of windows version */
int e; /* errno version of error */
}
@ -108,34 +109,33 @@ errmap[] =
{ 0, NULL, 0}
};
int __stdcall
geterrno_from_win_error (DWORD code, int deferrno)
{
for (int i = 0; errmap[i].w != 0; ++i)
if (code == errmap[i].w)
{
syscall_printf ("windows error %u == errno %d", code, errmap[i].e);
return errmap[i].e;
}
syscall_printf ("unknown windows error %u, setting errno to %d", code,
deferrno);
return deferrno; /* FIXME: what's so special about EACCESS? */
}
/* seterrno_from_win_error: Given a Windows error code, set errno
as appropriate. */
void
seterrno_from_win_error (const char *file, int line, int code)
void __stdcall
seterrno_from_win_error (const char *file, int line, DWORD code)
{
int i;
for (i = 0; errmap[i].w != 0; ++i)
if (code == errmap[i].w)
break;
if (errmap[i].w != 0)
{
if (strace.active)
strace.prntf (_STRACE_SYSCALL, NULL, "%s:%d seterrno: %d (%s) -> %d",
file, line, code, errmap[i].s, errmap[i].e);
set_errno (errmap[i].e);
}
else
{
if (strace.active)
strace.prntf (_STRACE_SYSCALL, NULL, "%s:%d seterrno: unknown error %d", file, line, code);
set_errno (EACCES);
}
syscall_printf ("%s:%d \b");
set_errno (geterrno_from_win_error (code, EACCES));
return;
}
/* seterrno: Set `errno' based on GetLastError (). */
void
void __stdcall
seterrno (const char *file, int line)
{
seterrno_from_win_error (file, line, GetLastError ());
@ -672,4 +672,3 @@ strerror (int errnum)
include files. */
return (char *) error;
}

View File

@ -16,6 +16,7 @@ details. */
#include "exceptions.h"
#include <imagehlp.h>
#include "pinfo.h"
#include "cygerrno.h"
char debugger_command[2 * MAX_PATH + 20];

View File

@ -14,6 +14,7 @@ details. */
#include <errno.h>
#include <unistd.h>
#include "dtable.h"
#include "cygerrno.h"
extern "C"
int

View File

@ -14,6 +14,7 @@ details. */
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "cygerrno.h"
static NO_COPY const int CHUNK_SIZE = 1024; /* Used for crlf conversions */

View File

@ -23,6 +23,7 @@ details. */
#include <winuser.h>
#include <ctype.h>
#include "pinfo.h"
#include "cygerrno.h"
/*
* Scroll the screen context.

View File

@ -13,6 +13,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include <limits.h>
#include "cygerrno.h"
#define RANDOM 8
#define URANDOM 9

View File

@ -16,6 +16,7 @@
#include <cygwin/rdevio.h>
#include <sys/mtio.h>
#include "cygerrno.h"
/* static wrapper functions to hide the effect of media changes and
bus resets which occurs after a new media is inserted. This is

View File

@ -14,6 +14,7 @@ details. */
#include <unistd.h>
#include <stdlib.h>
#include "pinfo.h"
#include "cygerrno.h"
/**********************************************************************/
/* fhandler_serial */

View File

@ -16,6 +16,7 @@ details. */
#include <unistd.h>
#include <sys/mtio.h>
#include "cygerrno.h"
/**********************************************************************/
/* fhandler_dev_tape */

View File

@ -15,6 +15,7 @@ details. */
#include <errno.h>
#include <ctype.h>
#include "pinfo.h"
#include "cygerrno.h"
/* Common functions shared by tty/console */

View File

@ -18,6 +18,7 @@ details. */
#include <limits.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
/* Tty master stuff */

View File

@ -15,6 +15,7 @@ details. */
#include <errno.h>
#include <wingdi.h>
#include <winuser.h>
#include "cygerrno.h"
/*
The following unix-style calls are supported:

View File

@ -18,6 +18,7 @@ details. */
#include "dll_init.h"
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
DWORD NO_COPY chunksize = 0;
/* Timeout to wait for child to start, parent to init child, etc. */

View File

@ -11,6 +11,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include "pinfo.h"
#include "cygerrno.h"
#define brksize ((char *) user_data->heaptop - (char *) user_data->heapbase)
#define brk (user_data->heapptr)

View File

@ -15,6 +15,7 @@ details. */
#include <sys/ioctl.h>
#include <errno.h>
#include "dtable.h"
#include "cygerrno.h"
extern "C"
int

View File

@ -15,6 +15,7 @@ details. */
#include <errno.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
/*
* Simple class used to keep a record of all current

View File

@ -25,6 +25,7 @@ details. */
#include <winsock.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
/* We only want to initialize WinSock in a child process if socket
handles are inheritted. This global allows us to know whether this

View File

@ -15,6 +15,7 @@ details. */
#include <errno.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
/* Read /etc/passwd only once for better performance. This is done
on the first call that needs information from it. */

View File

@ -82,6 +82,7 @@ details. */
#include <ctype.h>
#include <winioctl.h>
#include "pinfo.h"
#include "cygerrno.h"
static int normalize_win32_path (const char *cwd, const char *src, char *dst);
static char *getcwd_inner (char *buf, size_t ulen, int posix_p, int with_chroot);
@ -101,6 +102,7 @@ struct symlink_info
unsigned pflags;
DWORD fileattr;
int is_symlink;
int error;
symlink_info (): known_suffix (NULL), contents (buf + MAX_PATH + 1) {}
int check (const char *path, const suffix_info *suffixes);
};
@ -154,9 +156,9 @@ static unsigned long cwd_hash;
#endif
#define ischrootpath(path) \
(myself->rootlen && \
strncasematch (myself->root, path, myself->rootlen) && \
(path[myself->rootlen] == '/' || path[myself->rootlen] == '\0'))
(myself->rootlen && \
strncasematch (myself->root, path, myself->rootlen) && \
(path[myself->rootlen] == '/' || path[myself->rootlen] == '\0'))
static int
path_prefix_p_ (const char *path1, const char *path2, int len1)
@ -224,7 +226,7 @@ path_conv::check (const char *src, unsigned opt,
full_path,
devn, unit, &path_flags);
MALLOC_CHECK;
if (error != 0)
if (error)
return;
if (devn != FH_BAD)
{
@ -265,9 +267,8 @@ path_conv::check (const char *src, unsigned opt,
for (;;)
{
save_errno s (0);
const suffix_info *suff;
/* Don't allow symlink.check to set anything in the path_conv
class if we're working on an inner component of the path */
if (component)
@ -287,10 +288,11 @@ path_conv::check (const char *src, unsigned opt,
path_flags = sym.pflags;
/* If symlink.check found an existing non-symlink file, then
it returns a length of 0 and sets errno to EINVAL. It also sets
any suffix found into `ext_here'. */
it sets the appropriate flag. It also sets any suffix found
into `ext_here'. */
if (!sym.is_symlink && sym.fileattr != (DWORD) -1)
{
error = sym.error;
if (component == 0)
{
fileattr = sym.fileattr;
@ -317,11 +319,10 @@ path_conv::check (const char *src, unsigned opt,
}
/* No existing file found. */
s.reset (); // remember errno from symlink.check
if (!(tail = strrchr (path_copy, '\\')) ||
(tail > path_copy && tail[-1] == ':'))
goto out; // all done
goto out; // all done
/* Haven't found a valid pathname component yet.
Pinch off the tail and try again. */
@ -392,13 +393,13 @@ out:
!GetVolumeInformation (tmp_buf, NULL, 0, &serial, NULL, &volflags, NULL, 0))
{
debug_printf ("GetVolumeInformation(%s) = ERR, full_path(%s), set_has_acls(FALSE)",
tmp_buf, full_path, GetLastError ());
tmp_buf, full_path, GetLastError ());
set_has_acls (FALSE);
}
else
{
debug_printf ("GetVolumeInformation(%s) = OK, full_path(%s), set_has_acls(%d)",
tmp_buf, full_path, volflags & FS_PERSISTENT_ACLS);
tmp_buf, full_path, volflags & FS_PERSISTENT_ACLS);
set_has_acls (volflags & FS_PERSISTENT_ACLS);
}
}
@ -504,10 +505,10 @@ get_device_number (const char *name, int &unit, BOOL from_conv)
else if (deveq ("zero"))
devn = FH_ZERO;
else if (deveq ("random") || deveq ("urandom"))
{
{
devn = FH_RANDOM;
unit = 8 + (deveqn ("u", 1) ? 1 : 0); /* Keep unit Linux conformant */
}
unit = 8 + (deveqn ("u", 1) ? 1 : 0); /* Keep unit Linux conformant */
}
else if (deveqn ("com", 3) && (unit = digits (name + 3)) >= 0)
devn = FH_SERIAL;
else if (deveq ("pipe") || deveq ("piper") || deveq ("pipew"))
@ -591,10 +592,10 @@ normalize_posix_path (const char *cwd, const char *src, char *dst)
else if (isslash (src[1]))
{
if (myself->rootlen)
{
{
debug_printf ("ENOENT = normalize_posix_path (%s)", src);
return ENOENT;
}
}
*dst++ = '/';
*dst++ = '/';
src += 2;
@ -630,16 +631,16 @@ normalize_posix_path (const char *cwd, const char *src, char *dst)
sawdot:
if (src[1] != '.')
{
if ((src[1] && !isslash (src[1])))
if (!src[1] || !isslash (src[1]))
break;
}
else
{
if (src[2] && !isslash (src[2]))
break;
if (!ischrootpath (dst_start) ||
dst - dst_start != (int) myself->rootlen)
while (dst > dst_start && !isslash (*--dst))
if (!ischrootpath (dst_start) ||
dst - dst_start != (int) myself->rootlen)
while (dst > dst_start && !isslash (*--dst))
continue;
src++;
}
@ -686,10 +687,10 @@ normalize_win32_path (const char *cwd, const char *src, char *dst)
else if (SLASH_P (src[0]) && SLASH_P (src[1]))
{
if (myself->rootlen)
{
{
debug_printf ("ENOENT = normalize_win32_path (%s)", src);
return ENOENT;
}
}
*dst++ = '\\';
++src;
}
@ -699,7 +700,7 @@ normalize_win32_path (const char *cwd, const char *src, char *dst)
strcpy (dst, myself->root);
char *c;
while ((c = strchr (dst, '/')) != NULL)
*c = '\\';
*c = '\\';
dst += myself->rootlen;
dst_root_start = dst;
*dst++ = '\\';
@ -913,7 +914,7 @@ mount_info::init ()
int
mount_info::conv_to_win32_path (const char *src_path, char *win32_path,
char *full_win32_path, DWORD &devn, int &unit,
unsigned *flags)
unsigned *flags)
{
int src_path_len = strlen (src_path);
int trailing_slash_p = (src_path_len > 1
@ -968,21 +969,21 @@ mount_info::conv_to_win32_path (const char *src_path, char *win32_path,
isrelpath = !isabspath (src_path);
*flags = set_flags_from_win32_path (dst);
if (myself->rootlen && dst[0] && dst[1] == ':')
{
char posix_path[MAX_PATH + 1];
{
char posix_path[MAX_PATH + 1];
rc = cygwin_shared->mount.conv_to_posix_path (dst, posix_path, 0);
if (rc)
{
debug_printf ("conv_to_posix_path failed, rc %d", rc);
return rc;
}
if (!ischrootpath (posix_path))
{
debug_printf ("ischrootpath failed");
return ENOENT;
}
}
rc = cygwin_shared->mount.conv_to_posix_path (dst, posix_path, 0);
if (rc)
{
debug_printf ("conv_to_posix_path failed, rc %d", rc);
return rc;
}
if (!ischrootpath (posix_path))
{
debug_printf ("ischrootpath failed");
return ENOENT;
}
}
goto fillin;
}
@ -1185,7 +1186,7 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
const char *lastchar = src_path + src_path_len - 1;
trailing_slash_p = SLASH_P (*lastchar) && lastchar[-1] != ':';
}
debug_printf ("conv_to_posix_path (%s, %s, %s)", src_path,
keep_rel_p ? "keep-rel" : "no-keep-rel",
trailing_slash_p ? "add-slash" : "no-add-slash");
@ -1459,13 +1460,13 @@ mount_info::del_reg_mount (const char * posix_path, unsigned flags)
{
int killres;
if ((flags & MOUNT_SYSTEM) == 0) /* Delete from user registry */
if ((flags & MOUNT_SYSTEM) == 0) /* Delete from user registry */
{
reg_key reg_user (KEY_ALL_ACCESS,
CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
killres = reg_user.kill (posix_path);
}
else /* Delete from system registry */
else /* Delete from system registry */
{
reg_key reg_sys (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, "SOFTWARE",
CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
@ -1514,23 +1515,23 @@ mount_info::read_cygdrive_info_from_registry ()
if (r2.get_string ("cygdrive prefix", cygdrive, sizeof (cygdrive), "") != 0)
{
/* Didn't find either so write the default to the registry and use it.
/* Didn't find either so write the default to the registry and use it.
NOTE: We are writing and using the user path prefix. */
write_cygdrive_info_to_registry ("/cygdrive", MOUNT_AUTO);
write_cygdrive_info_to_registry ("/cygdrive", MOUNT_AUTO);
}
else
{
/* Fetch system cygdrive_flags from registry; returns MOUNT_AUTO on
/* Fetch system cygdrive_flags from registry; returns MOUNT_AUTO on
error. */
cygdrive_flags = r2.get_int ("cygdrive flags", MOUNT_AUTO);
slashify (cygdrive, cygdrive, 1);
cygdrive_len = strlen(cygdrive);
cygdrive_flags = r2.get_int ("cygdrive flags", MOUNT_AUTO);
slashify (cygdrive, cygdrive, 1);
cygdrive_len = strlen(cygdrive);
}
}
else
{
/* Fetch user cygdrive_flags from registry; returns MOUNT_AUTO on
error. */
error. */
cygdrive_flags = r.get_int ("cygdrive flags", MOUNT_AUTO);
slashify (cygdrive, cygdrive, 1);
cygdrive_len = strlen(cygdrive);
@ -1959,12 +1960,12 @@ mount_item::getmntent ()
strcpy (cygwin_shared->mount.mnt_dir, posix_path);
ret.mnt_dir = cygwin_shared->mount.mnt_dir;
if (!(flags & MOUNT_SYSTEM)) /* user mount */
if (!(flags & MOUNT_SYSTEM)) /* user mount */
strcpy (cygwin_shared->mount.mnt_type, (char *) "user");
else /* system mount */
else /* system mount */
strcpy (cygwin_shared->mount.mnt_type, (char *) "system");
if ((flags & MOUNT_AUTO)) /* cygdrive */
if ((flags & MOUNT_AUTO)) /* cygdrive */
strcat (cygwin_shared->mount.mnt_type, (char *) ",auto");
ret.mnt_type = cygwin_shared->mount.mnt_type;
@ -2068,7 +2069,7 @@ cygwin_umount (const char *path, unsigned flags)
if (flags & MOUNT_AUTO)
{
/* When flags include MOUNT_AUTO, take this to mean that we actually want
to remove the cygdrive prefix and flags without actually unmounting
to remove the cygdrive prefix and flags without actually unmounting
anything. */
res = cygwin_shared->mount.remove_cygdrive_info_from_registry (path, flags);
}
@ -2169,10 +2170,10 @@ symlink (const char *topath, const char *frompath)
else
{
CloseHandle (h);
set_file_attribute (win32_path.has_acls (),
win32_path.get_win32 (),
S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO);
SetFileAttributesA (win32_path.get_win32 (), FILE_ATTRIBUTE_SYSTEM);
set_file_attribute (win32_path.has_acls (),
win32_path.get_win32 (),
S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO);
SetFileAttributesA (win32_path.get_win32 (), FILE_ATTRIBUTE_SYSTEM);
res = 0;
}
}
@ -2236,6 +2237,7 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
char extbuf[MAX_PATH + 5];
const char *path = in_path;
error = 0;
if (!suffixes)
ext_here = NULL;
else if ((known_suffix = has_suffix (in_path, suffixes)) != NULL)
@ -2262,19 +2264,23 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
matter, so we just return 0. For example, getting the
attributes of \\HOST will typically fail. */
debug_printf ("GetFileAttributesA (%s) failed", path);
__seterrno ();
error = geterrno_from_win_error (GetLastError (), EACCES);
continue;
}
/* Windows allows path\. even when `path' isn't a directory.
Detect this scenario and disallow it, since it is non-UNIX like. */
char *p = strchr (path, '\0');
if (p > path + 1 && p[-1] == '.' && SLASH_P (p[-2]) &&
!(fileattr & FILE_ATTRIBUTE_DIRECTORY))
Detect this scenario and disallow it, since it is non-UNIX like.
FIXME: This code actually checks for things like foo/ and foo/..
even though those usages have already been (erroneously?) eaten
by cygwin_shared->mount.conv_to_win32_path in path_conv::check. */
char *p = strrchr (path, '\\');
if (p && !(fileattr & FILE_ATTRIBUTE_DIRECTORY) &&
(*++p == '\0' || (*p == '.' && (*++p == '\0' || (*p == '.' && p[1] == '\0')))))
{
debug_printf ("\\. specified on non-directory");
set_errno (ENOTDIR);
return 0;
debug_printf ("%s is a non-directory", path);
error = ENOTDIR;
goto file_not_symlink;
}
/* A symlink will have the `system' file attribute. */
@ -2295,7 +2301,7 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
DWORD got;
if (! ReadFile (h, cookie_buf, sizeof (cookie_buf), &got, 0))
set_errno (EIO);
error = EIO;
else if (got == sizeof (cookie_buf)
&& memcmp (cookie_buf, SYMLINK_COOKIE,
sizeof (cookie_buf)) == 0)
@ -2305,7 +2311,7 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
res = ReadFile (h, contents, MAX_PATH + 1, &got, 0);
if (!res)
set_errno (EIO);
error = EIO;
else
{
/* Versions prior to b16 stored several trailing
@ -2347,7 +2353,6 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
goto out;
file_not_symlink:
set_errno (EINVAL);
is_symlink = FALSE;
syscall_printf ("not a symlink");
res = 0;
@ -2516,12 +2521,12 @@ getcwd_inner (char *buf, size_t ulen, int posix_p, int with_chroot)
if (strlen (cwd_posix) >= len)
set_errno (ERANGE);
else if (with_chroot && ischrootpath(cwd_posix))
{
strcpy (buf, cwd_posix + myself->rootlen);
if (!buf[0])
strcpy (buf, "/");
resbuf = buf;
}
{
strcpy (buf, cwd_posix + myself->rootlen);
if (!buf[0])
strcpy (buf, "/");
resbuf = buf;
}
else
{
strcpy (buf, cwd_posix);
@ -2550,9 +2555,9 @@ getcwd_inner (char *buf, size_t ulen, int posix_p, int with_chroot)
if (cwd_posix != NULL)
if (with_chroot && ischrootpath (temp))
{
strcpy (cwd_posix, temp + myself->rootlen);
if (!buf[0])
strcpy (buf, "/");
strcpy (cwd_posix, temp + myself->rootlen);
if (!buf[0])
strcpy (buf, "/");
}
else
strcpy (cwd_posix, temp);
@ -2639,12 +2644,12 @@ chdir (const char *dir)
char pathbuf[MAX_PATH];
(void) normalize_posix_path (cwd_posix, dir, pathbuf);
/* Look for trailing path component consisting entirely of dots. This
is needed only in case of chdir since Windows simply ignores count
of dots > 2 here instead of returning an error code. Counts of dots
<= 2 are already eliminated by normalize_posix_path. */
is needed only in case of chdir since Windows simply ignores count
of dots > 2 here instead of returning an error code. Counts of dots
<= 2 are already eliminated by normalize_posix_path. */
char *last_slash = strrchr (pathbuf, '/');
if (last_slash > pathbuf && strspn (last_slash + 1, ".") == strlen (last_slash + 1))
*last_slash = '\0';
*last_slash = '\0';
free (cwd_posix);
cwd_posix = strdup (pathbuf);
}

View File

@ -15,6 +15,7 @@ details. */
#include <limits.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
static char NO_COPY pinfo_dummy[sizeof(pinfo)] = {0};

View File

@ -13,6 +13,7 @@ details. */
#include <sys/fcntl.h>
#include <errno.h>
#include "dtable.h"
#include "cygerrno.h"
static int
make_pipe (int fildes[2], unsigned int psize, int mode)

View File

@ -12,6 +12,7 @@
#include <sys/poll.h>
#include <errno.h>
#include "dtable.h"
#include "cygerrno.h"
extern "C"
int

View File

@ -15,6 +15,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include "pinfo.h"
#include "cygerrno.h"
/* add timeval values */
static void

View File

@ -14,6 +14,7 @@
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
#include "cygerrno.h"
extern "C"
int

View File

@ -24,6 +24,7 @@ details. */
#include <ctype.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
extern BOOL allow_ntea;
BOOL allow_ntsec = FALSE;

View File

@ -34,6 +34,7 @@ details. */
#include <winsock.h>
#include "select.h"
#include "dtable.h"
#include "cygerrno.h"
/*
* All these defines below should be in sys/types.h

View File

@ -14,6 +14,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include "pinfo.h"
#include "cygerrno.h"
extern "C"
_sig_func_ptr

View File

@ -17,6 +17,7 @@ details. */
#include <errno.h>
#include <stdlib.h>
#include "pinfo.h"
#include "cygerrno.h"
extern BOOL allow_ntsec;

View File

@ -22,6 +22,7 @@ details. */
#include <paths.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
extern BOOL allow_ntsec;

View File

@ -26,6 +26,7 @@ details. */
#include <lmcons.h> /* for UNLEN */
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
extern BOOL allow_ntsec;

View File

@ -14,6 +14,7 @@ details. */
#include <time.h>
#include <limits.h>
#include "dtable.h"
#include "cygerrno.h"
/* sysconf: POSIX 4.8.1.1 */
/* Allows a portable app to determine quantities of resources or

View File

@ -15,6 +15,7 @@ details. */
#include <stdarg.h>
#include <unistd.h>
#include "dtable.h"
#include "cygerrno.h"
/* FIXME: These should probably be in the registry. */
/* FIXME: The Win95 path should be whatever slash is */

View File

@ -14,6 +14,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include "dtable.h"
#include "cygerrno.h"
/* tcsendbreak: POSIX 7.2.2.1 */
extern "C"

View File

@ -17,6 +17,7 @@ details. */
#include <stdlib.h>
#include <errno.h>
#include "pinfo.h"
#include "cygerrno.h"
#define FACTOR (0x19db1ded53ea710LL)
#define NSPERSEC 10000000LL

View File

@ -16,6 +16,7 @@ details. */
#include <winuser.h>
#include "dtable.h"
#include "pinfo.h"
#include "cygerrno.h"
extern fhandler_tty_master *tty_master;

View File

@ -12,6 +12,7 @@ details. */
#include <sys/wait.h>
#include <stdlib.h>
#include <errno.h>
#include "cygerrno.h"
/* This is called _wait and not wait because the real wait is defined
in libc/syscalls/syswait.c. It calls us. */

View File

@ -17,6 +17,7 @@ details. */
#include <limits.h>
#include <wingdi.h>
#include <winuser.h>
#include "cygerrno.h"
static NO_COPY UINT timer_active = 0;
static NO_COPY struct itimerval itv;

View File

@ -466,31 +466,4 @@ extern "C" char __stdcall **cur_environ ();
extern char *old_title;
extern BOOL display_title;
/*************************** errno manipulation ******************************/
void seterrno_from_win_error (const char *file, int line, int code);
void seterrno (const char *, int line);
#define __seterrno() seterrno (__FILE__, __LINE__)
#define __seterrno_from_win_error(val) seterrno_from_win_error (__FILE__, __LINE__, val)
#define set_errno(val) (_impure_ptr->_errno = (val))
#define get_errno() (_impure_ptr->_errno)
extern "C" void __stdcall set_sig_errno (int e);
class save_errno
{
int saved;
public:
save_errno () {saved = get_errno ();}
save_errno (int what) {saved = get_errno (); set_errno (what); }
void set (int what) {set_errno (what); saved = what;}
void reset () {saved = get_errno ();}
~save_errno () {set_errno (saved);}
};
extern const char *__sp_fn;
extern int __sp_ln;
#endif /* defined __cplusplus */