Commit Graph

9978 Commits

Author SHA1 Message Date
Corinna Vinschen 68bb3deabd Cygwin: fix GB18030 support
The changes to support GB18030 were insufficient and the underlying
Windows conversion functions just failed. Fix how the Windows functions
are called for GB18030.

Fixes: 5da71b6059 ("Cygwin: add support for GB18030 codeset")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-31 22:39:09 +02:00
Corinna Vinschen 4f78215c86 Cygwin: belatedly bump CYGWIN_VERSION_API_MINOR for new posix_spawn funcs
Commit c743751aaf ("Cygwin: Export
posix_spawn_file_actions_add{f}chdir_np")
added two new functions but we forgot to bump the API version.
Catch up.

Fixes: c743751aaf ("Cygwin: Export posix_spawn_file_actions_add{f}chdir_np")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-31 22:39:09 +02:00
Corinna Vinschen a13b0b7aea Cygwin: fnmatch: fix range comparison in C locale
Commit c36064bbd0 introduced operating on character pointers
instead of operating on characters, to allow collating symbols.
This patch neglected to change the expression for range
comparison in case we're in the C locale.  Thus it suddenly
compared pointers instead of characters.  Fix that.

Fixes: c36064bbd0 ("Cygwin: fnmatch: support collating symbols in [. .] brackets")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-27 21:57:49 +02:00
Corinna Vinschen 4fbcc8c5fe Rename _NL_CTYPE_OUTDIGITSx_MB/WC to _NL_CTYPE_OUTDIGITx_MB/WC
The extended _NL_foo names were originally designed after their GLibc
counterparts.  However, the OUTDIGIT macros were accidentally defined as
OUTDIGITS, plural.  Fix them.

Fixes: d47d5b850b ("Extend locale support to maintain wide char values of native strings")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26 19:55:26 +02:00
Corinna Vinschen fcc87263c4 Cygwin: add AT_EMPTY_PATH fix to release message
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26 15:14:55 +02:00
Corinna Vinschen f48ce81122 Cygwin: Fix and streamline AT_EMPTY_PATH handling
The GLIBC extension AT_EMPTY_PATH allows the functions fchownat
and fstatat to operate on dirfd alone, if the given pathname is an
empty string.  This also allows to operate on any file type, not
only directories.

Commit fa84aa4dd2 broke this.  It only allows dirfd to be a
directory in calls to these two functions.

Fix that by handling AT_EMPTY_PATH right in gen_full_path_at.
A valid dirfd and an empty pathname is now a valid combination
and, noticably, this returns a valid path in path_ret.  That
in turn allows to remove the additional path generation code
from the callers.

Fixes: fa84aa4dd2 ("Cygwin: fix errno values set by readlinkat")
Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Tested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26 15:14:33 +02:00
Corinna Vinschen 0051091999 Cygwin: use new _AT_NULL_PATHNAME_ALLOWED flag
Convert gen_full_path_at to take flag values from the caller, rather
than just a bool indicating that empty paths are allowed.  This is in
preparation of a better AT_EMPTY_PATH handling in a followup patch.

Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26 15:14:27 +02:00
Corinna Vinschen ae03aa7303 Cygwin: gen_full_path_at: drop never reached code
The check if the local variable p is NULL is useless.  The preceeding
code always sets p to a valid pointer, or it crashes if path_ret is
invalid (which would be a bug in Cygwin).

Fixes: c57b57e5c4 ("* cygwin.din: Sort.")
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26 15:13:47 +02:00
Corinna Vinschen 971d2dffea Cygwin: get_posix_access: do not merge permissions for just created files
When creating the POSIX ACL rewrite, the code merging permissions from
everyone/group to group/user ACEs was accidentally called for newly
generated files as well.

This could result in broken permissions, if umask used unusual values
like "0100", granted permissions to everyone/group not granted to
group/user.

Make sure to skip permission merging if the file got just created and
we only want to set correct permissions for the first time.

Fixes: bc444e5aa4 ("Reapply POSIX ACL changes.")
Reported-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-21 21:57:44 +02:00
Jon Turney 8b0b719d49
Cygwin: Fix uninitialized use of fh in strace output in stat_worker()
Move strace output to fix uninitalized use of fh introduced in previous commit.

../../../../src/winsup/cygwin/syscalls.cc: In function ‘int stat_worker(path_conv&, stat*)’:
../../../../src/winsup/cygwin/syscalls.cc:1971:69: error: ‘fh’ may be used uninitialized [-Werror=maybe-uninitialized]

Fixes: 42b44044b3 ("Cygwin: Fix Windows file handle leak in stat("file", -1)")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-07-21 14:24:08 +01:00
Jon Turney 42b44044b3
Cygwin: Fix Windows file handle leak in stat("file", -1)
Don't leak a Windows file handle if stat() is called with a valid
filename, but invalid stat buffer pointer.

We do not destroy fh (which closes a Windows handle it has opened) if an
exception happens in the __try block.

Avoid this by re-ordering things so that we don't construct the fhandler
object until after we've attempted to use the struct stat buffer.

Fixes: 73151c54d5 ("syscalls.cc (stat_worker): Don't call build_fh_pc with invalid pc.")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-07-21 13:23:33 +01:00
Corinna Vinschen a02144808c Cygwin: don't wait infinitely on a pthread cancel event
Starting with commit 42faed4128 ("* thread.h (class pthread): Add bool
member canceled."), pthread::testcancel waits infinitely on cancel_event
after it checked if the canceled variable is set.  However, this might
introduce a deadlock, if the thread calling pthread_cancel is terminated
after setting canceled to true, but before calling SetEvent on cancel_event.

In fact, it's not at all necessary to wait infinitely.  By definition,
the thread is only canceled if cancel_event is set.  The canceled
variable is just a helper to speed up code.  We can safely assume that
the thread hasn't been canceled yet, if canceled is set, but cancel_event
isn't.

Fixes: 42faed4128 ("* thread.h (class pthread): Add bool member canceled.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-18 22:21:36 +02:00
Jon Turney 89e80d414b
Cygwin: Restore signal handlers on thread cancellation during system()
Add back the restoration of signal handlers modified during system() on
thread cancellation.

Removed in 3cb9da14 which describes it as 'ill-conceived' (additional
context doesn't appear to be available).

We use the internal implementation helpers for the pthread cleanup
chain, so we can neatly tuck it inside the object, and keep the point
when we restore the signal handlers the same. (The
pthread_cleanup_push/pop() functions are implemented as macros which
must appear in the same lexical scope.)

Fixes: 3cb9da1461 ("Put signals on hold and use system_call_cleanup
class to set and restore signals rather than doing it prior to to
running the program.  Remove the ill-conceived pthread_cleanup stuff.")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-07-18 16:43:36 +01:00
Jon Turney c431f6b7fe
Cygwin: pthread: Take note of schedparam in pthread_create
Take note of schedparam in any pthread_attr_t passed to pthread_create.

postcreate() (racily, after the thread is actually created), sets the
scheduling priority if it's inherited, but precreate() doesn't store any
scheduling priority explicitly set via a non-default attr to
pthread_create, so schedparam.sched_priority has the default value of 0.

(I think this is another long-standing bug exposed by 4b51e4c1.  Now we
don't lie about the actual thread priority, it's apparent it's not
really being set in this case.)

Fixes testcase priority2.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-07-18 14:18:45 +01:00
Jon Turney e8c1a579cd
Cygwin: testsuite: Setup test prereqs in 'installation' the tests run in
Do some setup in the Cygwin 'installation' at testsuite/testinst/:

* Ensure /tmp exists

* Use BusyBox to provide executables needed by tests which use system()
(sh, sleep, ls)

This enables tests which use system(), or require /tmp to exist to pass.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-07-14 14:02:37 +01:00
Mark Geisert c836d26d76 Cygwin: Update release/3.4.8 for latest <sys/cpuset.h> commit 2023-07-13 12:15:37 +02:00
Mark Geisert 3f2790e044 Cygwin: Make gcc-specific code in <sys/cpuset.h> compiler-agnostic
The current version of <sys/cpuset.h> cannot be compiled by Clang due to
the use of builtin versions of malloc, free, and memset.  Their presence
here was a dubious optimization anyway, so their usage has been
converted to standard library functions.

The use of __builtin_popcountl remains because Clang implements it just
like gcc does.  If/when some other compiler (Rust? Go?) runs into this
issue we can deal with specialized handling then.

The "#include <sys/cdefs>" here to define __inline can be removed since
both of the new includes sub-include it.

Addresses: https://cygwin.com/pipermail/cygwin/2023-July/253927.html
Fixes: 9cc910dd33a5 (Cygwin: Make <sys/cpuset.h> safe for c89 compilations)
Signed-off-by: Mark Geisert <mark@maxrnd.com>
2023-07-10 10:42:24 +02:00
Takashi Yano b03601a671 Cygwin: fstat(): Fix st_rdev returned by fstat() for /dev/tty.
While st_rdev returned by fstat() for /dev/tty should be FH_TTY,
the current cygwin1.dll returns FH_PTYS+minor or FH_CONS+minor.
Similarly, fstat() does not return correct value for /dev/console,
/dev/conout, /dev/conin or /dev/ptmx.

This patch fixes the issue by:
1) Introduce dev_referred_via in fhandler_termios.
2) Add new argument, which has dev_t value referred by open(),
  for constructors of fhandler_pty_slave and fhandler_pty_master to
  set the value of dev_referred_via.
3) Set st_rdev using dev_referred_via in fhandler_termios::fstat()
  if it is available.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-07-08 08:03:22 +09:00
Takashi Yano 3edb55af82 Cygwin: stat(): Fix "Bad address" error on stat() for /dev/tty.
As reported in
https://cygwin.com/pipermail/cygwin/2023-June/253888.html,
"Bad address" error occurs when stat() is called after the commit
3721a756b0 ("Cygwin: console: Make the console accessible from
other terminals.").

There are two problems in the current code. One is fhandler_console::
fstat() calls get_ttyp()->getsid(). However, fh_alloc() in dtable.cc
omits to initialize the fhandler_console instance when stat() is
called. Due to this, get_ttyp() returns NULL and access violation
occurs. The other problem is fh_alloc() assigns fhandler_console
even if the CTTY is not a console. So the first problem above occurs
even if the CTTY is a pty.

This patch fixes the issue by:
1) Call set_unit() to initialize _tc if the get_ttyp() returns NULL.
2) Assign fhandler_pty_slave for /dev/tty if CTTY is a pty in fh_alloc().

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible
  from other terminals.").
Fixes: 23771fa1f7 ("dtable.cc (fh_alloc): Make different decisions
  when generating fhandler for not-opened devices. Add kludge to deal
  with opening /dev/tty.")
Reported-by: Bruce Jerrick <bmj001@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-07-08 08:03:16 +09:00
Corinna Vinschen e38f91d5a9 Cygwin: Fix latest release message being in the wrong release file.
Fixes: 6422e76637 ("Cygwin: Make <sys/cpuset.h> safe for c89 compilations")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-04 16:50:37 +02:00
Mark Geisert 6422e76637 Cygwin: Make <sys/cpuset.h> safe for c89 compilations
Four modifications to include/sys/cpuset.h:
* Change C++-style comments to C-style also supported by C++
* Change "inline" to "__inline" on code lines
* Add "#include <sys/cdefs.h>" to make sure __inline is defined
* Don't declare loop variables on for-loop init clauses

Tested by first reproducing the reported issue with home-grown test
programs by compiling with gcc option "-std=c89", then compiling again
using the modified <sys/cpuset.h>. Other "-std=" options tested too.

Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")
Signed-off-by: Mark Geisert <mark@maxrnd.com>
2023-07-04 15:39:12 +02:00
Takashi Yano bfb16b0ede Cygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthread().
Currently, _my_tls.tid is set to pthread_null if pthread::self()
is called before pthread::init_mainthread(). As a result, pthread::
init_mainthread() does not set _my_tls.tid appropriately. Due to
this, pthread_join() fails in LDAP environment if the program is
the first program which loads cygwin1.dll.

https://cygwin.com/pipermail/cygwin/2023-June/253792.html

With this patch, _my_tls.tid is re-initialized in pthread::
init_mainthread() if it is pthread_null.

Reported-by: Mümin A. <muminaydin06@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-06-27 22:10:43 +09:00
Brian Inglis 6604db8b80 fhandler/proc.cc: use wincap.has_user_shstk
In test for AMD/Intel Control flow Enforcement Technology user mode
shadow stack support replace Windows version tests with test of wincap
member addition has_user_shstk with Windows version dependent value

Fixes: 41fdb869f9 ("fhandler/proc.cc(format_proc_cpuinfo): Add Linux 6.3 cpuinfo")
Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
2023-06-20 10:06:56 +02:00
Brian Inglis 1c4a00962f wincap.cc: set wincap member has_user_shstk true for 2004+
Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
2023-06-20 10:06:56 +02:00
Brian Inglis 293785382c wincap.h: add wincap member has_user_shstk
Indicate support of user mode hardware-enforced shadow stack

Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
2023-06-20 10:06:56 +02:00
Philippe Cerfon 0480315010 Cygwin: use new XATTR_{NAME,SIZE}_MAX instead of MAX_EA_{NAME,VALUE}_LEN
Signed-off-by: Philippe Cerfon <philcerf@gmail.com>
2023-06-16 21:44:41 +02:00
Philippe Cerfon 538b29a8da Cygwin: export XATTR_{NAME,SIZE,LIST}_MAX
These are used for example by CPython.

Signed-off-by: Philippe Cerfon <philcerf@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-06-16 21:44:41 +02:00
Johannes Schindelin 80ff7bc26c Do not rely on `getenv ("HOME")`'s path conversion
In the very early code path where `dll_crt0_1 ()` calls
`user_shared->initialize ()`, the Cygwin runtime calls `internal_pwsid ()`
to initialize the user name in preparation for reading the `fstab` file.

In case `db_home: env` is defined in `/etc/nsswitch.conf`, we need to
look at the environment variable `HOME` and use it, if set.

When all of this happens, though, the `pinfo_init ()` function has had no
chance to run yet (and therefore, `environ_init ()`). At this stage,
therefore, `getenv ()`'s `findenv_func ()` call still finds `getearly ()`
and we get the _verbatim_ value of `HOME`. That is, the Windows form.
But we need the "POSIX" form.

To add insult to injury, later calls to `getpwuid (getuid ())` will
receive a cached version of the home directory via
`cygheap->pg.pwd_cache.win.find_user ()` thanks to the first
`internal_pwsid ()` call caching the result via
`add_user_from_cygserver ()`, read: we will never receive the converted
`HOME` but always the Windows variant.

So, contrary to the assumptions made in 27376c60a9 (Allow deriving the
current user's home directory via the HOME variable, 2023-03-28), we
cannot assume that `getenv ("HOME")` returned a "POSIX" path.

This is a real problem. Even setting aside that common callers of
`getpwuid ()` (such as OpenSSH) are unable to handle Windows paths in the
`pw_dir` attribute, the Windows path never makes it back to the caller
unscathed. The value returned from `fetch_home_env ()` is not actually
used as-is. Instead, the `fetch_account_from_windows ()` method uses it
to write a pseudo `/etc/passwd`-formatted line that is _then_ parsed via
the `pwdgrp::parse_passwd ()` method which sees no problem with
misinterpreting the colon after the drive letter as a field separator of
that `/etc/passwd`-formatted line, and instead of a Windows path, we now
have a mere drive letter.

Let's detect when the `HOME` value is still in Windows format in
`fetch_home_env ()`, and convert it in that case.

For good measure, interpret this "Windows format" not only to include
absolute paths with drive prefixes, but also UNC paths.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-06-06 15:18:53 +02:00
Johannes Schindelin e9dd5d8f25 uinfo: special-case IIS APPPOOL accounts
The account under which Azure Web Apps run is an IIS APPOOL account that
is generated on the fly.

These are special because the virtual machines on which thes Apps run
are not domain-joined, yet the accounts are domain accounts.

To support the use case where such a Web App needs to call `ssh` (e.g.
to deploy from a Git repository that is accessible only via SSH), we do
need OpenSSH's `getpwuid (getuid ())` invocation to work.

But currently it does not. Concretely, `getuid ()` returns -1 for these
accounts, and OpenSSH fails to find the correct home directory
(_especially_ when that home directory was overridden via a `db_home:
env` line in `/etc/nsswitch.conf`).

This can be verified e.g. in a Kudu console (for details about Kudu
consoles, see https://github.com/projectkudu/kudu/wiki/Kudu-console):
the domain is `IIS APPPOOL`, the account name is the name of the Azure
Web App, the SID starts with 'S-1-5-82-`, and
`pwdgrp::fetch_account_from_windows()` runs into the code path where
"[...] the domain returned by LookupAccountSid is not our machine name,
and if our machine is no domain member, we lose.  We have nobody to ask
for the POSIX offset."

Since these IIS APPPOOL accounts are relatively similar to AzureAD
accounts in this scenario, let's imitate the latter to support also the
former.

Reported-by: David Ebbo <david.ebbo@gmail.com>
Helped-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-06-06 15:18:53 +02:00
Takashi Yano a903878948 Cygwin: pty: Additional fix for transferring input at exit.
The commit 9fc746d17d does not fix transferring input at exit
appropriately. If the more than one non-cygwin apps are executed
simultaneously and one of them is terminated, the pty master failed
to send input to the other non-cygwin apps. This patch fixes that.

Fixes: 9fc746d17d ("Cygwin: pty: Fix transferring type-ahead input between input pipes.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-06-02 10:19:18 +09:00
Takashi Yano 9fc746d17d Cygwin: pty: Fix transferring type-ahead input between input pipes.
After the commit e5fcc5837c, transferring type-ahead input between
the pipe for cygwin app and the pipe for non-cygwin app will not be
done appropriately when the stdin of the non-cygwin app is not pty.
Due to this issue, sometimes the keyboard input might be lost which
should be sent to cygwin app. This patch fixes the issue.

Fixes: e5fcc5837c ("Cygwin: pty: Fix reading CONIN$ when stdin is not a pty.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-06-01 20:00:45 +09:00
Johannes Schindelin 4840a56325
Cygwin: Adjust CWD magic to accommodate for the latest Windows previews
Reportedly Windows 11 build 25*** from Insider changed the current
working directory logic a bit, and Cygwin's "magic" (or:
"technologically sufficiently advanced") code needs to be adjusted
accordingly.

This fixes https://github.com/git-for-windows/git/issues/4429

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-05-24 20:44:52 +01:00
Brian Inglis 41fdb869f9
fhandler/proc.cc(format_proc_cpuinfo): Add Linux 6.3 cpuinfo
cpuid    0x00000007:0 ecx:7 shstk Shadow Stack support & Windows [20]20H1/[20]2004+
		    => user_shstk User mode program Shadow Stack support
AMD SVM  0x8000000a:0 edx:25 vnmi virtual Non-Maskable Interrrupts
Sync AMD 0x80000008:0 ebx flags across two output locations
2023-05-12 16:12:11 +01:00
Biswapriyo Nath 3bee68248f
Cygwin: Fix compiling with w32api-headers v11.0.0
This solves redefinition of FILE_CS_FLAG_CASE_SENSITIVE_DIR in winnt.h
and fixes the following compiler errors

ntdll.h:523:3: error: expected identifier before numeric constant
  523 |   FILE_CS_FLAG_CASE_SENSITIVE_DIR                       = 0x01
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ntdll.h:522:1: note: to match this ‘{’
  522 | {
      | ^
2023-05-01 11:40:52 +01:00
Corinna Vinschen c3798a2f7d Cygwin: locales: drop unused has_modifier macro
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-24 22:41:41 +02:00
Corinna Vinschen 48ae24fd81 Cygwin: locales: ignore @cjkwide and @cjksingle just like @cjknarrow
When the @cjkwide and @cjksingle modifiers have been added, the
patches missed to add checks for the new modifiers in the Cygwin
locale code.  Along the same lines, commit c3e7f7609e forgot to
add a test for @cjksingle.

Merge check for cjk* modifiers into a macro set andf use that
throughout. Fix comments.

Fixes: f92f048528 ("Locale modifier @cjkwide to adjust ambiguous-width in non-CJK locales")
Fixes: c8204b1069 ("Locale modifier "@cjksingle" to enforce single-width CJK width.")
Fixes: c3e7f7609e ("Cygwin: locales: fix behaviour for @cjk* and @euro locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-24 22:41:41 +02:00
Corinna Vinschen da40bd6eaf Cygwin: posix_spawnp: don't fallback to sh
Per the discussion starting with
https://cygwin.com/pipermail/cygwin/2023-April/253495.html
stop falling back to sh if the file given to posix_spawnp
is no executable.

This is not necessarily the last word on it, given
https://www.austingroupbugs.net/view.php?id=1674, but for now,
opt for following the proposal in the Austin Group bug entry,
as well as PASSing the GNULIB test-posix_spawnp-script test.

Fixes: c7c1a1ca1b ("Add support for new posix_spawn function.")
Fixes: 3fbfcd11fb ("Cygwin: posix_spawn: add Cygwin-specific code fixing process synchronisation")
Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-19 21:08:48 +02:00
David McFarland 53f7fb20a0 Cygwin: mbrtowi: fix segfault when pwi is NULL
mbrtowi was missing null-checks on pwi, but NULL is passed from
regex/engine.c:173.

In a git repo with sendemail.smtpserver set, this results in a segfault when
using git-send-email, which calls:

git config --get-regexp '^sende?mail[.]'

Fixes: 60c25da90d ("Cygwin: mbrtowi: define replacement for mbrtowc, returning UTF-32 value")
Signed-off-by: David McFarland <corngood@gmail.com>
2023-04-19 10:14:46 +02:00
Corinna Vinschen c743751aaf Cygwin: Export posix_spawn_file_actions_add{f}chdir_np
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-19 00:34:36 +02:00
Corinna Vinschen d30a5917a9 Cygwin: align renameat2 to Linux behaviour
In contrast to rename default behaviour, Linux' renameat2 returns -1
with errno set to EEXIST, if oldfile and newfile refer to the same
file, and the RENAME_NOREPLACE flag is set.

Follow suit, given this is a Linux-only function anyway.

Fixes: f665b1cef3 ("cygwin: Implement renameat2")
Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-18 18:18:27 +02:00
Corinna Vinschen fa84aa4dd2 Cygwin: fix errno values set by readlinkat
readlinkat(fd, "", ...) is supposed to return ENOENT per POSIX,
but Cygwin returns EBADF.

At the same time, we have to maintain the special feature of
glibc that readlinkat(fd, "", ...) operates on fd, if fd is pointing
at a symlink opened with O_PATH|O_NOFOLLOW.

And, while fixing that, readlinkat(fd, path, ...) *still* has to set errno
to EBADF, if fd is an invalid descriptor *and* path is a relative path.

This required to change the evaluation order in the helper function
gen_full_path_at.

Last but not least, in case of the aforementioned glibc-like special
handling for symlink descriptors, we have to make sure that errors from
gen_full_path_at are not spilled into that special handling.

Fixes: 6cc05784e1 ("Cygwin: readlinkat: allow pathname to be empty")
Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-18 13:52:50 +02:00
Corinna Vinschen 2fbb06d3cb Cygwin: fix return value of ilogbl(NaN)
Fixes: 792e51b721 ("Add missing long double functions to Cygwin")
Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-18 13:43:06 +02:00
Corinna Vinschen 836d04d98c Cygwin: add release text for previous commit
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-18 10:12:03 +02:00
David McFarland a14a0e542d Cygwin: cygheap: fix fork error after heap has grown
2f9b8ff0 introduced a problem where forks would sometimes fail with:

child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows pid 14032, Win32 error 299

When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be set to
allocsize(cygheap_max), which is an address, not a size.  VirtualAlloc would be
called to commit commit_size bytes, which would fail, and then child_copy would
be called with zero as the base address.

Fixes: 2f9b8ff00c ("Cygwin: decouple cygheap from Cygwin DLL")
Signed-off-by: David McFarland <corngood@gmail.com>
2023-04-18 10:06:53 +02:00
Takashi Yano e5fcc5837c Cygwin: pty: Fix reading CONIN$ when stdin is not a pty.
Previously, the pty master sends inputs to the pipe for cygwin app
even when pseudo console is activated if stdin is not the pty.
This causes the problem that key input is not sent to non cygwin
app even if the app opens CONIN$. This patch sets switch_to_nat_pipe
to true regardless whether stdin is the pty or not to allow that case.

https://cygwin.com/pipermail/cygwin/2023-April/253424.html

Reported-by: Wladislav Artsimovich <cygwin@frost.kiwi>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-04-14 11:22:33 +09:00
Johannes Schindelin cc8404039f Respect `db_home` setting even for SYSTEM/Microsoft accounts
We should not blindly set the home directory of the SYSTEM account (or
of Microsoft accounts) to `/home/<name>`, especially
`/etc/nsswitch.conf` defines `db_home: env`, in which case we want to
respect the `HOME` variable.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-04-03 18:17:43 +02:00
Corinna Vinschen 2898a359b8 Cygwin: dirname: fix handling of leading slashes
Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/xbd_chap04.html:

  "A pathname that begins with two successive slashes may be interpreted
   in an implementation-defined manner, although more than two leading
   slashes shall be treated as a single slash."

So more than 2 leading slashes are supposed to be folded into one,
which our dirname neglected.  Fix that.

Fixes: 24e8fc6872 ("* cygwin.din (basename): Export.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-29 10:23:05 +02:00
Johannes Schindelin 27376c60a9 Allow deriving the current user's home directory via the HOME variable
This patch hails from Git for Windows (where the Cygwin runtime is used
in the form of a slightly modified MSYS2 runtime), where it is a
well-established technique to let the `$HOME` variable define where the
current user's home directory is, falling back to `$HOMEDRIVE$HOMEPATH`
and `$USERPROFILE`.

The idea is that we want to share user-specific settings between
programs, whether they be Cygwin, MSYS2 or not.  Unfortunately, we
cannot blindly activate the "db_home: windows" setting because in some
setups, the user's home directory is set to a hidden directory via an
UNC path (\\share\some\hidden\folder$) -- something many programs
cannot handle correctly, e.g. `cmd.exe` and other native Windows
applications that users want to employ as Git helpers.

The established technique is to allow setting the user's home directory
via the environment variables mentioned above: `$HOMEDRIVE$HOMEPATH` or
`$USERPROFILE`.  This has the additional advantage that it is much
faster than querying the Windows user database.

Of course this scheme needs to be opt-in.  For that reason, it needs
to be activated explicitly via `db_home: env` in `/etc/nsswitch.conf`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-03-28 12:18:14 +02:00
Corinna Vinschen 80cea27942 Cygwin: /proc/locales: filter out useless explicit utf8 locales
Fixes: c42b98bdc6 ("Cygwin: introduce /proc/codesets and /proc/locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-26 14:12:13 +02:00
Corinna Vinschen 2d5492453a Cygwin: locales: fix behaviour for @euro locales
Latest Windows supports more EU locales than GLibc, so some of the
@euro locales are not covered by checking the GLibc locale defaults.
Those locales have no long history, they are all UTF-8.  So just
check for @euro in the UTF-8 case and set them to ISO-8859-15.

Fixes: 2483e54be8 ("Cygwin: locale: Set default charset from Linux locale -> codeset mapping")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-26 13:06:38 +02:00
Corinna Vinschen c3e7f7609e Cygwin: locales: fix behaviour for @cjk* and @euro locales
@cjknarrow and @cjkwide modifiers are newlib only, so they need
some tweaking in __set_charset_from_locale.

Fixes: 2483e54be8 ("Cygwin: locale: Set default charset from Linux locale -> codeset mapping")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-26 13:01:52 +02:00
Corinna Vinschen 68aea16d3f Cygwin: /proc/locales: use ENCODING_LEN to define array sizes
Fixes: c42b98bdc6 ("Cygwin: introduce /proc/codesets and /proc/locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-26 12:52:32 +02:00
Corinna Vinschen 4e578fad79 Cygwin: /proc/locales: use modifier when checking default codeset
Drop usage of newlocale/nl_langinfo_l/freelocale.
Call __set_charset_from_locale instead, and make sure to call it
with modifier, if any, otherwise suffer wrong results.

Fixes: c42b98bdc6 ("Cygwin: introduce /proc/codesets and /proc/locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-26 12:51:28 +02:00
Corinna Vinschen a97fbb58e2 Cygwin: locales: fix return value check of ResolveLocaleName
ResolveLocaleName does not simply return an error value if it
can't resolve a locale.  Rather, it returns an empty string and
the length of this string: 1.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-25 22:48:35 +01:00
Corinna Vinschen 7002f7f7c7 Revert "Cygwin: locales: drop supporting iso639 strings as valid locales"
This reverts commit 15898b9588.

The idea behind this patch was wrong.  Systems are supposed to
support iso639-only strings as settings for the locale environment
variables, and they are not necessarily available in the
/usr/share/locale/locale.alias file.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-25 22:30:15 +01:00
Corinna Vinschen b5b67a65f8 Cygwin: locales: implement own method to check locale validity
The Windows function ResolveLocaleName is next to useless to
convert a partial locale identifier into a full, supported
locale identifier.  It converts anything which vaguely resembles
a locale into some other locale it supports.

Bad examples are:
  "en-XY" gets converted to "en-US", and worse,
  "ff-BF" gets converted to "ff-Latn-SN", even though "ff-Adlm-BF"
  exists!

To check if a locale is supported, we have to enumerate all valid
Windows locales, and return the match, even if the locale in Windows
requires a script.  Implement resolve_locale_name() as replacement
function for ResolveLocaleName.

Fixes: e95a7a7955 ("Cygwin: convert Windows locale handling from LCID to ISO5646 strings")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-24 12:50:59 +01:00
Corinna Vinschen 15898b9588 Cygwin: locales: drop supporting iso639 strings as valid locales
This was incorrect behaviour.  The only valid way to support those
is by adding them to /usr/share/locale/locale.alias.

Fixes: e95a7a7955 ("Cygwin: convert Windows locale handling from LCID to ISO5646 strings")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-24 12:50:59 +01:00
Corinna Vinschen c53d0910e6 Cygwin: locales: set errno to ENOENT if locale is invalid
This allows newlocale to return with a valid errno if the
locale is invalid.

Fixes: e95a7a7955 ("Cygwin: convert Windows locale handling from LCID to ISO5646 strings")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-24 12:50:59 +01:00
Corinna Vinschen 676796498d Cygwin: /proc/locales: fix "sr" locales
The sr_XY locales are supposed to default to cyrillic, but the code
always attached a @cyrillic, same reason as in the previous commit.

Special case "sr" further to workaround that issue.

Fixes: c42b98bdc6 ("Cygwin: introduce /proc/codesets and /proc/locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-24 12:50:59 +01:00
Corinna Vinschen 9296f134fb Cygwin: /proc/locales: fix sd_IN locale
Due to the way locales are evaluated in Windows, we can't ask for
the script of the "sd-IN" locale, because Windows only knows the
"sd-Deva-IN" locale.  So asking for the script of the "sd" locale
returns "Arab;", because "sd" is converted to "sd-Arab-PK".

Special case "sd-IN" to workaround that issue.

Fixes: c42b98bdc6 ("Cygwin: introduce /proc/codesets and /proc/locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-24 12:50:59 +01:00
Yoshinao Muramatsu 87ab6c7b26 Cygwin: log disabling posix semantics
Add log when workaround occurs

Signed-off-by: Yoshinao Muramatsu <ysno@ac.auone-net.jp>
2023-03-21 18:56:52 +01:00
Yoshinao Muramatsu 7666e248dd Cygwin: fix rename in container
Renaming files returns STATUS_INVALID_PARAMETE on a bind mounted file system
in hyper-v container with FILE_RENAME_POSIX_SEMANTICS.

Disable the use_posix_semantics flag and retry.

Signed-off-by: Yoshinao Muramatsu <ysno@ac.auone-net.jp>
2023-03-21 18:56:52 +01:00
Yoshinao Muramatsu 527dd1b407 Cygwin: fix unlink in container
Deleting files returns STATUS_INVALID_PARAMETE on a bind mounted file system
in hyper-v container with FILE_DISPOSITION_POSIX_SEMANTICS.
Therefore fall back to default method.

This code is suggested by Johannes Schindelin on github
and I change it more simple.

Signed-off-by: Yoshinao Muramatsu <ysno@ac.auone-net.jp>
2023-03-21 18:56:27 +01:00
Corinna Vinschen fe2545e9fa Cygwin: don't use unlink/rename POSIX semantics on certain NTFS
If a host NTFS is mapped into a Hyper-V isolated container, the
OPEN_BY_FILE_ID filesystem flag is missing, just as if that NTFS
is a remote drive.  However, NtQueryVolumeInformationFile claims
the drive is a local drive.

We can use this fact to learn that the process is running under
Hyper-V, and that the Hyper-V isolated process can't use rename/unlink
with POSIX semantics.  Strange enough, the POSIX_UNLINK_RENAME filesystem
flag is still set...

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-21 18:29:59 +01:00
Corinna Vinschen 0a962aa2c2 Cygwin: fs_info::update: fix NTFS filesystem flags
These flags are used to check a remote filesystem.  Not all
flags supported by a local NTFS are available when checking
a remote NTFS.  Fix the flag set accordingly, otherwise
the remote NTFS will ba handled as CIFS.

Fixes: fcccdc4021 ("Cygwin: fs_info: update filesystem flags and check Windows 7 flags")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-21 18:02:49 +01:00
Corinna Vinschen 5924191333 Cygwin: regex: fix faulty check for valid range expression
Except for the "C" or "POSIX" locale, checking for start <= finish
is always wrong.  Range start must be <= range finish in terms of the
locale's collating order.  So make sure to call always wcscoll(), even
in the "C"/"POSIX" locale, which makes wcscoll equivalent to wcscmp
anyway.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-20 12:58:03 +01:00
Corinna Vinschen e914374383 Cygwin: regex: fix freeing g->charjump in low memory condition
computejumps() moves g->charjump to a position relativ to the value of
CHAR_MIN.  As such, g->charjump doesn't necessarily point to the address
actually allocated.  While regfree() takes that into account, the low
memory handling in regcomp_internal() doesn't.  Fix that by free'ing
the actually allocated address, as in regfree().

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-20 12:56:17 +01:00
Corinna Vinschen 271292b1fb Cygwin: unlink: drop unlink_nt/unlink_nt_shareable wrappers
Useless indirection.  Rename _unlink_nt back to unlink_nt
and call the function directly with `sharable' flag as needed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-20 12:55:30 +01:00
Corinna Vinschen fcccdc4021 Cygwin: fs_info: update filesystem flags and check Windows 7 flags
Update the list of filesystem flags to the flags supported since
Windows 7.  Make sure to use the new flags only with Windows
filesystems, not with 3rd party filesystems.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-20 12:55:30 +01:00
Corinna Vinschen 5da71b6059 Cygwin: add support for GB18030 codeset
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16 18:25:09 +01:00
Corinna Vinschen 2285cf0d1c Cygwin: regex: NONCHAR: re-add cast to int
wint_t is unsigned int and the test checks for a negative value.  Thus,
it's optimized out by gcc.  Add the cast from commit 44caccfca2 to
avoid this.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16 13:47:10 +01:00
Corinna Vinschen 0bdc764b42 Cygwin: regex: wgetnext: Re-add kludge to be more glibc compatible
Add comment to explain.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16 13:46:01 +01:00
Corinna Vinschen 585e7f9891 Cygwin: regex: convert wchar_t to wint_t throughout
...and use __wcollate_range_cmp.  This will have to be tweaked further
when supporting collation symbols...

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16 13:45:37 +01:00
Corinna Vinschen 988c304ec2 Cygwin: regex: fix build errors
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16 12:50:08 +01:00
Corinna Vinschen 24f34edc2a Cygwin: replace regex with latest verbatim FreeBSD version
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-16 11:12:08 +01:00
Corinna Vinschen 3569e3577c Cygwin: kill(1): don't print spurious error message
Make kill -V and kill -l exit immediately, thus stopping to
print "not enough arguments" accidentally.

Fixes: ef48a2cad3 ("* kill.cc (prog_name) New global variable.")
Fixes: c49fa76263 ("* Makefile.in (kill.exe): Add as a specific target.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-15 22:08:04 +01:00
Corinna Vinschen 07b5d3726f Cygwin: signals: drop accidental spaces from real-time signal names
The signal names for the real-time signals contain spaces from
the beginning of their availability.  Fix that.

Fixes: 61522196c7 ("* Merge in cygwin-64bit-branch.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-15 21:44:52 +01:00
Mark Geisert dfd14093e3 Cygwin: Fix type mismatch on sys/cpuset.h
Addresses https://cygwin.com/pipermail/cygwin/2023-March/253220.html

Take the opportunity to follow FreeBSD's and Linux's lead in recasting
macro inline code as calls to static inline functions.  This allows the
macros to be type-safe.  In addition, added a lower bound check to the
functions that use a cpu number to avoid a potential buffer underrun on
a bad argument.  h/t to Corinna for the advice on recasting.

Fixes: 362b98b49a ("Cygwin: Implement CPU_SET(3) macros")
2023-03-14 11:26:13 +01:00
Takashi Yano 93f70d7849 Cygwin: ctty: Remove old 'kludge' code.
Remove old 'kludge' code which does not seem necessary anymore. The
comment of the 'kludge' is as follows.

  * syscalls.cc (setsid): On second thought, in the spirit of keeping
    things kludgy, set ctty to -2 here as a special flag, and...
    (open): ...only eschew setting O_NOCTTY when that case is detected.

Fixes: c38a2d8373
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-03-07 10:51:44 +09:00
Takashi Yano 13a84ac79b Cygwin: ctty: Replace ctty constant with more descriptive macros.
This patch replaces ctty constants with more descriptive macros
(CTTY_UNINITIALIZED and CTTY_RELEASED) rather than -1 and -2 as
well as checking sign with CTTY_IS_VALID().

Fixes: 3b7df69aaa (Cygwin: ctty: Add comments for the special values: -1 and -2.)
Suggested-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-03-07 10:51:29 +09:00
Takashi Yano ce979464f3 Cygwin: console: Suppress unnecessary open_shared_console() calls.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-03-07 10:50:59 +09:00
Takashi Yano 523985b31e Cygwin: ctty: Add missing fixup_after_{exec,fork}() call.
Previously, fixup_after_{exec,fork}() calls for CTTY were missing.
This patch fixes that.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-03-07 10:14:25 +09:00
Corinna Vinschen 5ca1c57a82 Cygwin: is_unicode_equiv: fix comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-03 18:19:18 +01:00
Corinna Vinschen 6bc687e35d Cygwin: glob: fix conversion from UTF-32 to multibyte
The conversion function g_Ctoc missed to drop the flag
values from the wint_t value.  That wasn't noticable with
the original version because it used a 64 bit Char type
and the flags were in the upper 32 bit region.  So the
flag values were silently dropped when wcrtomb was called.
After converting Char to wint_t, we have to do drop the
flags explicitely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-03 18:19:17 +01:00
Corinna Vinschen 68db1fa7ba Cygwin: define CHARCLASS_NAME_MAX
CHARCLASS_NAME_MAX isn't defined yet, accidentally.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 21:22:56 +01:00
Corinna Vinschen c0aba3141b Cygwin: add collating symbols support to release message
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 11:49:52 +01:00
Corinna Vinschen c36064bbd0 Cygwin: fnmatch: support collating symbols in [. .] brackets
This requires quite a few changes in how fnmatch operates.
It always operates on wint_t strings now, just like regex and glob,
and it always keeps a pointer on the character inside the string,
rather than operating on a single character.

As a result, just drop the ifdef's for Cygwin.  The code is
non-portable now anyway...

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 10:54:52 +01:00
Corinna Vinschen 149cabea82 Cygwin: mbsnrtowci: like mbsnrtowcs, just for wint_t
Deviation from standard: If the input is broken, the output will be
broken.  I. e., we just copy the current byte over into the wint_t
destination and try to pick up on the next byte.  This is in line
with the way fnmatch works.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 10:54:52 +01:00
Corinna Vinschen 9870f1d1ff Cygwin: wcichr: add wint_t replacement for wcschr
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 10:54:52 +01:00
Corinna Vinschen b81969345d Cygwin: add wcipcpy and wcipncpy helper functions
wint_t replacements for wcpcpy and wcpncpy

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 10:54:52 +01:00
Corinna Vinschen 77883ac914 Cygwin: wcitoascii: move to wchar.h as inline function
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-01 10:54:52 +01:00
Corinna Vinschen 0d2ad77c40 Cygwin: fnmatch: drop static variable
fnmatch calls fnmatch1 with a static mbstate_t.  This breaks
calling fnmatch from multiple threads.  Fix it by folding
fnmatch1 into fnmatch and moving all mbstates to local variables.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-28 16:45:52 +01:00
Corinna Vinschen 6e75277b12 Cygwin: __wscollate_range_cmp: fix incorrect comment
The comment that the first arg must be the pattern was added
during development, before it turned out that __wscollate_range_cmp
can be implemented in an order independent way.

Better explain why this function uses pointers to strings.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-28 12:24:29 +01:00
Corinna Vinschen 5011c8cc48 Cygwin: fetch-lc-def-codesets-from-linux: fix locale name handling
As the former call to `locale -av' has the unwanted side effect
to shorten the locale name to <= 15 chars, don't use it.  Use
`locale -a' instead and fetch the codeset from another call to
`locale' for each locale.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-26 20:14:54 +01:00
Corinna Vinschen abd81bc01f Cygwin: locale: fix devanagari modifier
Effectively revert commit 57bac33359.  The fact that the
devanagari modifier was called devanagar (missing the trailing 'i')
is a result of `locale -av' shortening the locale name to a maximum
of 15 characters.

D'oh.  I guess we need a better way to do this...

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-26 17:17:33 +01:00
Corinna Vinschen c42b98bdc6 Cygwin: introduce /proc/codesets and /proc/locales
So far locale(1) had to have knowledge how to construct, thus
duplicating the effort how Cygwin handles locale strings.

Move locale list and codeset list generation into Cygwin by
providing /proc/codesets and /proc/locales files.  /proc/locales
does not list aliases, those are still handled in locale(1).

locale(1) opens the files and ueses that info for printing,
like any other application can do now.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-26 17:07:06 +01:00
Corinna Vinschen a31d4039d0 Cygwin: fetch-lc-def-codesets-from-linux: speed up
Drop shell read loop in favor of performing the locale output
evaluation inside a single awk invocation.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-25 20:15:53 +01:00
Corinna Vinschen 2483e54be8 Cygwin: locale: Set default charset from Linux locale -> codeset mapping
Generate lc_def_codeset.h header containing the default mapping from
locale to codeset on Linux.  Use this mapping in __set_charset_from_locale
in the first place.

For every locale not covered by this table, just map Windows codepages
to equivalent codesets used on Linux/Unix, getting rid of LCIDs entirely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-25 16:12:51 +01:00
Corinna Vinschen 7b591704b8 Cygwin: locale: new script creating linux default codeset mapping
New script creating a mapping table from locale to default codeset
for this locale.  We use that in Cygwin now to generate the own
default codeset mapping based on Linux locale names.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-25 16:12:51 +01:00
Corinna Vinschen 57bac33359 Cygwin: locale: fix devanagar modifier
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-25 16:12:51 +01:00