From b9a541124a85c8954147de3c1716dfb1e33b2357 Mon Sep 17 00:00:00 2001
From: Christopher Degawa <ccom@randomderp.com>
Date: Wed, 18 Aug 2021 10:00:26 -0500
Subject: [PATCH 22/N] pacman.c: handle cr on stdin as well

Improves compatibility with Windows targets, specifically when using
powershell for string transforming package names and piping into
pacman as it's virtually impossible to send newline only terminated
strings through pipes

Allows for stuff such as

```powershell
$a="vim nano"
$b="cmake ninja"
$a.Split(' '), $b.Split(' ').ForEach({Write-Output mingw-w64-ucrt-x86_64-$_}) |
  pacman -S --needed -
```

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
---
 src/pacman/pacman.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 3a25442..46c8ef8 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1187,6 +1187,12 @@ int main(int argc, char *argv[])
 				if(line[nread - 1] == '\n') {
 					/* remove trailing newline */
 					line[nread - 1] = '\0';
+#ifdef __MSYS__
+					if (line[nread - 2] == '\r') {
+						/* remove trailing carriage returns */
+						line[nread - 2] = '\0';
+					}
+#endif
 				}
 				if(line[0] == '\0') {
 					/* skip empty lines */
