aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-02-14 15:07:36 +0000
committerRon Yorston <rmy@pobox.com>2019-02-14 15:07:36 +0000
commitee7e00dc580c4e8075ab0776aeb3526c2c22f2b6 (patch)
treeb934dcdb7b9d27767c5336ad287408242c426b2f
parent6312c005522de47dcaf442f613065415bcbd8ef7 (diff)
downloadbusybox-w32-ee7e00dc580c4e8075ab0776aeb3526c2c22f2b6.tar.gz
busybox-w32-ee7e00dc580c4e8075ab0776aeb3526c2c22f2b6.tar.bz2
busybox-w32-ee7e00dc580c4e8075ab0776aeb3526c2c22f2b6.zip
win32: add a function to remove CRs from a text buffer
-rw-r--r--editors/awk.c19
-rw-r--r--include/mingw.h3
-rw-r--r--shell/ash.c11
-rw-r--r--win32/mingw.c11
4 files changed, 19 insertions, 25 deletions
diff --git a/editors/awk.c b/editors/awk.c
index dbb26068d..c4553728d 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -1998,20 +1998,11 @@ static int ptest(node *pattern)
1998#if ENABLE_PLATFORM_MINGW32 1998#if ENABLE_PLATFORM_MINGW32
1999static ssize_t FAST_FUNC safe_read_strip_cr(int fd, void *buf, size_t count) 1999static ssize_t FAST_FUNC safe_read_strip_cr(int fd, void *buf, size_t count)
2000{ 2000{
2001 ssize_t n, i, j; 2001 ssize_t n;
2002 char *b = (char *)buf; 2002
2003 2003 do {
2004 retry: 2004 n = safe_read(fd, buf, count);
2005 n = safe_read(fd, buf, count); 2005 } while (n > 0 && (n=remove_cr((char *)buf, n)) == 0);
2006 if (n > 0) {
2007 for (i=j=0; i<n; ++i) {
2008 if (b[i] != '\r')
2009 b[j++] = b[i];
2010 }
2011 if (j == 0)
2012 goto retry;
2013 n = j;
2014 }
2015 2006
2016 return n; 2007 return n;
2017} 2008}
diff --git a/include/mingw.h b/include/mingw.h
index 4655fe511..185eb66ed 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -500,7 +500,8 @@ static inline char *auto_win32_extension(const char *p)
500 return s ? auto_string(s) : NULL; 500 return s ? auto_string(s) : NULL;
501} 501}
502 502
503void FAST_FUNC convert_slashes(char *p); 503void convert_slashes(char *p) FAST_FUNC;
504size_t remove_cr(char *p, size_t len) FAST_FUNC;
504 505
505int err_win_to_posix(DWORD winerr); 506int err_win_to_posix(DWORD winerr);
506 507
diff --git a/shell/ash.c b/shell/ash.c
index 735364962..29130db0e 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13619,16 +13619,7 @@ evalstring(char *s, int flags)
13619 13619
13620 s = sstrdup(s); 13620 s = sstrdup(s);
13621#if ENABLE_PLATFORM_MINGW32 13621#if ENABLE_PLATFORM_MINGW32
13622 { 13622 remove_cr(s, strlen(s)+1);
13623 char *t, *u;
13624
13625 for (t=u=s; *t; ++t) {
13626 if (*t != '\r') {
13627 *u++ = *t;
13628 }
13629 }
13630 *u = '\0';
13631 }
13632#endif 13623#endif
13633 setinputstring(s); 13624 setinputstring(s);
13634 setstackmark(&smark); 13625 setstackmark(&smark);
diff --git a/win32/mingw.c b/win32/mingw.c
index 2a5f96c31..8217ec772 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1273,6 +1273,17 @@ void FAST_FUNC convert_slashes(char *p)
1273 } 1273 }
1274} 1274}
1275 1275
1276size_t FAST_FUNC remove_cr(char *p, size_t len)
1277{
1278 ssize_t i, j;
1279
1280 for (i=j=0; i<len; ++i) {
1281 if (p[i] != '\r')
1282 p[j++] = p[i];
1283 }
1284 return j;
1285}
1286
1276#undef opendir 1287#undef opendir
1277DIR *mingw_opendir(const char *path) 1288DIR *mingw_opendir(const char *path)
1278{ 1289{