Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog19
-rw-r--r--winsup/cygwin/cygerrno.h34
-rw-r--r--winsup/cygwin/dcrt0.cc1
-rw-r--r--winsup/cygwin/dir.cc1
-rw-r--r--winsup/cygwin/dll_init.cc1
-rw-r--r--winsup/cygwin/dtable.cc1
-rw-r--r--winsup/cygwin/environ.cc1
-rw-r--r--winsup/cygwin/errno.cc47
-rw-r--r--winsup/cygwin/exceptions.cc1
-rw-r--r--winsup/cygwin/fcntl.cc1
-rw-r--r--winsup/cygwin/fhandler.cc1
-rw-r--r--winsup/cygwin/fhandler_console.cc1
-rw-r--r--winsup/cygwin/fhandler_random.cc1
-rw-r--r--winsup/cygwin/fhandler_raw.cc1
-rw-r--r--winsup/cygwin/fhandler_serial.cc1
-rw-r--r--winsup/cygwin/fhandler_tape.cc1
-rw-r--r--winsup/cygwin/fhandler_termios.cc1
-rw-r--r--winsup/cygwin/fhandler_tty.cc1
-rw-r--r--winsup/cygwin/fhandler_windows.cc1
-rw-r--r--winsup/cygwin/fork.cc1
-rw-r--r--winsup/cygwin/heap.cc1
-rw-r--r--winsup/cygwin/ioctl.cc1
-rw-r--r--winsup/cygwin/mmap.cc1
-rw-r--r--winsup/cygwin/net.cc1
-rw-r--r--winsup/cygwin/passwd.cc1
-rw-r--r--winsup/cygwin/path.cc169
-rw-r--r--winsup/cygwin/pinfo.cc1
-rw-r--r--winsup/cygwin/pipe.cc1
-rw-r--r--winsup/cygwin/poll.cc1
-rw-r--r--winsup/cygwin/resource.cc1
-rw-r--r--winsup/cygwin/scandir.cc1
-rw-r--r--winsup/cygwin/security.cc1
-rw-r--r--winsup/cygwin/select.cc1
-rw-r--r--winsup/cygwin/signal.cc1
-rw-r--r--winsup/cygwin/sigproc.cc1
-rw-r--r--winsup/cygwin/spawn.cc1
-rw-r--r--winsup/cygwin/syscalls.cc1
-rw-r--r--winsup/cygwin/sysconf.cc1
-rw-r--r--winsup/cygwin/syslog.cc1
-rw-r--r--winsup/cygwin/termios.cc1
-rw-r--r--winsup/cygwin/times.cc1
-rw-r--r--winsup/cygwin/tty.cc1
-rw-r--r--winsup/cygwin/wait.cc1
-rw-r--r--winsup/cygwin/window.cc1
-rw-r--r--winsup/cygwin/winsup.h27
45 files changed, 203 insertions, 133 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 03dccdffc..1d3217ea3 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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,
diff --git a/winsup/cygwin/cygerrno.h b/winsup/cygwin/cygerrno.h
new file mode 100644
index 000000000..c83120095
--- /dev/null
+++ b/winsup/cygwin/cygerrno.h
@@ -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;
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index e14447ab5..f6b2bfc1d 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -18,6 +18,7 @@ details. */
#include <ctype.h>
#include "dtable.h"
#include "pinfo.h"
+#include "cygerrno.h"
#define MAX_AT_FILE_LEVEL 10
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index 07d0e34ca..612d9e015 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -14,6 +14,7 @@ details. */
#include <sys/stat.h>
#include <errno.h>
#include "pinfo.h"
+#include "cygerrno.h"
#define _COMPILING_NEWLIB
#include "dirent.h"
diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc
index 1cbc2ce82..e7a552670 100644
--- a/winsup/cygwin/dll_init.cc
+++ b/winsup/cygwin/dll_init.cc
@@ -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 *);
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 9f0c2a047..c405d9208 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -22,6 +22,7 @@ details. */
#include <winsock.h>
#include "dtable.h"
#include "pinfo.h"
+#include "cygerrno.h"
dtable fdtab;
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index dfb53a82c..7ae95b54e 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -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;
diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
index 1485c1906..25dcf705c 100644
--- a/winsup/cygwin/errno.cc
+++ b/winsup/cygwin/errno.cc
@@ -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}
};
-/* 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)
+int __stdcall
+geterrno_from_win_error (DWORD code, int deferrno)
{
- int i;
-
- for (i = 0; errmap[i].w != 0; ++i)
+ for (int i = 0; errmap[i].w != 0; ++i)
if (code == errmap[i].w)
- break;
+ {
+ syscall_printf ("windows error %u == errno %d", code, errmap[i].e);
+ return errmap[i].e;
+ }
- 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 ("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 __stdcall
+seterrno_from_win_error (const char *file, int line, DWORD code)
+{
+ 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;
}
-
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 52e333cdf..39ae079bc 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -16,6 +16,7 @@ details. */
#include "exceptions.h"
#include <imagehlp.h>
#include "pinfo.h"
+#include "cygerrno.h"
char debugger_command[2 * MAX_PATH + 20];
diff --git a/winsup/cygwin/fcntl.cc b/winsup/cygwin/fcntl.cc
index 6f64bd941..da7391199 100644
--- a/winsup/cygwin/fcntl.cc
+++ b/winsup/cygwin/fcntl.cc
@@ -14,6 +14,7 @@ details. */
#include <errno.h>
#include <unistd.h>
#include "dtable.h"
+#include "cygerrno.h"
extern "C"
int
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 5e84dd57e..4b620953e 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -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 */
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 7388dda06..92e695bb6 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -23,6 +23,7 @@ details. */
#include <winuser.h>
#include <ctype.h>
#include "pinfo.h"
+#include "cygerrno.h"
/*
* Scroll the screen context.
diff --git a/winsup/cygwin/fhandler_random.cc b/winsup/cygwin/fhandler_random.cc
index a577c4846..2c364b241 100644
--- a/winsup/cygwin/fhandler_random.cc
+++ b/winsup/cygwin/fhandler_random.cc
@@ -13,6 +13,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include <limits.h>
+#include "cygerrno.h"
#define RANDOM 8
#define URANDOM 9
diff --git a/winsup/cygwin/fhandler_raw.cc b/winsup/cygwin/fhandler_raw.cc
index 579fe1dfc..7a2e97b25 100644
--- a/winsup/cygwin/fhandler_raw.cc
+++ b/winsup/cygwin/fhandler_raw.cc
@@ -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
diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc
index 80f090426..45114865c 100644
--- a/winsup/cygwin/fhandler_serial.cc
+++ b/winsup/cygwin/fhandler_serial.cc
@@ -14,6 +14,7 @@ details. */
#include <unistd.h>
#include <stdlib.h>
#include "pinfo.h"
+#include "cygerrno.h"
/**********************************************************************/
/* fhandler_serial */
diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc
index 4860faeb1..03dd485f8 100644
--- a/winsup/cygwin/fhandler_tape.cc
+++ b/winsup/cygwin/fhandler_tape.cc
@@ -16,6 +16,7 @@ details. */
#include <unistd.h>
#include <sys/mtio.h>
+#include "cygerrno.h"
/**********************************************************************/
/* fhandler_dev_tape */
diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc
index 3e3b5b66e..e154e29a4 100644
--- a/winsup/cygwin/fhandler_termios.cc
+++ b/winsup/cygwin/fhandler_termios.cc
@@ -15,6 +15,7 @@ details. */
#include <errno.h>
#include <ctype.h>
#include "pinfo.h"
+#include "cygerrno.h"
/* Common functions shared by tty/console */
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 2ada539be..1b0bb390d 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -18,6 +18,7 @@ details. */
#include <limits.h>
#include "dtable.h"
#include "pinfo.h"
+#include "cygerrno.h"
/* Tty master stuff */
diff --git a/winsup/cygwin/fhandler_windows.cc b/winsup/cygwin/fhandler_windows.cc
index 7d63344e7..5b1e2859e 100644
--- a/winsup/cygwin/fhandler_windows.cc
+++ b/winsup/cygwin/fhandler_windows.cc
@@ -15,6 +15,7 @@ details. */
#include <errno.h>
#include <wingdi.h>
#include <winuser.h>
+#include "cygerrno.h"
/*
The following unix-style calls are supported:
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 6181b2442..d9bc5d98d 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -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. */
diff --git a/winsup/cygwin/heap.cc b/winsup/cygwin/heap.cc
index 53bace4af..fdc436710 100644
--- a/winsup/cygwin/heap.cc
+++ b/winsup/cygwin/heap.cc
@@ -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)
diff --git a/winsup/cygwin/ioctl.cc b/winsup/cygwin/ioctl.cc
index e232ae3d3..860ad6efb 100644
--- a/winsup/cygwin/ioctl.cc
+++ b/winsup/cygwin/ioctl.cc
@@ -15,6 +15,7 @@ details. */
#include <sys/ioctl.h>
#include <errno.h>
#include "dtable.h"
+#include "cygerrno.h"
extern "C"
int
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index bef6b4bb7..9afcd8c2c 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -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
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index e0b5a0854..e8217b31e 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -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
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index d5f8b1551..8dfa33053 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -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. */
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 8ab7316ca..94da12594 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -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];
-
- 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;
- }
- }
+ {
+ 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;
+ }
+ }
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);
}
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 49ef4991a..8316bd2e3 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -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};
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index c001c55cd..091548a05 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -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)
diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc
index 24b097dce..0ecf15268 100644
--- a/winsup/cygwin/poll.cc
+++ b/winsup/cygwin/poll.cc
@@ -12,6 +12,7 @@
#include <sys/poll.h>
#include <errno.h>
#include "dtable.h"
+#include "cygerrno.h"
extern "C"
int
diff --git a/winsup/cygwin/resource.cc b/winsup/cygwin/resource.cc
index 330e147e3..5a3241fc5 100644
--- a/winsup/cygwin/resource.cc
+++ b/winsup/cygwin/resource.cc
@@ -15,6 +15,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include "pinfo.h"
+#include "cygerrno.h"
/* add timeval values */
static void
diff --git a/winsup/cygwin/scandir.cc b/winsup/cygwin/scandir.cc
index 0f2bfd07e..ce9f46513 100644
--- a/winsup/cygwin/scandir.cc
+++ b/winsup/cygwin/scandir.cc
@@ -14,6 +14,7 @@
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
+#include "cygerrno.h"
extern "C"
int
diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc
index 98bf59c47..6766007d4 100644
--- a/winsup/cygwin/security.cc
+++ b/winsup/cygwin/security.cc
@@ -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;
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 8c630ee7a..5f427d43e 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -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
diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc
index 5695b4db4..94cd2cf23 100644
--- a/winsup/cygwin/signal.cc
+++ b/winsup/cygwin/signal.cc
@@ -14,6 +14,7 @@ details. */
#include "winsup.h"
#include <errno.h>
#include "pinfo.h"
+#include "cygerrno.h"
extern "C"
_sig_func_ptr
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 1bd9bcda4..a1d9ad38c 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -17,6 +17,7 @@ details. */
#include <errno.h>
#include <stdlib.h>
#include "pinfo.h"
+#include "cygerrno.h"
extern BOOL allow_ntsec;
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 6ac71e1b7..409572760 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -22,6 +22,7 @@ details. */
#include <paths.h>
#include "dtable.h"
#include "pinfo.h"
+#include "cygerrno.h"
extern BOOL allow_ntsec;
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 4acec27bf..114b768fb 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -26,6 +26,7 @@ details. */
#include <lmcons.h> /* for UNLEN */
#include "dtable.h"
#include "pinfo.h"
+#include "cygerrno.h"
extern BOOL allow_ntsec;
diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc
index 05131d9a1..25f8370ab 100644
--- a/winsup/cygwin/sysconf.cc
+++ b/winsup/cygwin/sysconf.cc
@@ -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
diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc
index b0c4789de..3a7926901 100644
--- a/winsup/cygwin/syslog.cc
+++ b/winsup/cygwin/syslog.cc
@@ -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 */
diff --git a/winsup/cygwin/termios.cc b/winsup/cygwin/termios.cc
index 6a5736b10..5eb5ddba9 100644
--- a/winsup/cygwin/termios.cc
+++ b/winsup/cygwin/termios.cc
@@ -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"
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index fa8cdb512..bd7286dff 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -17,6 +17,7 @@ details. */
#include <stdlib.h>
#include <errno.h>
#include "pinfo.h"
+#include "cygerrno.h"
#define FACTOR (0x19db1ded53ea710LL)
#define NSPERSEC 10000000LL
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 1aa182cc9..015cce657 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -16,6 +16,7 @@ details. */
#include <winuser.h>
#include "dtable.h"
#include "pinfo.h"
+#include "cygerrno.h"
extern fhandler_tty_master *tty_master;
diff --git a/winsup/cygwin/wait.cc b/winsup/cygwin/wait.cc
index 91b8e5cd4..62d4112f1 100644
--- a/winsup/cygwin/wait.cc
+++ b/winsup/cygwin/wait.cc
@@ -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. */
diff --git a/winsup/cygwin/window.cc b/winsup/cygwin/window.cc
index 98e6b6d03..4373acc24 100644
--- a/winsup/cygwin/window.cc
+++ b/winsup/cygwin/window.cc
@@ -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;
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index 3c9e51981..db304414f 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -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 */