Differences between 20080129 and 20080213 diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/bsd_helper.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/bsd_helper.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/bsd_helper.cc 2007-11-08 14:24:01.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/bsd_helper.cc 2008-02-11 18:57:10.000000000 +0000 @@ -452,5 +452,5 @@ _vm_pager_allocate (int size, int shmflg PAGE_READWRITE, 0, size, NULL); if (!object) - panic ("CreateFileMapping in _vm_pager_allocate failed, %E"); + panic ("CreateFileMapping in _vm_pager_allocate failed, %lu", GetLastError ()); return object; } @@ -463,5 +463,5 @@ vm_object_duplicate (struct thread *td, td->client->handle (), &dup_object, 0, TRUE, DUPLICATE_SAME_ACCESS)) - panic ("!DuplicateHandle in vm_object_duplicate failed, %E"); + panic ("!DuplicateHandle in vm_object_duplicate failed, %lu", GetLastError ()); return dup_object; } diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/bsd_log.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/bsd_log.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/bsd_log.cc 2005-11-10 10:50:46.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/bsd_log.cc 2008-02-11 18:57:10.000000000 +0000 @@ -12,5 +12,4 @@ details. */ #define _KERNEL 1 #define __BSD_VISIBLE 1 -#include #include #include @@ -54,12 +53,13 @@ _vlog (const char *file, int line, int l { char buf[16384]; + char *pos; if ((level == LOG_DEBUG && log_debug != TUN_TRUE) || (level != LOG_DEBUG && level >= log_level)) return; - strcpy (buf, "cygserver: "); + pos = stpcpy (buf, "cygserver: "); if (file && log_debug == TUN_TRUE) - __small_sprintf (strchr (buf, '\0'), "%s, line %d: ", file, line); - __small_vsprintf (strchr (buf, '\0'), fmt, ap); + pos += snprintf (pos, 16384 - (pos - buf), "%s, line %d: ", file, line); + vsnprintf (pos, 16384 - (pos - buf), fmt, ap); if (log_syslog == TUN_TRUE && level != LOG_DEBUG) syslog (level, buf); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/bsd_mutex.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/bsd_mutex.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/bsd_mutex.cc 2007-02-23 11:43:48.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/bsd_mutex.cc 2008-02-11 18:57:10.000000000 +0000 @@ -35,5 +35,5 @@ mtx_init (mtx *m, const char *name, cons m->h = CreateSemaphore (NULL, 1, 1, NULL); if (!m->h) - panic ("couldn't allocate %s mutex, %E\n", name); + panic ("couldn't allocate %s mutex, %lu\n", name, GetLastError ()); } @@ -44,5 +44,6 @@ _mtx_lock (mtx *m, DWORD winpid, const c m->name, winpid, m->owner); if (WaitForSingleObject (m->h, INFINITE) != WAIT_OBJECT_0) - _panic (file, line, "wait for %s in %d failed, %E", m->name, winpid); + _panic (file, line, "wait for %s in %d failed, %lu", m->name, winpid, + GetLastError ()); m->owner = winpid; _log (file, line, LOG_DEBUG, "Locked mutex %s/%u (%u)", @@ -86,5 +87,6 @@ _mtx_unlock (mtx *m, const char *file, i /* Check if the semaphore was already on it's max value. */ if (GetLastError () != ERROR_TOO_MANY_POSTS) - _panic (file, line, "release of mutex %s failed, %E", m->name); + _panic (file, line, "release of mutex %s failed, %lu", m->name, + GetLastError ()); } _log (file, line, LOG_DEBUG, "Unlocked mutex %s/%u (owner: %u)", @@ -200,5 +202,5 @@ class msleep_sync_array a[i].wakeup_evt = CreateEvent (NULL, TRUE, FALSE, NULL); if (!a[i].wakeup_evt) - panic ("CreateEvent failed: %E"); + panic ("CreateEvent failed: %lu", GetLastError ()); debug ("i = %d, CreateEvent: %x", i, a[i].wakeup_evt); a[i].threads = 1; @@ -283,5 +285,5 @@ msleep_init (void) msleep_glob_evt = CreateEvent (NULL, TRUE, FALSE, NULL); if (!msleep_glob_evt) - panic ("CreateEvent in msleep_init failed: %E"); + panic ("CreateEvent in msleep_init failed: %lu", GetLastError ()); long msgmni = support_msgqueues ? msginfo.msgmni : 0; long semmni = support_semaphores ? seminfo.semmni : 0; @@ -347,7 +349,7 @@ _msleep (void *ident, struct mtx *mtx, i hope for the best. */ if (GetLastError () != ERROR_INVALID_HANDLE) - panic ("wait in msleep (%s) failed, %E", wmesg); - debug ("wait in msleep (%s) failed for %d, %E", wmesg, - td->td_proc->winpid); + panic ("wait in msleep (%s) failed, %lu", wmesg, GetLastError ()); + debug ("wait in msleep (%s) failed for %d, %lu", wmesg, + td->td_proc->winpid, GetLastError ()); ret = EIDRM; break; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/Makefile.in winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/Makefile.in --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/Makefile.in 2007-08-02 14:23:22.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/Makefile.in 2008-02-11 18:57:10.000000000 +0000 @@ -44,5 +44,5 @@ OBJS:= cygserver.o client.o process.o ms LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)} -CYGWIN_OBJS:=$(cygwin_build)/smallprint.o $(cygwin_build)/strfuncs.o $(cygwin_build)/version.o +CYGWIN_OBJS:=$(cygwin_build)/version.o CYGWIN_LIB:=$(cygwin_build)/libcygwin.a diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/sysv_sem.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/sysv_sem.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygserver/sysv_sem.cc 2006-01-09 15:10:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygserver/sysv_sem.cc 2008-02-11 18:57:10.000000000 +0000 @@ -13,4 +13,5 @@ #ifdef __OUTSIDE_CYGWIN__ #include "woutsup.h" +#include #include #include @@ -248,6 +249,6 @@ seminit(void) for (i = 0; i < seminfo.semmni; i++) { - char *buf = (char *)malloc (16); - __small_sprintf (buf, "semid[%d]", i); + char *buf = (char *) sys_malloc(16, M_SEM, M_WAITOK); + snprintf(buf, 16, "semid[%d]", i); mtx_init(&sema_mtx[i], buf, NULL, MTX_DEF); } @@ -281,6 +282,8 @@ semunload(void) sys_free(sema, M_SEM); sys_free(semu, M_SEM); - for (int i = 0; i < seminfo.semmni; i++) + for (int i = 0; i < seminfo.semmni; i++) { + sys_free((void *) sema_mtx[i].name, M_SEM); mtx_destroy(&sema_mtx[i]); + } mtx_destroy(&sem_mtx); return (0); @@ -873,5 +876,5 @@ semget(struct thread *td, struct semget_ #endif - DPRINTF(("semget(0x%X, %d, 0%o)\n", key, nsems, semflg)); + DPRINTF(("semget(0x%llx, %d, 0%o)\n", key, nsems, semflg)); if (!jail_sysvipc_allowed && jailed(td->td_ucred)) return (ENOSYS); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/autoload.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/autoload.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/autoload.cc 2007-12-13 12:55:34.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/autoload.cc 2008-02-11 18:57:10.000000000 +0000 @@ -321,5 +321,5 @@ LoadDLLfuncEx (LsaLookupAuthenticationPa LoadDLLfuncEx (LsaRegisterLogonProcess, 12, secur32, 1) -LoadDLLfunc (CharToOemA, 8, user32) +LoadDLLfunc (CharNextExA, 12, user32) LoadDLLfunc (CloseClipboard, 0, user32) LoadDLLfunc (CloseDesktop, 4, user32) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygheap.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygheap.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygheap.h 2007-11-27 13:27:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygheap.h 2008-02-11 18:57:11.000000000 +0000 @@ -224,7 +224,9 @@ struct cwdstuff char *posix; UNICODE_STRING win32; + HANDLE dir; DWORD drive_length; static muto cwd_lock; char *get (char *, int = 1, int = 0, unsigned = CYG_MAX_PATH); + HANDLE get_handle () { return dir; } DWORD get_drive (char * dst) { diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygtls.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygtls.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygtls.cc 2007-11-27 13:27:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygtls.cc 2008-02-13 17:30:15.000000000 +0000 @@ -261,5 +261,21 @@ _cygtls::init_exception_handler (excepti { el.handler = eh; - el.prev = ⪙ + /* Apparently Windows stores some information about an exception and tries + to figure out if the SEH which returned 0 last time actually solved the + problem, or if the problem still persists (e.g. same exception at same + address). In this case Windows seems to decide that it can't trust + that SEH and calls the next handler in the chain instead. + + At one point this was a loop (el.prev = ⪙). This outsmarted the + above behaviour. Unfortunately this trick doesn't work anymore with + Windows 2008, which irremediably gets into an endless loop, taking 100% + CPU. That's why we reverted to a normal SEH chain. + + On the bright side, Windows' behaviour is covered by POSIX: + + "If and when the function returns, if the value of sig was SIGFPE, + SIGILL, or SIGSEGV or any other implementation-defined value + corresponding to a computational exception, the behavior is undefined." */ + el.prev = _except_list; _except_list = ⪙ } Binary files winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygwin1.dbg and winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygwin1.dbg differ diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygwin.din winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygwin.din --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/cygwin.din 2007-12-30 22:07:17.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/cygwin.din 2008-02-11 18:57:11.000000000 +0000 @@ -29,4 +29,5 @@ _sys_nerr DATA _timezone DATA _tzname DATA +_Exit SIGFE a64l NOSIGFE abort NOSIGFE @@ -349,5 +350,4 @@ _execvp = execvp SIGFE exit = cygwin_exit SIGFE _exit SIGFE -_Exit SIGFE exp NOSIGFE _exp = exp NOSIGFE @@ -433,5 +433,4 @@ fcvtf SIGFE _fcvtf = fcvtf SIGFE fdatasync SIGFE -fdopendir SIGFE fdim NOSIGFE fdimf NOSIGFE @@ -439,4 +438,5 @@ fdopen SIGFE _fdopen = fdopen SIGFE _fdopen64 = fdopen64 SIGFE +fdopendir SIGFE feof SIGFE _feof = feof SIGFE @@ -454,4 +454,5 @@ _fgetpos64 = fgetpos64 SIGFE fgets SIGFE _fgets = fgets SIGFE +fgetxattr SIGFE fileno SIGFE _fileno = fileno SIGFE @@ -462,4 +463,5 @@ _finitef = finitef NOSIGFE fiprintf SIGFE _fiprintf = fiprintf SIGFE +flistxattr SIGFE flock SIGFE flockfile SIGFE @@ -502,4 +504,5 @@ _free = free SIGFE freeaddrinfo = cygwin_freeaddrinfo SIGFE freeifaddrs SIGFE +fremovexattr SIGFE freopen SIGFE _freopen = freopen SIGFE @@ -521,4 +524,5 @@ fsetpos SIGFE _fsetpos = fsetpos SIGFE _fsetpos64 = fsetpos64 SIGFE +fsetxattr SIGFE fstat SIGFE _fstat = fstat SIGFE @@ -696,4 +700,5 @@ _getw = getw SIGFE getwd SIGFE _getwd = getwd SIGFE +getxattr SIGFE glob SIGFE _glob = glob SIGFE @@ -850,9 +855,12 @@ _lgammaf = lgammaf NOSIGFE lgammaf_r NOSIGFE _lgammaf_r = lgammaf_r NOSIGFE +lgetxattr SIGFE link SIGFE _link = link SIGFE listen = cygwin_listen SIGFE +listxattr SIGFE llabs NOSIGFE lldiv NOSIGFE +llistxattr SIGFE llrint = _f_llrint NOSIGFE llrintf = _f_llrintf NOSIGFE @@ -888,4 +896,5 @@ _longjmp = longjmp NOSIGFE lrand48 NOSIGFE _lrand48 = lrand48 NOSIGFE +lremovexattr SIGFE lrint = _f_lrint NOSIGFE lrintf = _f_lrintf NOSIGFE @@ -897,4 +906,5 @@ lseek SIGFE _lseek = lseek SIGFE _lseek64 = lseek64 SIGFE +lsetxattr SIGFE lstat SIGFE _lstat = lstat SIGFE @@ -1171,4 +1181,5 @@ _remainderf = remainderf NOSIGFE remove SIGFE _remove = remove SIGFE +removexattr SIGFE remque NOSIGFE remquo NOSIGFE @@ -1342,4 +1353,5 @@ setutxent SIGFE setvbuf SIGFE _setvbuf = setvbuf SIGFE +setxattr SIGFE sexecl = sexecve_is_bad SIGFE sexecle = sexecve_is_bad SIGFE @@ -1350,10 +1362,10 @@ sexecv = sexecve_is_bad SIGFE sexecve = sexecve_is_bad SIGFE sexecvpe = sexecve_is_bad SIGFE +shm_open SIGFE +shm_unlink SIGFE shmat SIGFE shmctl SIGFE shmdt SIGFE shmget SIGFE -shm_open SIGFE -shm_unlink SIGFE shutdown = cygwin_shutdown SIGFE sigaction SIGFE diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/dcrt0.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/dcrt0.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/dcrt0.cc 2007-12-13 12:55:34.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/dcrt0.cc 2008-02-11 18:57:11.000000000 +0000 @@ -19,4 +19,5 @@ details. */ #include #include +#include #include #include @@ -856,9 +857,8 @@ dll_crt0_1 (void *) if (!__argc) { - char *line = GetCommandLineA (); - line = strcpy ((char *) alloca (strlen (line) + 1), line); - - if (current_codepage == oem_cp) - CharToOemA (line, line); + PWCHAR wline = GetCommandLineW (); + size_t size = sys_wcstombs (NULL, 0, wline); + char *line = (char *) alloca (size); + sys_wcstombs (line, size, wline); /* Scan the command line and build argv. Expand wildcards if not @@ -893,5 +893,5 @@ dll_crt0_1 (void *) { char *cp = strchr (__progname, '\0') - 4; - if (cp > __progname && strcasematch (cp, ".exe")) + if (cp > __progname && ascii_strcasematch (cp, ".exe")) *cp = '\0'; } diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/dtable.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/dtable.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/dtable.cc 2007-12-16 23:34:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/dtable.cc 2008-02-11 18:57:11.000000000 +0000 @@ -337,5 +337,7 @@ dtable::init_std_file_from_handle (int f DWORD access; - if (fd == 0) + if (dev == FH_TTY || dev == FH_CONSOLE) + access = GENERIC_READ | GENERIC_WRITE; + else if (fd == 0) access = GENERIC_READ; else diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/environ.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/environ.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/environ.cc 2007-12-13 12:55:35.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/environ.cc 2008-02-11 18:57:11.000000000 +0000 @@ -17,4 +17,5 @@ details. */ #include #include +#include #include "pinfo.h" #include "perprocess.h" @@ -460,5 +461,5 @@ glob_init (const char *buf) ignore_case_with_glob = false; } - else if (strncasematch (buf, "ignorecase", 10)) + else if (ascii_strncasematch (buf, "ignorecase", 10)) { allow_glob = true; @@ -478,15 +479,15 @@ check_case_init (const char *buf) return; - if (strncasematch (buf, "relax", 5)) + if (ascii_strncasematch (buf, "relax", 5)) { pcheck_case = PCHECK_RELAXED; debug_printf ("File case checking set to RELAXED"); } - else if (strcasematch (buf, "adjust")) + else if (ascii_strcasematch (buf, "adjust")) { pcheck_case = PCHECK_ADJUST; debug_printf ("File case checking set to ADJUST"); } - else if (strcasematch (buf, "strict")) + else if (ascii_strcasematch (buf, "strict")) { pcheck_case = PCHECK_STRICT; @@ -507,5 +508,5 @@ set_file_api_mode (codepage_type cp) debug_printf ("File APIs set to OEM"); } - else if (cp == ansi_cp) + else { SetFileApisToANSI (); @@ -514,22 +515,29 @@ set_file_api_mode (codepage_type cp) } -static void +void codepage_init (const char *buf) { - if (!buf || !*buf) - return; + if (!buf) + buf = "ansi"; - if (strcasematch (buf, "oem")) + if (ascii_strcasematch (buf, "oem")) { current_codepage = oem_cp; - set_file_api_mode (current_codepage); + active_codepage = GetOEMCP (); } - else if (strcasematch (buf, "ansi")) + else if (ascii_strcasematch (buf, "utf8")) { - current_codepage = ansi_cp; - set_file_api_mode (current_codepage); + current_codepage = utf8_cp; + active_codepage = CP_UTF8; } else - debug_printf ("Wrong codepage name: %s", buf); + { + if (!ascii_strcasematch (buf, "ansi")) + debug_printf ("Wrong codepage name: %s", buf); + /* Fallback to ANSI */ + current_codepage = ansi_cp; + active_codepage = GetACP (); + } + set_file_api_mode (current_codepage); } @@ -549,5 +557,5 @@ static void set_ntsec (const char *buf) { - allow_ntsec = (buf && strcasematch (buf, "yes")); + allow_ntsec = (buf && ascii_strcasematch (buf, "yes")); } @@ -555,5 +563,5 @@ static void set_smbntsec (const char *buf) { - allow_smbntsec = (buf && strcasematch (buf, "yes")); + allow_smbntsec = (buf && ascii_strcasematch (buf, "yes")); } @@ -640,5 +648,5 @@ parse_options (char *buf) { char *keyword_here = p; - if (!(istrue = !strncasematch (p, "no", 2))) + if (!(istrue = !ascii_strncasematch (p, "no", 2))) p += 2; else if (!(istrue = *p != '-')) @@ -652,5 +660,5 @@ parse_options (char *buf) for (parse_thing *k = known; k->name != NULL; k++) - if (strcasematch (p, k->name)) + if (ascii_strcasematch (p, k->name)) { switch (k->disposition) @@ -905,5 +913,5 @@ char * spenv::retrieve (bool no_envblock, const char *const env) { - if (env && !strncasematch (env, name, namelen)) + if (env && !ascii_strncasematch (env, name, namelen)) return NULL; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/errno.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/errno.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/errno.cc 2006-09-07 20:42:53.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/errno.cc 2008-02-11 18:57:11.000000000 +0000 @@ -63,8 +63,13 @@ static NO_COPY struct X (DISK_FULL, ENOSPC), X (DUP_NAME, ENOTUNIQ), + X (EAS_DIDNT_FIT, ENOSPC), + X (EAS_NOT_SUPPORTED, ENOTSUP), + X (EA_LIST_INCONSISTENT, EINVAL), + X (EA_TABLE_FULL, ENOSPC), X (END_OF_MEDIA, ENOSPC), X (EOM_OVERFLOW, EIO), X (FILEMARK_DETECTED, EIO), X (FILENAME_EXCED_RANGE, ENAMETOOLONG), + X (FILE_CORRUPT, EEXIST), X (FILE_EXISTS, EEXIST), X (FILE_INVALID, ENXIO), @@ -77,4 +82,5 @@ static NO_COPY struct X (INVALID_DATA, EINVAL), X (INVALID_DRIVE, ENODEV), + X (INVALID_EA_NAME, EINVAL), X (INVALID_FUNCTION, EBADRQC), X (INVALID_HANDLE, EBADF), diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/exceptions.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/exceptions.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/exceptions.cc 2007-12-16 23:34:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/exceptions.cc 2008-02-13 17:30:15.000000000 +0000 @@ -246,7 +246,18 @@ stack_info::walk () if (needargs) - /* The arguments follow the return address */ - for (unsigned i = 0; i < NPARAMS; i++) - sf.Params[i] = (DWORD) *++ebp; + { + unsigned nparams = NPARAMS; + + /* The arguments follow the return address */ + sf.Params[0] = (DWORD) *++ebp; + /* Hack for XP/2K3 WOW64. If the first stack param points to the + application entry point, we can only fetch one additional + parameter. Accessing anything beyond this address results in + a SEGV. This is fixed in Vista/2K8 WOW64. */ + if (wincap.has_restricted_stack_args () && sf.Params[0] == 0x401000) + nparams = 2; + for (unsigned i = 0; i < nparams; i++) + sf.Params[i] = (DWORD) *++ebp; + } return 1; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler.cc 2007-12-16 23:34:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler.cc 2008-02-11 18:57:11.000000000 +0000 @@ -1477,4 +1477,19 @@ fhandler_base::facl (int cmd, int nentri } +ssize_t +fhandler_base::fgetxattr (const char *name, void *value, size_t size) +{ + set_errno (ENOTSUP); + return -1; +} + +int +fhandler_base::fsetxattr (const char *name, const void *value, size_t size, + int flags) +{ + set_errno (ENOTSUP); + return -1; +} + int fhandler_base::fadvise (_off64_t offset, _off64_t length, int advice) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_clipboard.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_clipboard.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_clipboard.cc 2005-11-14 04:28:44.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_clipboard.cc 2008-02-11 18:57:11.000000000 +0000 @@ -15,5 +15,7 @@ details. */ #include #include +#include #include +#include #include #include @@ -83,5 +85,5 @@ set_clipboard (const void *buf, size_t l { HGLOBAL hmem; - unsigned char *clipbuf; + void *clipbuf; /* Native CYGWIN format */ OpenClipboard (0); @@ -92,6 +94,6 @@ set_clipboard (const void *buf, size_t l return -1; } - clipbuf = (unsigned char *) GlobalLock (hmem); - memcpy (clipbuf + sizeof (size_t), buf, len); + clipbuf = GlobalLock (hmem); + memcpy ((unsigned char *) clipbuf + sizeof (size_t), buf, len); *(size_t *) (clipbuf) = len; GlobalUnlock (hmem); @@ -119,5 +121,12 @@ set_clipboard (const void *buf, size_t l OpenClipboard (0); - hmem = GlobalAlloc (GMEM_MOVEABLE, len + 2); + + len = MultiByteToWideChar (get_cp (), 0, (const char *) buf, len, NULL, 0); + if (!len) + { + system_printf ("Invalid string"); + return -1; + } + hmem = GlobalAlloc (GMEM_MOVEABLE, (len + 1) * sizeof (WCHAR)); if (!hmem) { @@ -125,11 +134,9 @@ set_clipboard (const void *buf, size_t l return -1; } - clipbuf = (unsigned char *) GlobalLock (hmem); - memcpy (clipbuf, buf, len); - *(clipbuf + len) = '\0'; - *(clipbuf + len + 1) = '\0'; + clipbuf = GlobalLock (hmem); + sys_mbstowcs ((PWCHAR) clipbuf, (const char *) buf, len); + *((PWCHAR) clipbuf + len) = L'\0'; GlobalUnlock (hmem); - if (!SetClipboardData - ((current_codepage == ansi_cp ? CF_TEXT : CF_OEMTEXT), hmem)) + if (!SetClipboardData (CF_UNICODETEXT, hmem)) { system_printf ("Couldn't write to the clipboard"); @@ -197,5 +204,5 @@ fhandler_dev_clipboard::read (void *ptr, { formatlist[0] = cygnativeformat; - formatlist[1] = current_codepage == ansi_cp ? CF_TEXT : CF_OEMTEXT; + formatlist[1] = CF_UNICODETEXT; OpenClipboard (0); if ((format = GetPriorityClipboardFormat (formatlist, 2)) <= 0) @@ -223,14 +230,22 @@ fhandler_dev_clipboard::read (void *ptr, else { - LPSTR lpstr; - lpstr = (LPSTR) GlobalLock (hglb); - - ret = ((len > (strlen (lpstr) - pos)) ? (strlen (lpstr) - pos) - : len); - - memcpy (ptr, lpstr + pos, ret); - //ret = snprintf((char *) ptr, len, "%s", lpstr);//+pos); + int wret; + PWCHAR buf; + buf = (PWCHAR) GlobalLock (hglb); + size_t glen = GlobalSize (hglb) / sizeof (WCHAR) - 1; + + /* This loop is necessary because the number of bytes returned + by WideCharToMultiByte does not indicate the number of wide + chars used for it, so we could potentially drop wide chars. */ + if (glen - pos > len) + glen = pos + len; + while ((wret = sys_wcstombs (NULL, 0, buf + pos, glen - pos)) + != -1 + && (size_t) wret > len) + --glen; + ret = sys_wcstombs ((char *) ptr, len, buf + pos, glen - pos); + //ret = snprintf((char *) ptr, len, "%s", buf);//+pos); pos += ret; - if (pos + len - ret >= strlen (lpstr)) + if (pos + len - ret >= wcslen (buf)) eof = true; GlobalUnlock (hglb); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_console.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_console.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_console.cc 2007-11-27 13:27:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_console.cc 2008-02-11 18:57:11.000000000 +0000 @@ -34,27 +34,5 @@ details. */ #include "registry.h" -#define CONVERT_LIMIT 16384 - -static bool -cp_convert (UINT destcp, char *dest, UINT srccp, const char *src, DWORD size) -{ - if (!size) - /* no action */; - else if (destcp == srccp) - { - if (dest != src) - memcpy (dest, src, size); - } - else - { - WCHAR wbuffer[CONVERT_LIMIT]; /* same size as the maximum input, s.b. */ - if (!MultiByteToWideChar (srccp, 0, src, size, wbuffer, sizeof (wbuffer))) - return false; - if (!WideCharToMultiByte (destcp, 0, wbuffer, size, dest, size, - NULL, NULL)) - return false; - } - return true; -} +#define CONVERT_LIMIT 65536 /* @@ -176,19 +154,19 @@ set_console_state_for_spawn (bool iscyg) any time. */ inline bool -dev_console::con_to_str (char *d, const char *s, DWORD sz) +dev_console::con_to_str (char *d, int dlen, WCHAR w) { - return cp_convert (get_cp (), d, GetConsoleCP (), s, sz); + return !!sys_wcstombs (d, dlen, &w, 1); } -inline bool -dev_console::str_to_con (char *d, const char *s, DWORD sz) +inline UINT +dev_console::get_console_cp () { - if (alternate_charset_active) - { - /* no translation when alternate charset is active */ - memcpy(d, s, sz); - return true; - } - return cp_convert (GetConsoleOutputCP (), d, get_cp (), s, sz); + return alternate_charset_active ? GetConsoleOutputCP () : get_cp (); +} + +inline DWORD +dev_console::str_to_con (PWCHAR d, const char *s, DWORD sz) +{ + return MultiByteToWideChar (get_console_cp (), 0, s, sz, d, CONVERT_LIMIT); } @@ -293,5 +271,5 @@ fhandler_console::read (void *pv, size_t const char *toadd = NULL; - if (!ReadConsoleInput (h, &input_rec, 1, &nread)) + if (!ReadConsoleInputW (h, &input_rec, 1, &nread)) { syscall_printf ("ReadConsoleInput failed, %E"); @@ -377,9 +355,5 @@ fhandler_console::read (void *pv, size_t else { - tmp[1] = ich; - /* Need this check since US code page seems to have a bug when - converting a CTRL-U. */ - if ((unsigned char) ich > 0x7f) - dev_state->con_to_str (tmp + 1, tmp + 1, 1); + dev_state->con_to_str (tmp + 1, 59, wch); /* Determine if the keystroke is modified by META. The tricky part is to distinguish whether the right Alt key should be @@ -388,5 +362,5 @@ fhandler_console::read (void *pv, size_t meta = (control_key_state & ALT_PRESSED) != 0 && ((control_key_state & CTRL_PRESSED) == 0 - || ((signed char) ich >= 0 && ich <= 0x1f || ich == 0x7f)); + || (wch <= 0x1f || wch == 0x7f)); if (!meta) toadd = tmp + 1; @@ -528,5 +502,4 @@ fhandler_console::read (void *pv, size_t break; } -#undef ich } @@ -923,5 +896,7 @@ fhandler_console::fhandler_console () : fhandler_termios () { + trunc_buf.len = 0; } + void dev_console::set_color (HANDLE h) @@ -1065,5 +1040,5 @@ fhandler_console::cursor_get (int *x, in #define NOR 0 #define IGN 4 -#if 0 +#if 1 #define ERR 5 #else @@ -1083,5 +1058,5 @@ static const char base_chars[256] = /*18 19 1A 1B 1C 1D 1E 1F */ NOR, NOR, ERR, ESC, ERR, ERR, ERR, ERR, /* ! " # $ % & ' */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR, -/*() * + , - . / */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR, +/*( ) * + , - . / */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR, /*0 1 2 3 4 5 6 7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR, /*8 9 : ; < = > ? */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR, @@ -1245,5 +1220,5 @@ fhandler_console::char_command (char c) dev_state->savebufsiz.X * dev_state->savebufsiz.Y); - ReadConsoleOutputA (get_output_handle (), dev_state->savebuf, + ReadConsoleOutputW (get_output_handle (), dev_state->savebuf, dev_state->savebufsiz, cob, &now.srWindow); } @@ -1259,5 +1234,5 @@ fhandler_console::char_command (char c) break; - WriteConsoleOutputA (get_output_handle (), dev_state->savebuf, + WriteConsoleOutputW (get_output_handle (), dev_state->savebuf, dev_state->savebufsiz, cob, &now.srWindow); @@ -1453,4 +1428,22 @@ beep () } +/* This gets called when we found an invalid UTF-8 character. We try with + the default ANSI codepage. If that fails we just print a question mark. + Looks ugly but is a neat and alomst sane fallback for many languages. */ +void +fhandler_console::write_replacement_char (const unsigned char *char_p) +{ + int n; + WCHAR def_cp_chars[2]; + DWORD done; + + n = MultiByteToWideChar (GetACP (), 0, (const CHAR *) char_p, 1, + def_cp_chars, 2); + if (n) + WriteConsoleW (get_output_handle (), def_cp_chars, n, &done, 0); + else + WriteConsoleW (get_output_handle (), L"?", 1, &done, 0); +} + const unsigned char * fhandler_console::write_normal (const unsigned char *src, @@ -1459,12 +1452,54 @@ fhandler_console::write_normal (const un /* Scan forward to see what a char which needs special treatment */ DWORD done; + DWORD buf_len; const unsigned char *found = src; + const unsigned char *nfound; + UINT cp = dev_state->get_console_cp (); - while (found < end) + /* First check if we have cached lead bytes of a former try to write + a truncated multibyte sequence. If so, process it. */ + if (trunc_buf.len) { - char ch = base_chars[*found]; - if (ch != NOR) + int cp_len = min (end - src, 4 - trunc_buf.len); + memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len); + nfound = next_char (cp, trunc_buf.buf, + trunc_buf.buf + trunc_buf.len + cp_len); + if (!nfound) /* Invalid multibyte sequence. */ + { /* Give up and print replacement chars. */ + for (int i = 0; i < trunc_buf.len; ++i) + write_replacement_char (trunc_buf.buf + i); + } + else if (nfound == trunc_buf.buf) + { /* Still truncated multibyte sequence. */ + trunc_buf.len += cp_len; + return end; + } + else + { + /* Valid multibyte sequence. Process. */ + WCHAR buf[2]; + buf_len = dev_state->str_to_con (buf, (const char *) trunc_buf.buf, + nfound - trunc_buf.buf); + WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0); + found = src + (nfound - trunc_buf.buf - trunc_buf.len); + } + /* Mark trunc_buf as unused. */ + trunc_buf.len = 0; + } + + while (found < end + && found - src < CONVERT_LIMIT + && base_chars[*found] == NOR) + { + nfound = next_char (cp, found, end); + if (!nfound) /* Invalid multibyte sequence. */ break; - found++; + if (nfound == found) /* Truncated multibyte sequence. */ + { /* Stick to it until the next write. */ + trunc_buf.len = end - found; + memcpy (trunc_buf.buf, found, trunc_buf.len); + return end; + } + found = nfound; } @@ -1473,25 +1508,25 @@ fhandler_console::write_normal (const un { DWORD len = found - src; - do + PWCHAR buf = (PWCHAR) alloca (CONVERT_LIMIT * sizeof (WCHAR)); + + buf_len = dev_state->str_to_con (buf, (const char *) src, len); + if (!buf_len) { - DWORD buf_len; - char buf[CONVERT_LIMIT]; - done = buf_len = min (sizeof (buf), len); - if (!dev_state->str_to_con (buf, (const char *) src, buf_len)) - { - debug_printf ("conversion error, handle %p", - get_output_handle ()); - __seterrno (); - return 0; - } + debug_printf ("conversion error, handle %p", + get_output_handle ()); + __seterrno (); + return 0; + } - if (dev_state->insert_mode) - { - int x, y; - cursor_get (&x, &y); - scroll_screen (x, y, -1, y, x + buf_len, y); - } + if (dev_state->insert_mode) + { + int x, y; + cursor_get (&x, &y); + scroll_screen (x, y, -1, y, x + buf_len, y); + } - if (!WriteFile (get_output_handle (), buf, buf_len, &done, 0)) + do + { + if (!WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0)) { debug_printf ("write failed, handle %p", get_output_handle ()); @@ -1499,14 +1534,16 @@ fhandler_console::write_normal (const un return 0; } - len -= done; - src += done; + buf_len -= done; + buf += done; } - while (len > 0); + while (buf_len > 0); + if (len >= CONVERT_LIMIT) + return found; } - if (src < end) + if (found < end) { int x, y; - switch (base_chars[*src]) + switch (base_chars[*found]) { case BEL: @@ -1521,5 +1558,5 @@ fhandler_console::write_normal (const un { if (y >= dev_state->info.winBottom && !dev_state->scroll_region.Top) - WriteFile (get_output_handle (), "\n", 1, &done, 0); + WriteConsoleW (get_output_handle (), L"\n", 1, &done, 0); else { @@ -1541,5 +1578,5 @@ fhandler_console::write_normal (const un break; case ERR: - WriteFile (get_output_handle (), src, 1, &done, 0); + WriteFile (get_output_handle (), found, 1, &done, 0); break; case TAB: @@ -1547,8 +1584,11 @@ fhandler_console::write_normal (const un cursor_set (false, 8 * (x / 8 + 1), y); break; + case NOR: + write_replacement_char (found); + break; } - src ++; + found++; } - return src; + return found; } diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_disk_file.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_disk_file.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_disk_file.cc 2008-01-23 00:27:15.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_disk_file.cc 2008-02-13 17:30:15.000000000 +0000 @@ -947,4 +947,27 @@ cant_access_acl: } +ssize_t +fhandler_disk_file::fgetxattr (const char *name, void *value, size_t size) +{ + if (pc.is_fs_special ()) + { + set_errno (ENOTSUP); + return -1; + } + return read_ea (get_handle (), pc, name, (char *) value, size); +} + +int +fhandler_disk_file::fsetxattr (const char *name, const void *value, size_t size, + int flags) +{ + if (pc.is_fs_special ()) + { + set_errno (ENOTSUP); + return -1; + } + return write_ea (get_handle (), pc, name, (const char *) value, size, flags); +} + int fhandler_disk_file::fadvise (_off64_t offset, _off64_t length, int advice) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_dsp.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_dsp.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_dsp.cc 2007-11-27 13:27:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_dsp.cc 2008-02-11 18:57:11.000000000 +0000 @@ -1132,4 +1132,5 @@ fhandler_dev_dsp::dup (fhandler_base * c debug_printf (""); child->archetype = archetype; + child->set_flags (get_flags ()); archetype->usecount++; return 0; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler.h 2008-01-12 19:52:28.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler.h 2008-02-11 18:57:11.000000000 +0000 @@ -289,4 +289,6 @@ class fhandler_base virtual int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2))); virtual int __stdcall facl (int, int, __acl32 *) __attribute__ ((regparm (3))); + virtual ssize_t __stdcall fgetxattr (const char *, void *, size_t) __attribute__ ((regparm (3))); + virtual int __stdcall fsetxattr (const char *, const void *, size_t, int) __attribute__ ((regparm (3))); virtual int __stdcall fadvise (_off64_t, _off64_t, int) __attribute__ ((regparm (3))); virtual int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3))); @@ -687,4 +689,6 @@ class fhandler_disk_file: public fhandle int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2))); int __stdcall facl (int, int, __acl32 *) __attribute__ ((regparm (3))); + ssize_t __stdcall fgetxattr (const char *, void *, size_t) __attribute__ ((regparm (3))); + int __stdcall fsetxattr (const char *, const void *, size_t, int) __attribute__ ((regparm (3))); int __stdcall fadvise (_off64_t, _off64_t, int) __attribute__ ((regparm (3))); int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3))); @@ -880,6 +884,7 @@ class dev_console bool raw_win32_keyboard_mode; - bool con_to_str (char *d, const char *s, DWORD sz); - bool str_to_con (char *d, const char *s, DWORD sz); + inline UINT get_console_cp (); + bool con_to_str (char *d, int dlen, WCHAR w); + DWORD str_to_con (PWCHAR d, const char *s, DWORD sz); void set_color (HANDLE); bool fillin_info (HANDLE); @@ -896,4 +901,11 @@ class fhandler_console: public fhandler_ static bool invisible_console; + /* Used when we encounter a truncated multi-byte sequence. The + lead bytes are stored here and revisited in the next write call. */ + struct { + int len; + unsigned char buf[4]; /* Max len of valid UTF-8 sequence. */ + } trunc_buf; + /* Output calls */ void set_default_attr (); @@ -904,4 +916,5 @@ class fhandler_console: public fhandler_ void cursor_get (int *, int *); void cursor_rel (int, int); + void write_replacement_char (const unsigned char *); const unsigned char *write_normal (unsigned const char*, unsigned const char *); void char_command (char); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_process.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_process.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_process.cc 2007-12-13 12:55:38.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_process.cc 2008-02-11 18:57:11.000000000 +0000 @@ -457,5 +457,5 @@ fhandler_process::fill_filebuf () { char *s = filebuf + len - 4; - if (strcasematch (s, ".exe")) + if (ascii_strcasematch (s, ".exe")) *s = 0; } @@ -619,5 +619,5 @@ format_process_stat (_pinfo *p, char *de { char *s = cmd + len - 4; - if (strcasematch (s, ".exe")) + if (ascii_strcasematch (s, ".exe")) *s = 0; } @@ -745,5 +745,5 @@ format_process_status (_pinfo *p, char * { char *s = cmd + len - 4; - if (strcasematch (s, ".exe")) + if (ascii_strcasematch (s, ".exe")) *s = 0; } diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_tty.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_tty.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/fhandler_tty.cc 2007-12-13 12:55:38.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/fhandler_tty.cc 2008-02-11 18:57:11.000000000 +0000 @@ -929,4 +929,5 @@ fhandler_tty_slave::dup (fhandler_base * fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype; *(fhandler_tty_slave *) child = *arch; + child->set_flags (get_flags ()); child->usecount = 0; arch->usecount++; @@ -941,4 +942,5 @@ fhandler_pty_master::dup (fhandler_base fhandler_tty_master *arch = (fhandler_tty_master *) archetype; *(fhandler_tty_master *) child = *arch; + child->set_flags (get_flags ()); child->usecount = 0; arch->usecount++; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/hookapi.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/hookapi.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/hookapi.cc 2007-11-27 13:27:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/hookapi.cc 2008-02-11 18:57:11.000000000 +0000 @@ -56,5 +56,5 @@ rvadelta (PIMAGE_NT_HEADERS pnt, DWORD i if (section[i].VirtualAddress <= import_rva && (section[i].VirtualAddress + section[i].Misc.VirtualSize) > import_rva) - // if (strncasematch ((char *) section[i].Name, ".idata", IMAGE_SIZEOF_SHORT_NAME)) + // if (ascii_strncasematch ((char *) section[i].Name, ".idata", IMAGE_SIZEOF_SHORT_NAME)) return section[i].VirtualAddress - section[i].PointerToRawData; return -1; @@ -191,5 +191,5 @@ hook_or_detect_cygwin (const char *name, for (PIMAGE_IMPORT_DESCRIPTOR pd = pdfirst; pd->FirstThunk; pd++) { - if (!strcasematch (rva (PSTR, hm, pd->Name - delta), "cygwin1.dll")) + if (!ascii_strcasematch (rva (PSTR, hm, pd->Name - delta), "cygwin1.dll")) continue; if (!fn) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/include/attr/xattr.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/include/attr/xattr.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/include/attr/xattr.h 1970-01-01 00:00:00.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/include/attr/xattr.h 2008-02-11 19:03:36.000000000 +0000 @@ -0,0 +1,46 @@ +/* attr/xattr.h + + Copyright 2008 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. */ + +#ifndef _ATTR_XATTR_H +#define _ATTR_XATTR_H + +#include "_ansi.h" +#if 0 +/* Per man pages you have to include explicitely before + including . That's how it works on Linux, too. */ +#include +#endif +#include + +#define XATTR_CREATE 1 +#define XATTR_REPLACE 2 + +#ifndef ENOATTR +#define ENOATTR ENODATA +#endif + +_BEGIN_STD_C + +ssize_t _EXFUN(getxattr,(const char *, const char *, void *, size_t )); +ssize_t _EXFUN(lgetxattr,(const char *, const char *, void *, size_t )); +ssize_t _EXFUN(fgetxattr,(int , const char *, void *, size_t )); +ssize_t _EXFUN(listxattr,(const char *, char *, size_t )); +ssize_t _EXFUN(llistxattr,(const char *, char *, size_t )); +ssize_t _EXFUN(flistxattr,(int , char *, size_t )); +int _EXFUN(setxattr,(const char *, const char *, const void *, size_t , int )); +int _EXFUN(lsetxattr,(const char *, const char *, const void *, size_t , int )); +int _EXFUN(fsetxattr,(int , const char *, const void *, size_t , int )); +int _EXFUN(removexattr,(const char *, const char *)); +int _EXFUN(lremovexattr,(const char *, const char *)); +int _EXFUN(fremovexattr,(int , const char *)); + +_END_STD_C + +#endif /* _ATTR_XATTR_H */ diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/include/cygwin/version.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/include/cygwin/version.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/include/cygwin/version.h 2008-01-29 21:16:13.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/include/cygwin/version.h 2008-02-13 17:30:20.000000000 +0000 @@ -323,4 +323,7 @@ details. */ _f_lrintl, _f_rint, _f_rintf, _f_rintl, llrint, llrintf, llrintl, rintl, lrintl, and redirect exports of lrint, lrintf, rint, rintf. + 180: Export getxattr, lgetxattr, fgetxattr, listxattr, llistxattr, + flistxattr, setxattr, lsetxattr, fsetxattr, removexattr, + lremovexattr, fremovexattr. */ @@ -328,5 +331,5 @@ details. */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 179 +#define CYGWIN_VERSION_API_MINOR 180 /* There is also a compatibity version number associated with the diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/include/limits.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/include/limits.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/include/limits.h 2008-01-12 19:52:28.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/include/limits.h 2008-02-11 18:57:11.000000000 +0000 @@ -29,5 +29,7 @@ details. */ /* Maximum length of a multibyte character. */ #ifndef MB_LEN_MAX -#define MB_LEN_MAX 1 +/* TODO: This is newlib's max value. We should probably rather define our + own _mbtowc_r and _wctomb_r functions which are only codepage dependent. */ +#define MB_LEN_MAX 8 #endif diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/libc/ftw.c winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/libc/ftw.c --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/libc/ftw.c 2005-08-08 13:39:55.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/libc/ftw.c 2008-02-11 18:57:11.000000000 +0000 @@ -50,4 +50,8 @@ ftw(const char *path, int (*fn)(const ch int error = 0, fnflag, sverrno; +#if 0 + /* GLibc allows nfds < 1 and treats it as nfds == 1. Since nfds is + not used in this OpenBSD version anyway, just ignore it for + Linux compatibility. */ /* XXX - nfds is currently unused */ if (nfds < 1 || nfds > OPEN_MAX) { @@ -55,4 +59,5 @@ ftw(const char *path, int (*fn)(const ch return (-1); } +#endif ftsp = fts_open(paths, FTS_LOGICAL | FTS_COMFOLLOW | FTS_NOCHDIR, NULL); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/libc/nftw.c winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/libc/nftw.c --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/libc/nftw.c 2005-08-08 13:39:55.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/libc/nftw.c 2008-02-11 18:57:11.000000000 +0000 @@ -51,4 +51,8 @@ nftw(const char *path, int (*fn)(const c int error = 0, ftsflags, fnflag, postorder, sverrno; +#if 0 + /* GLibc allows nfds < 1 and treats it as nfds == 1. Since nfds is + not used in this OpenBSD version anyway, just ignore it for + Linux compatibility. */ /* XXX - nfds is currently unused */ if (nfds < 1 || nfds > OPEN_MAX) { @@ -56,4 +60,5 @@ nftw(const char *path, int (*fn)(const c return (-1); } +#endif ftsflags = FTS_COMFOLLOW; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/Makefile.in winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/Makefile.in --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/Makefile.in 2008-01-23 00:27:15.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/Makefile.in 2008-02-11 18:57:10.000000000 +0000 @@ -137,5 +137,5 @@ DLL_OFILES:=assert.o autoload.o bsdlib.o grp.o heap.o hookapi.o inet_addr.o inet_network.o init.o ioctl.o ipc.o \ localtime.o lsearch.o malloc_wrapper.o minires-os-if.o \ - minires.o miscfuncs.o mktemp.o mmap.o msg.o net.o netdb.o nftw.o \ + minires.o miscfuncs.o mktemp.o mmap.o msg.o net.o netdb.o nftw.o ntea.o \ passwd.o path.o pinfo.o pipe.o poll.o posix_ipc.o pthread.o random.o \ regcomp.o regerror.o regexec.o regfree.o registry.o resource.o rexec.o \ diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/miscfuncs.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/miscfuncs.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/miscfuncs.cc 2007-12-13 12:55:38.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/miscfuncs.cc 2008-02-11 18:57:11.000000000 +0000 @@ -18,4 +18,7 @@ details. */ #include #include +#include +#include +#include #include "cygthread.h" #include "cygtls.h" @@ -95,12 +98,12 @@ cygwin_wcsncasecmp (const wchar_t *ws, { UNICODE_STRING us, ut; + size_t ls = 0, lt = 0; - n *= sizeof (WCHAR); - RtlInitUnicodeString (&us, ws); - if (us.Length > n) - us.Length = n; - RtlInitUnicodeString (&ut, wt); - if (ut.Length > n) - ut.Length = n; + while (ws[ls] && ls < n) + ++ls; + RtlInitCountedUnicodeString (&us, ws, ls * sizeof (WCHAR)); + while (wt[lt] && lt < n) + ++lt; + RtlInitCountedUnicodeString (&ut, wt, lt * sizeof (WCHAR)); return RtlCompareUnicodeString (&us, &ut, TRUE); } @@ -126,16 +129,18 @@ cygwin_strncasecmp (const char *cs, cons UNICODE_STRING us, ut; ULONG len; - - n *= sizeof (WCHAR); - len = (strlen (cs) + 1) * sizeof (WCHAR); + size_t ls = 0, lt = 0; + + while (cs[ls] && ls < n) + ++ls; + len = ls * sizeof (WCHAR); RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len); - us.Length = sys_mbstowcs (us.Buffer, cs, us.MaximumLength) * sizeof (WCHAR); - if (us.Length > n) - us.Length = n; - len = (strlen (ct) + 1) * sizeof (WCHAR); + us.Length = MultiByteToWideChar (get_cp (), 0, cs, ls, us.Buffer, + us.MaximumLength) * sizeof (WCHAR); + while (ct[lt] && lt < n) + ++lt; + len = lt * sizeof (WCHAR); RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len); - ut.Length = sys_mbstowcs (ut.Buffer, ct, ut.MaximumLength) * sizeof (WCHAR); - if (ut.Length > n) - ut.Length = n; + ut.Length = MultiByteToWideChar (get_cp (), 0, ct, lt, ut.Buffer, + ut.MaximumLength) * sizeof (WCHAR); return RtlCompareUnicodeString (&us, &ut, TRUE); } @@ -189,4 +194,116 @@ cygwin_strupr (char *string) } +/* FIXME? We only support standard ANSI/OEM codepages according to + http://www.microsoft.com/globaldev/reference/cphome.mspx as well + as UTF-8 and codepage 1361, which is also mentioned as valid + doublebyte codepage in MSDN man pages (e.g. IsDBCSLeadByteEx). + Everything else will be hosed. */ + +bool +is_cp_multibyte (UINT cp) +{ + switch (cp) + { + case 932: + case 936: + case 949: + case 950: + case 1361: + case 65001: + return true; + } + return false; +} + +/* OMYGOD! CharNextExA is not UTF-8 aware! It only works fine with + double byte charsets. So we have to do it ourselves for UTF-8. + + While being at it, we do more. If a double-byte or multibyte + sequence is truncated due to an early end, we need a way to recognize + it. The reason is that multiple buffered write statements might + accidentally stop and start in the middle of a single character byte + sequence. If we have to interpret the byte sequences (as in + fhandler_console), we would print wrong output in these cases. + + So we have four possible return values here: + + ret = end if str >= end + ret = NULL if we encounter an invalid byte sequence + ret = str if we encounter the start byte of a truncated byte sequence + ret = str + n if we encounter a vaild byte sequence +*/ + +const unsigned char * +next_char (UINT cp, const unsigned char *str, const unsigned char *end) +{ + const unsigned char *ret = NULL; + + if (str >= end) + return end; + + switch (cp) + { + case 932: + case 936: + case 949: + case 950: + case 1361: + if (*str <= 0x7f) + ret = str + 1; + else if (str == end - 1 && IsDBCSLeadByteEx (cp, *str)) + ret = str; + else + ret = (const unsigned char *) CharNextExA (cp, (const CHAR *) str, 0); + break; + case CP_UTF8: + switch (str[0] >> 4) + { + case 0x0 ... 0x7: /* One byte character. */ + ret = str + 1; + break; + case 0x8 ... 0xb: /* Followup byte. Invalid as first byte. */ + ret = NULL; + break; + case 0xc ... 0xd: /* Two byte character. */ + /* Check followup bytes for validity. */ + if (str >= end - 1) + ret = str; + else if (str[1] <= 0xbf) + ret = str + 2; + else + ret = NULL; + break; + case 0xe: /* Three byte character. */ + if (str >= end - 2) + ret = str; + else if ((str[1] & 0xc0) == 0x80 && (str[2] & 0xc0) == 0x80 + && (str[0] != 0xe0 || str[1] >= 0xa0) + && (str[0] != 0xed || str[1] <= 0x9f)) + ret = str + 3; + else + ret = NULL; + break; + case 0xf: /* Four byte character. */ + if (str[0] >= 0xf8) + ret = NULL; + else if (str >= end - 3) + ret = str; + else if ((str[1] & 0xc0) == 0x80 && (str[2] & 0xc0) == 0x80 + && (str[3] & 0xc0) == 0x80 + && (str[0] == 0xf0 || str[1] >= 0x90) + && (str[0] == 0xf4 || str[1] <= 0x8f)) + ret = str + 4; + else + ret = NULL; + break; + } + break; + default: + ret = str + 1; + break; + } + return ret; +} + int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/ntdll.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/ntdll.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/ntdll.h 2008-01-23 00:27:15.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/ntdll.h 2008-02-11 18:57:11.000000000 +0000 @@ -26,4 +26,7 @@ #define STATUS_OBJECT_PATH_NOT_FOUND ((NTSTATUS) 0xc000003A) #define STATUS_SHARING_VIOLATION ((NTSTATUS) 0xc0000043) +#define STATUS_EA_TOO_LARGE ((NTSTATUS) 0xc0000050) +#define STATUS_NONEXISTENT_EA_ENTRY ((NTSTATUS) 0xc0000051) +#define STATUS_NO_EAS_ON_FILE ((NTSTATUS) 0xc0000052) #define STATUS_DELETE_PENDING ((NTSTATUS) 0xc0000056) #define STATUS_DISK_FULL ((NTSTATUS) 0xc000007f) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/ntea.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/ntea.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/ntea.cc 2007-02-20 00:16:17.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/ntea.cc 2008-02-11 18:57:11.000000000 +0000 @@ -1,7 +1,5 @@ -/* ntea.cc: code for manipulating NTEA information - - Copyright 1997, 1998, 2000, 2001, 2006 Red Hat, Inc. +/* ntea.cc: code for manipulating Extended Attributes - Written by Sergey S. Okhapkin (sos@prospect.com.ru) + Copyright 1997, 1998, 2000, 2001, 2006, 2008 Red Hat, Inc. This file is part of Cygwin. @@ -12,161 +10,484 @@ details. */ #include "winsup.h" -#include -#include +#include "cygtls.h" +#include "cygerrno.h" #include "security.h" +#include "path.h" +#include "fhandler.h" +#include "dtable.h" +#include "pinfo.h" +#include "cygheap.h" +#include #include "ntdll.h" +#include +#include -/* Default to not using NTEA information */ -bool allow_ntea; +#define MAX_EA_NAME_LEN 256 +#define MAX_EA_VALUE_LEN 65536 -/* - * read_ea - read file's Extended Attribute. - * - * Parameters: - * file - pointer to filename - * attrname- pointer to EA name (case insensitiv) - * attrbuf - pointer to buffer to store EA's value. - * len - length of attrbuf. - * Return value: - * 0 - if file or attribute "attrname" not found. - * N - number of bytes stored in attrbuf if success. - * -1 - attrbuf too small for EA value. - */ +/* At least one maximum sized entry fits. */ +#define EA_BUFSIZ (sizeof (FILE_FULL_EA_INFORMATION) + MAX_EA_NAME_LEN \ + + MAX_EA_VALUE_LEN) -int __stdcall -read_ea (HANDLE hdl, const char *file, const char *attrname, char *attrbuf, - int len) +#define NEXT_FEA(p) ((PFILE_FULL_EA_INFORMATION) (p->NextEntryOffset \ + ? (char *) p + p->NextEntryOffset : NULL)) + +ssize_t __stdcall +read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size) { + OBJECT_ATTRIBUTES attr; + NTSTATUS status; IO_STATUS_BLOCK io; + ssize_t ret = -1; + HANDLE h = hdl; + ULONG glen = 0; + PFILE_GET_EA_INFORMATION gea = NULL; + PFILE_FULL_EA_INFORMATION fea; + /* We have to store the latest EaName to compare with the next one, since + ZwQueryEaFile has a bug when accessing files on a remote share. It + returns the last EA entry of the file infinitely. Even utilizing the + optional EaIndex only helps marginally. If you use that, the last + EA in the file is returned twice. */ + char lastname[MAX_EA_NAME_LEN]; - /* Prepare buffer which receives the result. */ - ULONG flen = sizeof (FILE_FULL_EA_INFORMATION) + strlen (attrname) - + len + 1; - PFILE_FULL_EA_INFORMATION fea = (PFILE_FULL_EA_INFORMATION) alloca (flen); - /* Prepare buffer specifying the EA to search for. */ - ULONG glen = sizeof (FILE_GET_EA_INFORMATION) + strlen (attrname); - PFILE_GET_EA_INFORMATION gea = (PFILE_GET_EA_INFORMATION) alloca (glen); - gea->NextEntryOffset = 0; - gea->EaNameLength = strlen (attrname); - strcpy (gea->EaName, attrname); + myfault efault; + if (efault.faulted (EFAULT)) + goto out; + + pc.get_object_attr (attr, sec_none_nih); + + debug_printf ("read_ea (%S, %s, %p, %lu)", + attr.ObjectName, name, value, size); + + fea = (PFILE_FULL_EA_INFORMATION) alloca (EA_BUFSIZ); + + if (name) + { + size_t nlen; + + /* Samba hides the user namespace from Windows clients. If we try to + retrieve a user namespace item, we remove the leading namespace from + the name, otherwise the search fails. */ + if (pc.fs_is_samba ()) + if (ascii_strncasematch (name, "user.", 5)) + name += 5; + else + { + set_errno (ENOATTR); + goto out; + } + + if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN) + { + set_errno (EINVAL); + return -1; + } + glen = sizeof (FILE_GET_EA_INFORMATION) + nlen; + gea = (PFILE_GET_EA_INFORMATION) alloca (glen); + + gea->NextEntryOffset = 0; + gea->EaNameLength = nlen; + strcpy (gea->EaName, name); + } - /* If no incoming hdl is given, the loop only runs once, trying to - open the file and to query the EA. If an incoming hdl is given, - the loop runs twice, first trying to query with the given hdl. - If this fails it tries to open the file and to query with that - handle again. */ - HANDLE h = hdl; - NTSTATUS status = STATUS_SUCCESS; - int ret = 0; while (true) { - if (!hdl && (h = CreateFile (file, FILE_READ_EA, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_none_nih, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, NULL)) - == INVALID_HANDLE_VALUE) + if (h) { - debug_printf ("Opening %s for querying EA %s failed, %E", - file, attrname); - goto out; + status = NtQueryEaFile (h, &io, fea, EA_BUFSIZ, TRUE, gea, glen, + NULL, TRUE); + if (status != STATUS_ACCESS_DENIED || !hdl) + break; } - status = NtQueryEaFile (h, &io, fea, flen, FALSE, gea, glen, NULL, TRUE); - if (NT_SUCCESS (status) || !hdl) + status = NtOpenFile (&h, READ_CONTROL | FILE_READ_EA, &attr, &io, + FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); + if (!NT_SUCCESS (status)) break; - debug_printf ("1. chance, %x = NtQueryEaFile (%s, %s), Win32 error %d", - status, file, attrname, RtlNtStatusToDosError (status)); hdl = NULL; } - if (!hdl) - CloseHandle (h); if (!NT_SUCCESS (status)) { - ret = -1; - debug_printf ("%x = NtQueryEaFile (%s, %s), Win32 error %d", - status, file, attrname, RtlNtStatusToDosError (status)); + if (status == STATUS_NO_EAS_ON_FILE) + ret = 0; + else if (status == STATUS_NONEXISTENT_EA_ENTRY) + /* Actually this error code is either never generated, or it was only + generated in some old and long forgotton NT version. See below. */ + set_errno (ENOATTR); + else + __seterrno_from_nt_status (status); + goto out; } - if (!fea->EaValueLength) - ret = 0; - else + if (name) { - memcpy (attrbuf, fea->EaName + fea->EaNameLength + 1, - fea->EaValueLength); + if (size > 0) + { + if (size < fea->EaValueLength) + { + set_errno (ERANGE); + goto out; + } + /* Another weird behaviour of ZwQueryEaFile. If you ask for a + specific EA which is not present in the file's EA list, you don't + get a useful error code like STATUS_NONEXISTENT_EA_ENTRY. Rather + ZwQueryEaFile returns success with the entry's EaValueLength + set to 0. */ + if (!fea->EaValueLength) + { + set_errno (ENOATTR); + goto out; + } + else + memcpy (value, fea->EaName + fea->EaNameLength + 1, + fea->EaValueLength); + } ret = fea->EaValueLength; } + else + { + ret = 0; + do + { + if (pc.fs_is_samba ()) /* See below. */ + fea->EaNameLength += 5; + if (size > 0) + { + if ((size_t) ret + fea->EaNameLength + 1 > size) + { + set_errno (ERANGE); + goto out; + } + /* Samba hides the user namespace from Windows clients. We add + it in EA listings to keep tools like attr/getfattr/setfattr + happy. */ + char tmpbuf[MAX_EA_NAME_LEN * 2], *tp = tmpbuf; + if (pc.fs_is_samba ()) + tp = stpcpy (tmpbuf, "user."); + stpcpy (tp, fea->EaName); + /* NTFS stores all EA names in uppercase unfortunately. To keep + compatibility with ext/xfs EA namespaces and accompanying + tools, which expect the namespaces to be lower case, we return + EA names in lowercase if the file is on a native NTFS. */ + if (pc.fs_is_ntfs ()) + strlwr (tp); + tp = stpcpy (value, tmpbuf) + 1; + ret += tp - value; + value = tp; + } + else + ret += fea->EaNameLength + 1; + strcpy (lastname, fea->EaName); + status = NtQueryEaFile (h, &io, fea, EA_BUFSIZ, TRUE, NULL, 0, + NULL, FALSE); + } + while (NT_SUCCESS (status) && strcmp (lastname, fea->EaName) != 0); + } out: - debug_printf ("%d = read_ea (%x, %s, %s, %x, %d)", ret, hdl, file, attrname, - attrbuf, len); + if (!hdl) + CloseHandle (h); + debug_printf ("%d = read_ea (%S, %s, %p, %lu)", + ret, attr.ObjectName, name, value, size); return ret; } -/* - * write_ea - write file's Extended Attribute. - * - * Parameters: - * file - pointer to filename - * attrname- pointer to EA name (case insensitiv) - * attrbuf - pointer to buffer with EA value. - * len - length of attrbuf. - * Return value: - * true if success, false otherwice. - * Note: if len=0 given EA will be deleted. - */ - -BOOL __stdcall -write_ea (HANDLE hdl, const char *file, const char *attrname, - const char *attrbuf, int len) +int __stdcall +write_ea (HANDLE hdl, path_conv &pc, const char *name, const char *value, + size_t size, int flags) { + OBJECT_ATTRIBUTES attr; + NTSTATUS status; IO_STATUS_BLOCK io; + int ret = -1; + HANDLE h = hdl; + PFILE_FULL_EA_INFORMATION fea; + ULONG flen; + size_t nlen; - /* Prepare buffer specifying the EA to write back. */ - ULONG flen = sizeof (FILE_FULL_EA_INFORMATION) + strlen (attrname) - + len + 1; - PFILE_FULL_EA_INFORMATION fea = (PFILE_FULL_EA_INFORMATION) alloca (flen); + myfault efault; + if (efault.faulted (EFAULT)) + goto out; + + pc.get_object_attr (attr, sec_none_nih); + + debug_printf ("write_ea (%S, %s, %p, %lu, %d)", + attr.ObjectName, name, value, size, flags); + + /* Samba hides the user namespace from Windows clients. If we get a + user namespace item, we remove the leading namespace from the name. + This keeps tools like attr/getfattr/setfattr happy. Otherwise + setting the EA fails as if we don't have the permissions. */ + if (pc.fs_is_samba () && ascii_strncasematch (name, "user.", 5)) + name += 5; + else + { + set_errno (EOPNOTSUPP); + goto out; + } + + /* removexattr is supposed to fail with ENOATTR if the requested EA is not + available. This is equivalent to the XATTR_REPLACE flag for setxattr. */ + if (!value) + flags = XATTR_REPLACE; + + if (flags) + { + if (flags != XATTR_CREATE && flags != XATTR_REPLACE) + { + set_errno (EINVAL); + goto out; + } + ssize_t rret = read_ea (hdl, pc, name, NULL, 0); + if (flags == XATTR_CREATE && rret > 0) + { + set_errno (EEXIST); + goto out; + } + if (flags == XATTR_REPLACE && rret < 0) + goto out; + } + + if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN) + { + set_errno (EINVAL); + goto out; + } + flen = sizeof (FILE_FULL_EA_INFORMATION) + nlen + 1 + size; + fea = (PFILE_FULL_EA_INFORMATION) alloca (flen); fea->NextEntryOffset = 0; fea->Flags = 0; - fea->EaNameLength = strlen (attrname); - fea->EaValueLength = len; - strcpy (fea->EaName, attrname); - memcpy (fea->EaName + fea->EaNameLength + 1, attrbuf, len); + fea->EaNameLength = nlen; + fea->EaValueLength = size; + strcpy (fea->EaName, name); + if (value) + memcpy (fea->EaName + fea->EaNameLength + 1, value, size); - /* If no incoming hdl is given, the loop only runs once, trying to - open the file and to set the EA. If an incoming hdl is given, - the loop runs twice, first trying to set the EA with the given hdl. - If this fails it tries to open the file and to set the EA with that - handle again. */ - HANDLE h = hdl; - NTSTATUS status = STATUS_SUCCESS; - bool ret = false; while (true) { - if (!hdl && (h = CreateFile (file, FILE_READ_EA, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_none_nih, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, NULL)) - == INVALID_HANDLE_VALUE) + if (h) { - debug_printf ("Opening %s for setting EA %s failed, %E", - file, attrname); - goto out; + status = NtSetEaFile (h, &io, fea, flen); + if (status != STATUS_ACCESS_DENIED || !hdl) + break; } - status = NtSetEaFile (h, &io, fea, flen); - if (NT_SUCCESS (status) || !hdl) + status = NtOpenFile (&h, READ_CONTROL | FILE_WRITE_EA, &attr, &io, + FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); + if (!NT_SUCCESS (status)) break; - debug_printf ("1. chance, %x = NtQueryEaFile (%s, %s), Win32 error %d", - status, file, attrname, RtlNtStatusToDosError (status)); hdl = NULL; } - if (!hdl) - CloseHandle (h); if (!NT_SUCCESS (status)) - debug_printf ("%x = NtQueryEaFile (%s, %s), Win32 error %d", - status, file, attrname, RtlNtStatusToDosError (status)); + { + /* STATUS_EA_TOO_LARGE has a matching Win32 error ERROR_EA_TABLE_FULL. + Too bad RtlNtStatusToDosError does not translate STATUS_EA_TOO_LARGE + to ERROR_EA_TABLE_FULL, but to ERROR_EA_LIST_INCONSISTENT. This + error code is also returned for STATUS_EA_LIST_INCONSISTENT, which + means the incoming EA list is... inconsistent. For obvious reasons + we translate ERROR_EA_LIST_INCONSISTENT to EINVAL, so we have to + handle STATUS_EA_TOO_LARGE explicitely here, to get the correct + mapping to ENOSPC. */ + if (status == STATUS_EA_TOO_LARGE) + set_errno (ENOSPC); + else + __seterrno_from_nt_status (status); + } else - ret = true; + ret = 0; out: - debug_printf ("%d = write_ea (%x, %s, %s, %x, %d)", ret, hdl, file, attrname, - attrbuf, len); + if (!hdl) + CloseHandle (h); + debug_printf ("%d = write_ea (%S, %s, %p, %lu, %d)", + ret, attr.ObjectName, name, value, size, flags); return ret; } + +static ssize_t __stdcall +getxattr_worker (path_conv &pc, const char *name, void *value, size_t size) +{ + int res = -1; + + if (pc.error) + { + debug_printf ("got %d error from build_fh_name", pc.error); + set_errno (pc.error); + } + else if (pc.exists ()) + { + fhandler_base *fh; + + if (!(fh = build_fh_pc (pc))) + return -1; + + res = fh->fgetxattr (name, value, size); + delete fh; + } + else + set_errno (ENOENT); + return res; +} + +extern "C" ssize_t +getxattr (const char *path, const char *name, void *value, size_t size) +{ + if (!name) + { + set_errno (EINVAL); + return -1; + } + path_conv pc (path, PC_SYM_FOLLOW | PC_POSIX, stat_suffixes); + return getxattr_worker (pc, name, value, size); +} + +extern "C" ssize_t +lgetxattr (const char *path, const char *name, void *value, size_t size) +{ + if (!name) + { + set_errno (EINVAL); + return -1; + } + path_conv pc (path, PC_SYM_NOFOLLOW | PC_POSIX, stat_suffixes); + return getxattr_worker (pc, name, value, size); +} + +extern "C" ssize_t +fgetxattr (int fd, const char *name, void *value, size_t size) +{ + int res; + + if (!name) + { + set_errno (EINVAL); + return -1; + } + cygheap_fdget cfd (fd); + if (cfd < 0) + res = -1; + else + res = cfd->fgetxattr (name, value, size); + return res; +} + +extern "C" ssize_t +listxattr (const char *path, char *list, size_t size) +{ + path_conv pc (path, PC_SYM_FOLLOW | PC_POSIX, stat_suffixes); + return getxattr_worker (pc, NULL, list, size); +} + +extern "C" ssize_t +llistxattr (const char *path, char *list, size_t size) +{ + path_conv pc (path, PC_SYM_NOFOLLOW | PC_POSIX, stat_suffixes); + return getxattr_worker (pc, NULL, list, size); +} + +extern "C" ssize_t +flistxattr (int fd, char *list, size_t size) +{ + int res; + + cygheap_fdget cfd (fd); + if (cfd < 0) + res = -1; + else + res = cfd->fgetxattr (NULL, list, size); + return res; +} + +static int __stdcall +setxattr_worker (path_conv &pc, const char *name, const void *value, + size_t size, int flags) +{ + int res = -1; + + if (pc.error) + { + debug_printf ("got %d error from build_fh_name", pc.error); + set_errno (pc.error); + } + else if (pc.exists ()) + { + fhandler_base *fh; + + if (!(fh = build_fh_pc (pc))) + return -1; + + res = fh->fsetxattr (name, value, size, flags); + delete fh; + } + else + set_errno (ENOENT); + return res; +} + +extern "C" int +setxattr (const char *path, const char *name, const void *value, size_t size, + int flags) +{ + if (!size) + { + set_errno (EINVAL); + return -1; + } + path_conv pc (path, PC_SYM_NOFOLLOW | PC_POSIX, stat_suffixes); + return setxattr_worker (pc, name, value, size, flags); +} + +extern "C" int +lsetxattr (const char *path, const char *name, const void *value, size_t size, + int flags) +{ + if (!size) + { + set_errno (EINVAL); + return -1; + } + path_conv pc (path, PC_SYM_NOFOLLOW | PC_POSIX, stat_suffixes); + return setxattr_worker (pc, name, value, size, flags); +} + +extern "C" int +fsetxattr (int fd, const char *name, const void *value, size_t size, int flags) +{ + int res; + + if (!size) + { + set_errno (EINVAL); + return -1; + } + cygheap_fdget cfd (fd); + if (cfd < 0) + res = -1; + else + res = cfd->fsetxattr (name, value, size, flags); + return res; +} + +extern "C" int +removexattr (const char *path, const char *name) +{ + path_conv pc (path, PC_SYM_FOLLOW | PC_POSIX, stat_suffixes); + return setxattr_worker (pc, name, NULL, 0, 0); +} + +extern "C" int +lremovexattr (const char *path, const char *name) +{ + path_conv pc (path, PC_SYM_NOFOLLOW | PC_POSIX, stat_suffixes); + return setxattr_worker (pc, name, NULL, 0, 0); +} + +extern "C" int +fremovexattr (int fd, const char *name) +{ + int res; + + cygheap_fdget cfd (fd); + if (cfd < 0) + res = -1; + else + res = cfd->fsetxattr (name, NULL, 0, 0); + return res; +} diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/path.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/path.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/path.cc 2008-01-29 21:16:07.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/path.cc 2008-02-11 18:57:11.000000000 +0000 @@ -1195,7 +1195,7 @@ out: const char *p = strchr (path, '\0') - 4; if (p >= path && - (strcasematch (".exe", p) || - strcasematch (".bat", p) || - strcasematch (".com", p))) + (ascii_strcasematch (".exe", p) || + ascii_strcasematch (".bat", p) || + ascii_strcasematch (".com", p))) path_flags |= PATH_EXEC; } @@ -1563,12 +1563,13 @@ special_name (const char *s, int inc = 1 int n; const char *p = NULL; - if (strncasematch (s, "conin$", n = 5) - || strncasematch (s, "conout$", n = 7) - || strncasematch (s, "nul", n = 3) - || strncasematch (s, "aux", 3) - || strncasematch (s, "prn", 3) - || strncasematch (s, "con", 3)) + if (ascii_strncasematch (s, "conin$", n = 5) + || ascii_strncasematch (s, "conout$", n = 7) + || ascii_strncasematch (s, "nul", n = 3) + || ascii_strncasematch (s, "aux", 3) + || ascii_strncasematch (s, "prn", 3) + || ascii_strncasematch (s, "con", 3)) p = s + n; - else if (strncasematch (s, "com", 3) || strncasematch (s, "lpt", 3)) + else if (ascii_strncasematch (s, "com", 3) + || ascii_strncasematch (s, "lpt", 3)) strtoul (s + 3, (char **) &p, 10); if (p && (*p == '\0' || *p == '.')) @@ -1576,5 +1577,5 @@ special_name (const char *s, int inc = 1 return (strchr (s, '\0')[-1] == '.') - || (strpbrk (s, special_chars) && !strncasematch (s, "%2f", 3)); + || (strpbrk (s, special_chars) && !ascii_strncasematch (s, "%2f", 3)); } @@ -2891,5 +2892,5 @@ is_floppy (const char *dos) if (!QueryDosDevice (dos, dev, 256)) return false; - return strncasematch (dev, "\\Device\\Floppy", 14); + return ascii_strncasematch (dev, "\\Device\\Floppy", 14); } @@ -3469,5 +3470,5 @@ suffix_scan::has (const char *in_path, c /* Check if the extension matches a known extension */ for (const suffix_info *ex = in_suffixes; ex->name != NULL; ex++) - if (strcasematch (ext_here, ex->name)) + if (ascii_strcasematch (ext_here, ex->name)) { nextstate = SCAN_JUSTCHECK; @@ -3478,5 +3479,5 @@ suffix_scan::has (const char *in_path, c /* Didn't match. Use last resort -- .lnk. */ - if (strcasematch (ext_here, ".lnk")) + if (ascii_strcasematch (ext_here, ".lnk")) { nextstate = SCAN_HASLNK; @@ -4174,5 +4175,5 @@ realpath (const char *path, char *resolv { char *c = strrchr (real_path.normalized_path, '.'); - if (!c || !strcasematch (c, real_path.known_suffix)) + if (!c || !ascii_strcasematch (c, real_path.known_suffix)) tack_on = strlen (real_path.known_suffix); } @@ -4432,5 +4433,5 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, open directories so that deleting the directory is disallowed. The below code opens with *all* sharing flags set. */ - HANDLE h; + HANDLE h, h_copy; NTSTATUS status; IO_STATUS_BLOCK io; @@ -4442,16 +4443,4 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, if (!nat_cwd) /* On init, just reopen CWD with desired access flags. */ RtlInitUnicodeString (&upath, L""); - else - { - /* TODO: - Check the length of the new CWD. Windows can only handle - CWDs of up to MAX_PATH length, including a trailing backslash. - If the path is longer, it's not an error condition for Cygwin, - so we don't fail. Windows on the other hand has a problem now. - For now, we just don't store the path in the PEB and proceed as - usual. */ - if (len > MAX_PATH - (nat_cwd->Buffer[len - 1] == L'\\' ? 1 : 2)) - goto skip_peb_storing; - } InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, @@ -4469,6 +4458,34 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, goto out; } + /* Workaround a problem in Vista which fails in subsequent calls to + CreateFile with ERROR_INVALID_HANDLE if the handle in + CurrentDirectoryHandle changes without calling SetCurrentDirectory, + and the filename given to CreateFile is a relative path. It looks + like Vista stores a copy of the CWD handle in some other undocumented + place. The NtClose/DuplicateHandle reuses the original handle for + the copy of the new handle and the next CreateFile works. + Note that this is not thread-safe (yet?) */ + if (!DuplicateHandle (GetCurrentProcess (), h, GetCurrentProcess (), + &h_copy, 0, TRUE, DUPLICATE_SAME_ACCESS)) + { + RtlReleasePebLock (); + __seterrno (); + NtClose (h); + res = -1; + goto out; + } + NtClose (*phdl); + dir = *phdl = h; - if (nat_cwd) /* No need to set path on init. */ + /* No need to set path on init. */ + if (nat_cwd + /* TODO: + Check the length of the new CWD. Windows can only handle + CWDs of up to MAX_PATH length, including a trailing backslash. + If the path is longer, it's not an error condition for Cygwin, + so we don't fail. Windows on the other hand has a problem now. + For now, we just don't store the path in the PEB and proceed as + usual. */ + && len <= MAX_PATH - (nat_cwd->Buffer[len - 1] == L'\\' ? 1 : 2)) { /* Convert to a Win32 path. */ @@ -4486,20 +4503,4 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, &upath); } - NtClose (*phdl); - /* Workaround a problem in Vista which fails in subsequent calls to - CreateFile with ERROR_INVALID_HANDLE if the handle in - CurrentDirectoryHandle changes without calling SetCurrentDirectory, - and the filename given to CreateFile is a relative path. It looks - like Vista stores a copy of the CWD handle in some other undocumented - place. The NtClose/DuplicateHandle reuses the original handle for - the copy of the new handle and the next CreateFile works. - Note that this is not thread-safe (yet?) */ - if (DuplicateHandle (GetCurrentProcess (), h, GetCurrentProcess (), phdl, - 0, TRUE, DUPLICATE_SAME_ACCESS)) - NtClose (h); - else - *phdl = h; - -skip_peb_storing: RtlReleasePebLock (); @@ -4553,5 +4554,5 @@ skip_peb_storing: { PWCHAR ptr = wcschr (win32.Buffer + 2, L'\\'); - if (*ptr) + if (ptr) ptr = wcschr (ptr + 1, L'\\'); if (ptr) diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/posix.sgml winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/posix.sgml --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/posix.sgml 2007-06-29 15:13:00.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/posix.sgml 2008-02-13 17:30:15.000000000 +0000 @@ -348,4 +348,7 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 llabs lldiv + llrint + llrintf + llrintl localeconv localtime @@ -363,4 +366,5 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 lrint lrintf + lrintl lround lroundf @@ -562,4 +566,5 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 rint rintf + rintl rmdir round @@ -796,6 +801,11 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 wcsspn wcsstr + wcstol + wcstoll wcstombs + wcstoul + wcstoull wcswidth + wcsxfrm wctob wctomb @@ -925,5 +935,5 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 -System interfaces compatible with GNU extensions: +System interfaces compatible with GNU or Linux extensions: @@ -955,12 +965,24 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 fcloseall fcloseall_r + fgetxattr + flistxattr fopencookie + fremovexattr + fsetxattr getline getopt_long getopt_long_only + getxattr + lgetxattr + listxattr + llistxattr + lremovexattr + lsetxattr memmem mempcpy pow10 pow10f + removexattr + setxattr stpcpy stpncpy @@ -976,4 +998,6 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 vasprintf_r vdprintf + wcpcpy + wcpncpy @@ -1169,7 +1193,4 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 lgammal lio_listio - llrint - llrintf - llrintl llround llroundf @@ -1181,5 +1202,4 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 logbl logl - lrintl lroundl makecontext @@ -1214,5 +1234,4 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 reminderl remquol - rintl roundl scalblnl @@ -1250,12 +1269,7 @@ also ISO/IEC 9945:2003 and IEEE Std 1003 wcstoimax wcstok - wcstol wcstold - wcstoll - wcstoul - wcstoull wcstoumax wcswcs - wcsxfrm wordexp wordfree diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/security.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/security.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/security.h 2007-07-20 14:29:43.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/security.h 2008-02-11 18:57:11.000000000 +0000 @@ -424,8 +424,8 @@ extern bool sec_acl (PACL acl, bool orig PSID sid2 = NO_SID, DWORD access2 = 0); -int __stdcall read_ea (HANDLE hdl, const char *file, const char *attrname, - char *buf, int len); -BOOL __stdcall write_ea (HANDLE hdl, const char *file, const char *attrname, - const char *buf, int len); +ssize_t __stdcall read_ea (HANDLE hdl, path_conv &pc, const char *name, + char *value, size_t size); +int __stdcall write_ea (HANDLE hdl, path_conv &pc, const char *name, + const char *value, size_t size, int flags); /* Note: sid1 is usually (read: currently always) the current user's diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/smallprint.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/smallprint.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/smallprint.cc 2007-12-13 12:55:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/smallprint.cc 2008-02-11 18:57:11.000000000 +0000 @@ -196,22 +196,15 @@ __small_vsprintf (char *dst, const char wfillin: { - ANSI_STRING as = { 0, 0, NULL }; - NTSTATUS status; + char *tmp; - if (current_codepage == ansi_cp) - status = RtlUnicodeStringToAnsiString (&as, us, TRUE); - else - status = RtlUnicodeStringToOemString (&as, us, TRUE); - if (!NT_SUCCESS (status)) + if (!sys_wcstombs_alloc (&tmp, HEAP_NOTHEAP, us->Buffer, + us->Length / sizeof (WCHAR))) { s = "invalid UNICODE_STRING"; goto fillin; } - for (i = 0; i < as.Length; ++i) - *dst++ = as.Buffer[i]; - if (current_codepage == ansi_cp) - RtlFreeAnsiString (&as); - else - RtlFreeOemString (&as); + for (i = 0; *tmp && i < n; i++) + *dst++ = *tmp++; + free (tmp); } break; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/spawn.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/spawn.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/spawn.cc 2007-12-16 23:34:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/spawn.cc 2008-02-11 18:57:11.000000000 +0000 @@ -529,5 +529,5 @@ loop: OSes because it's still heavily used by some users. They have been warned. */ - if (!strcasematch (wstname, "WinSta0")) + if (!ascii_strcasematch (wstname, "WinSta0")) { char sid[128]; @@ -943,10 +943,10 @@ av::fixup (const char *prog_arg, path_co { const char *p; - bool exeext = strcasematch (ext, ".exe"); - if (exeext && real_path.iscygexec () || strcasematch (ext, ".bat")) + bool exeext = ascii_strcasematch (ext, ".exe"); + if (exeext && real_path.iscygexec () || ascii_strcasematch (ext, ".bat")) return 0; if (!*ext && ((p = ext - 4) > real_path.get_win32 ()) - && (strcasematch (p, ".bat") || strcasematch (p, ".cmd") - || strcasematch (p, ".btm"))) + && (ascii_strcasematch (p, ".bat") || ascii_strcasematch (p, ".cmd") + || ascii_strcasematch (p, ".btm"))) return 0; while (1) @@ -1035,5 +1035,5 @@ just_shell: if (!pgm) { - if (strcasematch (ext, ".com")) + if (ascii_strcasematch (ext, ".com")) break; pgm = (char *) "/bin/sh"; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/strace.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/strace.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/strace.cc 2007-12-13 12:55:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/strace.cc 2008-02-11 18:57:11.000000000 +0000 @@ -168,5 +168,6 @@ strace::vsprntf (char *buf, const char * if (p != progname) strcpy (progname, p); - if ((p = strrchr (progname, '.')) != NULL && strcasematch (p, ".exe")) + if ((p = strrchr (progname, '.')) != NULL + && ascii_strcasematch (p, ".exe")) *p = '\000'; p = progname; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/strfuncs.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/strfuncs.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/strfuncs.cc 2007-11-08 14:24:01.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/strfuncs.cc 2008-02-11 18:57:11.000000000 +0000 @@ -11,14 +11,24 @@ details. */ #include "winsup.h" +#include #include #include #include +#include "cygerrno.h" +#include "security.h" +#include "path.h" +#include "fhandler.h" +#include "dtable.h" +#include "cygheap.h" codepage_type current_codepage = ansi_cp; +UINT active_codepage = 0; UINT get_cp () { - return current_codepage == ansi_cp ? GetACP() : GetOEMCP(); + if (!active_codepage) + codepage_init ("ansi"); + return active_codepage; } @@ -27,10 +37,10 @@ get_cp () matter what. */ int __stdcall -sys_wcstombs (char *tgt, int tlen, const WCHAR *src, int slen) +sys_wcstombs (char *tgt, int tlen, const PWCHAR src, int slen) { int ret; ret = WideCharToMultiByte (get_cp (), 0, src, slen, tgt, tlen, NULL, NULL); - if (ret) + if (ret && tgt) { ret = (ret < tlen) ? ret : tlen - 1; @@ -40,6 +50,37 @@ sys_wcstombs (char *tgt, int tlen, const } +/* Allocate a buffer big enough for the string, always including the + terminating '\0'. The buffer pointer is returned in *tgt_p, the return + value is the number of bytes written to the buffer, as usual. + The "type" argument determines where the resulting buffer is stored. + It's either one of the cygheap_types values, or it's "HEAP_NOTHEAP". + In the latter case the allocation uses simple calloc. + + Note that this code is shared by cygserver (which requires it via + __small_vsprintf) and so when built there plain calloc is the + only choice. */ int __stdcall -sys_mbstowcs (WCHAR *tgt, const char *src, int len) +sys_wcstombs_alloc (char **tgt_p, int type, const PWCHAR src, int slen) +{ + int ret; + + ret = WideCharToMultiByte (get_cp (), 0, src, slen, NULL, 0,NULL, NULL); + if (ret) + { + size_t tlen = (slen == -1 ? ret : ret + 1); + + if (type == HEAP_NOTHEAP) + *tgt_p = (char *) calloc (tlen, sizeof (char)); + else + *tgt_p = (char *) ccalloc ((cygheap_types) type, tlen, sizeof (char)); + if (!*tgt_p) + return 0; + ret = sys_wcstombs (*tgt_p, tlen, src, slen); + } + return ret; +} + +int __stdcall +sys_mbstowcs (PWCHAR tgt, const char *src, int len) { int res = MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len); @@ -47,4 +88,24 @@ sys_mbstowcs (WCHAR *tgt, const char *sr } +/* Same as sys_wcstombs_alloc, just backwards. */ +int __stdcall +sys_mbstowcs_alloc (PWCHAR *tgt_p, int type, const char *src) +{ + int ret; + + ret = MultiByteToWideChar (get_cp (), 0, src, -1, NULL, 0); + if (ret) + { + if (type == HEAP_NOTHEAP) + *tgt_p = (PWCHAR) calloc (ret, sizeof (WCHAR)); + else + *tgt_p = (PWCHAR) ccalloc ((cygheap_types) type, ret, sizeof (WCHAR)); + if (!*tgt_p) + return 0; + ret = sys_mbstowcs (*tgt_p, src, ret); + } + return ret; +} + static WCHAR hex_wchars[] = L"0123456789abcdef"; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/string.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/string.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/string.h 2007-12-13 12:55:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/string.h 2008-02-11 18:57:11.000000000 +0000 @@ -62,13 +62,8 @@ strechr (const char *s, int c) #ifdef __INSIDE_CYGWIN__ -/* Don't use. Not NLS aware. */ -#if 0 // Not NLS aware extern const char isalpha_array[]; -#undef strcasematch -#define strcasematch cygwin_strcasematch - static inline int -cygwin_strcasematch (const char *cs, const char *ct) +ascii_strcasematch (const char *cs, const char *ct) { register int __res; @@ -96,9 +91,6 @@ cygwin_strcasematch (const char *cs, con } -#undef strncasematch -#define strncasematch cygwin_strncasematch - static inline int -cygwin_strncasematch (const char *cs, const char *ct, size_t n) +ascii_strncasematch (const char *cs, const char *ct, size_t n) { register int __res; @@ -127,5 +119,5 @@ cygwin_strncasematch (const char *cs, co return __res; } -#else + #undef strcasecmp #define strcasecmp cygwin_strcasecmp @@ -138,5 +130,4 @@ int __stdcall cygwin_strncasecmp (const #define strcasematch(s1,s2) (!cygwin_strcasecmp ((s1),(s2))) #define strncasematch(s1,s2,n) (!cygwin_strncasecmp ((s1),(s2),(n))) -#endif #undef strlwr diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/syscalls.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/syscalls.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/syscalls.cc 2007-12-13 12:55:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/syscalls.cc 2008-02-13 17:30:15.000000000 +0000 @@ -1000,4 +1000,5 @@ isatty (int fd) return res; } +EXPORT_ALIAS (isatty, _isatty) /* Under NT, try to make a hard link using backup API. If that @@ -1460,6 +1461,6 @@ rename_append_suffix (path_conv &pc, con char buf[len + 5]; - if (strcasematch (path + len - 4, ".lnk") - || strcasematch (path + len - 4, ".exe")) + if (ascii_strcasematch (path + len - 4, ".lnk") + || ascii_strcasematch (path + len - 4, ".exe")) len -= 4; stpcpy (stpncpy (buf, path, len), suffix); @@ -1530,6 +1531,6 @@ rename (const char *oldpath, const char } if (oldpc.known_suffix - && (strcasematch (oldpath + olen - 4, ".lnk") - || strcasematch (oldpath + olen - 4, ".exe"))) + && (ascii_strcasematch (oldpath + olen - 4, ".lnk") + || ascii_strcasematch (oldpath + olen - 4, ".exe"))) old_explicit_suffix = true; @@ -1560,6 +1561,6 @@ rename (const char *oldpath, const char } if (newpc.known_suffix - && (strcasematch (newpath + nlen - 4, ".lnk") - || strcasematch (newpath + nlen - 4, ".exe"))) + && (ascii_strcasematch (newpath + nlen - 4, ".lnk") + || ascii_strcasematch (newpath + nlen - 4, ".exe"))) new_explicit_suffix = true; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/thread.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/thread.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/thread.cc 2007-12-13 12:55:41.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/thread.cc 2008-02-13 17:30:15.000000000 +0000 @@ -2641,6 +2641,22 @@ pthread_kill (pthread_t thread, int sig) si.si_pid = myself->pid; si.si_uid = myself->uid; - thread->cygtls->set_threadkill (); - int rval = sig ? sig_send (NULL, si, thread->cygtls) : 0; + int rval; + if (!thread->valid) + rval = ESRCH; + else if (sig) + { + thread->cygtls->set_threadkill (); + rval = sig_send (NULL, si, thread->cygtls); + } + else + switch (WaitForSingleObject (thread->win32_obj_id, 0)) + { + case WAIT_TIMEOUT: + rval = 0; + break; + default: + rval = ESRCH; + break; + } // unlock myself diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/uinfo.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/uinfo.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/uinfo.cc 2007-12-13 12:55:42.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/uinfo.cc 2008-02-11 18:57:11.000000000 +0000 @@ -368,5 +368,5 @@ cygheap_user::env_logsrv (const char *na const char *mydomain = domain (); const char *myname = winname (); - if (!mydomain || strcasematch (myname, "SYSTEM")) + if (!mydomain || ascii_strcasematch (myname, "SYSTEM")) return almost_null; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/wincap.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/wincap.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/wincap.cc 2007-12-13 12:55:42.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/wincap.cc 2008-02-13 17:30:15.000000000 +0000 @@ -41,4 +41,5 @@ static NO_COPY wincaps wincap_unknown = has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -70,4 +71,5 @@ static NO_COPY wincaps wincap_nt4 = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -99,4 +101,5 @@ static NO_COPY wincaps wincap_nt4sp4 = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -128,4 +131,5 @@ static NO_COPY wincaps wincap_2000 = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -157,4 +161,5 @@ static NO_COPY wincaps wincap_2000sp4 = has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -186,4 +191,5 @@ static NO_COPY wincaps wincap_xp = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -215,4 +221,5 @@ static NO_COPY wincaps wincap_xpsp1 = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -244,4 +251,5 @@ static NO_COPY wincaps wincap_xpsp2 = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:false, }; @@ -273,4 +281,5 @@ static NO_COPY wincaps wincap_2003 = { has_gaa_on_link_prefix:false, supports_all_posix_ai_flags:false, + has_restricted_stack_args:true, }; @@ -302,4 +311,5 @@ static NO_COPY wincaps wincap_vista = { has_gaa_on_link_prefix:true, supports_all_posix_ai_flags:true, + has_restricted_stack_args:false, }; @@ -389,5 +399,8 @@ wincapc::init () wow64 = is_wow64_proc; else - ((wincaps *)this->caps)->needs_count_in_si_lpres2 = false; + { + ((wincaps *)this->caps)->needs_count_in_si_lpres2 = false; + ((wincaps *)this->caps)->has_restricted_stack_args = false; + } __small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion, diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/wincap.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/wincap.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/wincap.h 2007-07-19 09:06:54.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/wincap.h 2008-02-13 17:30:15.000000000 +0000 @@ -40,4 +40,5 @@ struct wincaps unsigned has_gaa_on_link_prefix : 1; unsigned supports_all_posix_ai_flags : 1; + unsigned has_restricted_stack_args : 1; }; @@ -85,4 +86,5 @@ public: bool IMPLEMENT (has_gaa_on_link_prefix) bool IMPLEMENT (supports_all_posix_ai_flags) + bool IMPLEMENT (has_restricted_stack_args) #undef IMPLEMENT diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/winf.cc winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/winf.cc --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/winf.cc 2006-04-13 01:37:00.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/winf.cc 2008-02-11 18:57:11.000000000 +0000 @@ -142,5 +142,5 @@ av::unshift (const char *what, int conv) cygwin_conv_to_posix_path (what, buf); char *p = strchr (buf, '\0') - 4; - if (p > buf && strcasematch (p, ".exe")) + if (p > buf && ascii_strcasematch (p, ".exe")) *p = '\0'; what = buf; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/winsup.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/winsup.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/cygwin/winsup.h 2007-12-13 12:55:42.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/cygwin/winsup.h 2008-02-11 18:57:11.000000000 +0000 @@ -111,13 +111,27 @@ extern const char case_folded_upper[]; extern "C" DWORD WINAPI GetLastError (void); -enum codepage_type {ansi_cp, oem_cp}; +/* Codepage and multibyte string specific stuff. */ +enum codepage_type {ansi_cp, oem_cp, utf8_cp}; extern codepage_type current_codepage; +extern UINT active_codepage; +void codepage_init (const char *buf); UINT get_cp (); +bool is_cp_multibyte (UINT cp); +const unsigned char *next_char (UINT cp, const unsigned char *str, + const unsigned char *end); -int __stdcall sys_wcstombs(char *, int, const WCHAR *, int = -1) +/* Used as type by sys_wcstombs_alloc and sys_mbstowcs_alloc. For a + description see there. */ +#define HEAP_NOTHEAP -1 + +int __stdcall sys_wcstombs (char *, int, const PWCHAR, int = -1) + __attribute__ ((regparm(3))); +int __stdcall sys_wcstombs_alloc (char **, int, const PWCHAR, int = -1) __attribute__ ((regparm(3))); -int __stdcall sys_mbstowcs(WCHAR *, const char *, int) +int __stdcall sys_mbstowcs (PWCHAR, const char *, int) + __attribute__ ((regparm(3))); +int __stdcall sys_mbstowcs_alloc (PWCHAR *, int, const char *) __attribute__ ((regparm(3))); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/mingw/Makefile.in winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/mingw/Makefile.in --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/mingw/Makefile.in 2007-11-27 13:27:14.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/mingw/Makefile.in 2008-02-11 18:57:11.000000000 +0000 @@ -1,4 +1,4 @@ # Makefile.in for the winsup/mingw directory. -# Copyright (c) 1995, 1996, 1997, 1998 Cygnus Solutions +# Copyright (c) 1995-2008, 1996, 1997, 1998 Cygnus Solutions # This program is free software; you can redistribute it and/or modify @@ -189,4 +189,8 @@ LIBS = libcrtdll.a \ libcoldname.a \ libmoldname.a libmoldnamed.a \ + libmoldname70.a libmoldname70d.a \ + libmoldname71.a libmoldname71d.a \ + libmoldname80.a libmoldname80d.a \ + libmoldname90.a libmoldname90d.a \ $(LIBM_A) \ libmingwthrd.a @@ -302,7 +306,7 @@ libcoldname.a: moldname-crtdll.def $(MOL $(RANLIB) $@ -libmoldname.a: moldname-msvcrt.def $(MOLD_OBJS) +libmoldname.a libmoldnamed.a: moldname-msvcrt.def $(MOLD_OBJS) $(DLLTOOL) --as $(AS) -k -U \ - --dllname msvcrt.dll \ + --dllname msvcrt$(@:libmoldname%a=%)dll \ --def moldname-msvcrt.def \ --output-lib $@ @@ -310,7 +314,7 @@ libmoldname.a: moldname-msvcrt.def $(MOL $(RANLIB) $@ -libmoldnamed.a: moldname-msvcrt.def $(MOLD_OBJS) +libmoldname70.a libmoldname70d.a libmoldname71.a libmoldname71d.a libmoldname80.a libmoldname80d.a libmoldname90.a libmoldname90d.a: moldname-msvcrt.def $(MOLD_OBJS) $(DLLTOOL) --as $(AS) -k -U \ - --dllname msvcrtd.dll \ + --dllname msvcr$(@:libmoldname%a=%)dll \ --def moldname-msvcrt.def \ --output-lib $@ diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/ras.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/ras.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/ras.h 2008-01-29 21:16:08.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/ras.h 2008-02-11 18:57:12.000000000 +0000 @@ -36,5 +36,5 @@ typedef unsigned long ULONG_PTR, *PULONG #define RAS_MaxUserData 200 #define RAS_MaxReplyMessage 1024 -#define RAX_MaxDnsSuffix 256 +#define RAS_MaxDnsSuffix 256 #define RDEOPT_UsePrefixSuffix 0x00000001 #define RDEOPT_PausedStates 0x00000002 @@ -74,4 +74,16 @@ typedef unsigned long ULONG_PTR, *PULONG #define RASEO_UseLogonCredentials 0x00004000 #define RASEO_PromoteAlternates 0x00008000 +#if (WINVER >= 0x501) +#define RASEO2_SecureFileAndPrint 0x00000001 +#define RASEO2_SecureClientForMSNet 0x00000002 +#define RASEO2_DontNegotiateMultilink 0x00000004 +#define RASEO2_DontUseRasCredentials 0x00000008 +#define RASEO2_UsePreSharedKey 0x00000010 +#define RASEO2_Internet 0x00000020 +#define RASEO2_DisableNbtOverIP 0x00000040 +#define RASEO2_UseGlobalDeviceSettings 0x00000080 +#define RASEO2_ReconnectIfDropped 0x00000100 +#define RASEO2_SharePhoneNumbers 0x00000200 +#endif #define RASNP_NetBEUI 0x00000001 #define RASNP_Ipx 0x00000002 @@ -546,4 +558,14 @@ typedef struct tagRASENTRYW { DWORD dwVpnStrategy; #endif +#if (WINVER >= 0x501) + DWORD dwfOptions2; + DWORD dwfOptions3; + WCHAR szDnsSuffix[RAS_MaxDnsSuffix]; + DWORD dwTcpWindowSize; + WCHAR szPrerequisitePbk[MAX_PATH]; + WCHAR szPrerequisiteEntry[RAS_MaxEntryName + 1]; + DWORD dwRedialCount; + DWORD dwRedialPause; +#endif } RASENTRYW, *LPRASENTRYW; @@ -593,4 +615,14 @@ typedef struct tagRASENTRYA { DWORD dwVpnStrategy; #endif +#if (WINVER >= 0x501) + DWORD dwfOptions2; + DWORD dwfOptions3; + CHAR szDnsSuffix[RAS_MaxDnsSuffix]; + DWORD dwTcpWindowSize; + CHAR szPrerequisitePbk[MAX_PATH]; + CHAR szPrerequisiteEntry[RAS_MaxEntryName + 1]; + DWORD dwRedialCount; + DWORD dwRedialPause; +#endif } RASENTRYA, *LPRASENTRYA; diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/specstrings.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/specstrings.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/specstrings.h 1970-01-01 00:00:00.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/specstrings.h 2008-02-13 17:30:16.000000000 +0000 @@ -0,0 +1,22 @@ +#ifndef _SPECSTRINGS_H +#define _SPECSTRINGS_H +#if __GNUC__ >=3 +#pragma GCC system_header +#endif + +/* __in and __out currently conflict with libstdc++, use with caution */ + +#define __in +#define __inout +#define __in_opt +#define __in_bcount(x) +#define __in_ecount(x) +#define __out +#define __out_ecount_part(x) +#define __out_ecount_part(x,y) +#define __struct_bcount(x) +#define __field_ecount_opt(x) +#define __out_bcount_opt(x) + +#endif + diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/windef.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/windef.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/windef.h 2007-02-18 08:08:12.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/windef.h 2008-02-13 17:30:16.000000000 +0000 @@ -56,5 +56,5 @@ extern "C" { #endif -/* Pseudo modifiers for parameters +/* Pseudo modifiers for parameters We don't use these unnecessary defines in the w32api headers. Define them by default since that is what people expect, but allow users @@ -159,5 +159,5 @@ extern "C" { #ifndef NONAMELESSUNION #ifdef __GNUC__ -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) #define _ANONYMOUS_UNION __extension__ #define _ANONYMOUS_STRUCT __extension__ diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/winnt.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/winnt.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/winnt.h 2007-07-18 12:52:45.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/winnt.h 2008-02-11 18:57:12.000000000 +0000 @@ -3546,4 +3546,13 @@ typedef enum { } POWER_ACTION, *PPOWER_ACTION; +#if (_WIN32_WINNT >= 0x0600) +typedef enum { + PoAc = 0, + PoDc = 1, + PoHot = 2, + PoConditionMaximum = 3 +} SYSTEM_POWER_CONDITION, *PSYSTEM_POWER_CONDITION; +#endif + typedef enum _DEVICE_POWER_STATE { PowerDeviceUnspecified, diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/winuser.h winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/winuser.h --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/include/winuser.h 2007-07-12 11:22:31.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/include/winuser.h 2008-02-11 18:57:12.000000000 +0000 @@ -1101,7 +1101,9 @@ extern "C" { #define PBT_APMOEMEVENT 11 #define PBT_APMRESUMEAUTOMATIC 18 - #define PBTF_APMRESUMEFROMFAILURE 1 #endif +#if (_WIN32_WINNT >= 0x0600) +#define PBT_POWERSETTINGCHANGE 32787 +#endif /* end pbt.h */ @@ -3368,5 +3370,33 @@ typedef struct { } #define POINTTOPOINTS(p) ((POINTS)MAKELONG((p).x,(p).y)) + +#ifndef _LPCGUID_DEFINED +#define _LPCGUID_DEFINED +typedef const GUID *LPCGUID; +#endif + +#if (_WIN32_WINNT >= 0x0600) +#define DEVICE_NOTIFY_WINDOW_HANDLE 0 +#define DEVICE_NOTIFY_SERVICE_HANDLE 1 + +typedef HANDLE HPOWERNOTIFY; + +typedef struct { + GUID PowerSetting; + DWORD DataLength; + UCHAR Data[1]; +} POWERBROADCAST_SETTING, *PPOWERBROADCAST_SETTING; +extern const GUID GUID_POWERSCHEME_PERSONALITY; +extern const GUID GUID_MIN_POWER_SAVINGS; +extern const GUID GUID_MAX_POWER_SAVINGS; +extern const GUID GUID_TYPICAL_POWER_SAVINGS; +extern const GUID GUID_ACDC_POWER_SOURCE; +extern const GUID GUID_BATTERY_PERCENTAGE_REMAINING; +extern const GUID GUID_IDLE_BACKGROUND_TASK; +extern const GUID GUID_SYSTEM_AWAYMODE; +extern const GUID GUID_MONITOR_POWER_ON; +#endif + WINUSERAPI HKL WINAPI ActivateKeyboardLayout(HKL,UINT); WINUSERAPI BOOL WINAPI AdjustWindowRect(LPRECT,DWORD,BOOL); @@ -3891,4 +3921,7 @@ WINUSERAPI HDEVNOTIFY WINAPI RegisterDev WINUSERAPI HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE,LPVOID,DWORD); #endif +#if (_WIN32_WINNT >= 0x0600) +WINUSERAPI HPOWERNOTIFY WINAPI RegisterPowerSettingNotification(HANDLE,LPCGUID,DWORD); +#endif WINUSERAPI BOOL WINAPI RegisterHotKey(HWND,int,UINT,UINT); #if (_WIN32_WINNT >= 0x0501) @@ -4038,4 +4071,7 @@ WINUSERAPI BOOL WINAPI UnregisterClassW( WINUSERAPI BOOL WINAPI UnregisterDeviceNotification(HANDLE); #endif +#if (_WIN32_WINNT >= 0x0600) +WINUSERAPI BOOL WINAPI UnregisterPowerSettingNotification(HPOWERNOTIFY); +#endif WINUSERAPI BOOL WINAPI UnregisterHotKey(HWND,int); WINUSERAPI BOOL WINAPI UpdateWindow(HWND); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/bthprops.def winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/bthprops.def --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/bthprops.def 1970-01-01 00:00:00.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/bthprops.def 2008-01-30 09:39:16.000000000 +0000 @@ -0,0 +1,8 @@ +LIBRARY BTHPROPS.CPL +EXPORTS +BluetoothFindFirstRadio@8 +BluetoothFindFirstDevice@8 +BluetoothFindNextDevice@8 +BluetoothFindDeviceClose@4 +BluetoothFindNextRadio@8 +BluetoothFindRadioClose@4 diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/Makefile.in winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/Makefile.in --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/Makefile.in 2006-11-02 00:54:46.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/Makefile.in 2008-02-11 18:57:12.000000000 +0000 @@ -127,5 +127,5 @@ UUID_OBJS = mshtml-uuid.o msxml-uuid.o u exdisp-uuid.o mlang-uuid.o objidl-uuid.o cguid-uuid.o \ olectlid-uuid.o ativscp-uuid.o urlmon-uuid.o hlink-uuid.o \ - hlguids-uuid.o extras-uuid.o devguid.o + hlguids-uuid.o extras-uuid.o devguid.o power-uuid.o EXTRA_OBJS = shell32.o scrnsave.o scrnsavw.o largeint.o \ $(UUID_OBJS) ws2_32.o @@ -135,5 +135,5 @@ UUID_SOURCES = mshtml-uuid.c msxml-uuid. exdisp-uuid.c mlang-uuid.c objidl-uuid.c cguid-uuid.c \ olectlid-uuid.c ativscp-uuid.c urlmon-uuid.c hlink-uuid.c \ - hlguids-uuid.c extras-uuid.c devguid.c + hlguids-uuid.c extras-uuid.c devguid.c power-uuid.c SOURCES = scrnsave.c shell32.c largeint.c $(UUID_SOURCES)\ res.rc test.c ws2_32.c diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/power-uuid.c winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/power-uuid.c --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/power-uuid.c 1970-01-01 00:00:00.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/power-uuid.c 2008-01-29 21:18:49.000000000 +0000 @@ -0,0 +1,18 @@ +/* power-uuid.c */ +/* Generate GUIDs for OLE Accessibility interfaces */ + +/* All IIDs defined in this file were found at "Registering for Power Events" on MSDN here: + * http://msdn2.microsoft.com/en-us/library/aa373195.aspx + */ + +#define INITGUID +#include +DEFINE_GUID(GUID_POWERSCHEME_PERSONALITY, 0x245d8541, 0x3943, 0x4422, 0xb0, 0x25, 0x13, 0xA7, 0x84, 0xF6, 0x79, 0xB7); +DEFINE_GUID(GUID_MIN_POWER_SAVINGS, 0x8c5e7fda, 0xe8bf, 0x4a96, 0x9a, 0x85, 0xa6, 0xe2, 0x3a, 0x8c, 0x63, 0x5c); +DEFINE_GUID(GUID_MAX_POWER_SAVINGS, 0xa1841308, 0x3541, 0x4fab, 0xbc, 0x81, 0xf7, 0x15, 0x56, 0xf2, 0x0b, 0x4a); +DEFINE_GUID(GUID_TYPICAL_POWER_SAVINGS, 0x381b4222, 0xf694, 0x41f0, 0x96, 0x85, 0xff, 0x5b, 0xb2, 0x60, 0xdf, 0x2e); +DEFINE_GUID(GUID_ACDC_POWER_SOURCE, 0x5d3e9a59, 0xe9D5, 0x4b00, 0xa6, 0xbd, 0xff, 0x34, 0xff, 0x51, 0x65, 0x48); +DEFINE_GUID(GUID_BATTERY_PERCENTAGE_REMAINING, 0xa7ad8041, 0xb45a, 0x4cae, 0x87, 0xa3, 0xee, 0xcb, 0xb4, 0x68, 0xa9, 0xe1); +DEFINE_GUID(GUID_IDLE_BACKGROUND_TASK, 0x515c31d8, 0xf734, 0x163d, 0xa0, 0xfd, 0x11, 0xa0, 0x8c, 0x91, 0xe8, 0xf1); +DEFINE_GUID(GUID_SYSTEM_AWAYMODE, 0x98a7f580, 0x01f7, 0x48aa, 0x9c, 0x0f, 0x44, 0x35, 0x2c, 0x29, 0xe5, 0xC0); +DEFINE_GUID(GUID_MONITOR_POWER_ON, 0x02731015, 0x4510, 0x4526, 0x99, 0xe6, 0xe5, 0xa1, 0x7e, 0xbd, 0x1a, 0xea); diff -p -N -d -r -U2 winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/user32.def winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/user32.def --- winsup-src-20080129/cygwin-snapshot-20080129-1/winsup/w32api/lib/user32.def 2007-02-18 08:08:12.000000000 +0000 +++ winsup-src-20080213/cygwin-snapshot-20080213-1/winsup/w32api/lib/user32.def 2008-02-11 18:57:12.000000000 +0000 @@ -485,4 +485,5 @@ RegisterClipboardFormatW@4 RegisterDeviceNotificationA@12 RegisterDeviceNotificationW@12 +RegisterPowerSettingNotification@12 RegisterHotKey@16 RegisterRawInputDevices@12 @@ -614,4 +615,5 @@ UnregisterClassA@8 UnregisterClassW@8 UnregisterDeviceNotification@4 +UnregisterPowerSettingNotification@4 UnregisterHotKey@8 UpdateLayeredWindow@36