Read in text mode, write in binary mode on OS/2

This enables to convert CR+LF to LF when reading, but disables to
convert LF to CR+LF when writing.

Instead, however, CR+LF are not passed into mksh as is.
This commit is contained in:
KO Myung-Hun 2015-05-16 13:20:53 +09:00
parent a3fdbc6802
commit 5127457319
5 changed files with 20 additions and 0 deletions

View File

@ -1668,6 +1668,7 @@ ac_header sys/select.h sys/types.h
ac_header sys/sysmacros.h
ac_header bstring.h
ac_header grp.h sys/types.h
ac_header io.h
ac_header libgen.h
ac_header libutil.h sys/types.h
ac_header paths.h

3
exec.c
View File

@ -901,6 +901,9 @@ scriptexec(struct op *tp, const char **ap)
unsigned short m;
ssize_t n;
#ifdef __OS2__
setmode(fd, O_TEXT);
#endif
/* read first couple of octets from file */
n = read(fd, buf, sizeof(buf) - 1);
close(fd);

4
main.c
View File

@ -1438,6 +1438,10 @@ openpipe(int *pv)
pv[1] = savefd(lpv[1]);
if (pv[1] != lpv[1])
close(lpv[1]);
#ifdef __OS2__
setmode(pv[0], O_TEXT);
setmode(pv[1], O_BINARY);
#endif
}
void

9
misc.c
View File

@ -1329,6 +1329,10 @@ blocking_read(int fd, char *buf, size_t nbytes)
ssize_t ret;
bool tried_reset = false;
#ifdef __OS2__
int saved_mode = setmode(fd, O_TEXT);
int saved_errno;
#endif
while ((ret = read(fd, buf, nbytes)) < 0) {
if (!tried_reset && errno == EAGAIN) {
if (reset_nonblock(fd) > 0) {
@ -1339,6 +1343,11 @@ blocking_read(int fd, char *buf, size_t nbytes)
}
break;
}
#ifdef __OS2__
saved_errno = errno;
setmode(fd, saved_mode);
errno = saved_errno;
#endif
return (ret);
}

3
sh.h
View File

@ -64,6 +64,9 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#if HAVE_IO_H
#include <io.h>
#endif
#if HAVE_LIBGEN_H
#include <libgen.h>
#endif