summaryrefslogtreecommitdiff
path: root/file_io/os2
diff options
context:
space:
mode:
authorbjh <bjh@13f79535-47bb-0310-9956-ffa450edef68>2010-04-04 13:10:34 +0000
committerbjh <bjh@13f79535-47bb-0310-9956-ffa450edef68>2010-04-04 13:10:34 +0000
commit415c380b81747684b258567789bf43844d282902 (patch)
treebdde25b9fcf7ca02a53d54486c2bc6cbe19fdf1e /file_io/os2
parent579029a9ef4341607575421dc9c8d0cba72e3468 (diff)
downloadlibapr-415c380b81747684b258567789bf43844d282902.tar.gz
OS/2: Do a proper implementation of apr_file_ungetc().
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@930686 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/os2')
-rw-r--r--file_io/os2/filedup.c1
-rw-r--r--file_io/os2/open.c2
-rw-r--r--file_io/os2/pipe.c3
-rw-r--r--file_io/os2/readwrite.c11
4 files changed, 15 insertions, 2 deletions
diff --git a/file_io/os2/filedup.c b/file_io/os2/filedup.c
index b1063f57c..810e227fb 100644
--- a/file_io/os2/filedup.c
+++ b/file_io/os2/filedup.c
@@ -49,6 +49,7 @@ static apr_status_t file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_po
dup_file->buffered = old_file->buffered;
dup_file->isopen = old_file->isopen;
dup_file->flags = old_file->flags & ~APR_INHERIT;
+ dup_file->ungetchar = old_file->ungetchar;
/* TODO - dup pipes correctly */
dup_file->pipe = old_file->pipe;
diff --git a/file_io/os2/open.c b/file_io/os2/open.c
index 46be806a5..888988c8a 100644
--- a/file_io/os2/open.c
+++ b/file_io/os2/open.c
@@ -44,6 +44,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr
dafile->buffer = NULL;
dafile->flags = flag;
dafile->blocking = BLK_ON;
+ dafile->ungetchar = -1;
if ((flag & APR_FOPEN_READ) && (flag & APR_FOPEN_WRITE)) {
mflags |= OPEN_ACCESS_READWRITE;
@@ -199,6 +200,7 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thef
(*file)->flags = flags;
(*file)->pipe = FALSE;
(*file)->buffered = (flags & APR_FOPEN_BUFFERED) > 0;
+ (*file)->ungetchar = -1;
if ((*file)->buffered) {
apr_status_t rv;
diff --git a/file_io/os2/pipe.c b/file_io/os2/pipe.c
index 211c43cde..d0851932e 100644
--- a/file_io/os2/pipe.c
+++ b/file_io/os2/pipe.c
@@ -85,6 +85,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
(*in)->pipe = 1;
(*in)->timeout = -1;
(*in)->blocking = BLK_ON;
+ (*in)->ungetchar = -1;
apr_pool_cleanup_register(pool, *in, apr_file_cleanup, apr_pool_cleanup_null);
(*out) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));
@@ -97,6 +98,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
(*out)->pipe = 1;
(*out)->timeout = -1;
(*out)->blocking = BLK_ON;
+ (*out)->ungetchar = -1;
apr_pool_cleanup_register(pool, *out, apr_file_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
@@ -186,6 +188,7 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
(*file)->pipe = 1;
(*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */
(*file)->timeout = -1;
+ (*file)->ungetchar = -1;
(*file)->filedes = *thefile;
if (register_cleanup) {
diff --git a/file_io/os2/readwrite.c b/file_io/os2/readwrite.c
index 6ff2feb54..deaf5c262 100644
--- a/file_io/os2/readwrite.c
+++ b/file_io/os2/readwrite.c
@@ -53,6 +53,13 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size
return APR_EBADF;
}
+ if (thefile->ungetchar != -1 && req_nbytes >= 1) {
+ *(char *)buf = (char)thefile->ungetchar;
+ (char *)buf++;
+ (*nbytes)--;
+ thefile->ungetchar = -1;
+ }
+
if (thefile->buffered) {
char *pos = (char *)buf;
ULONG blocksize;
@@ -249,8 +256,8 @@ APR_DECLARE(apr_status_t) apr_file_putc(char ch, apr_file_t *thefile)
APR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile)
{
- apr_off_t offset = -1;
- return apr_file_seek(thefile, APR_CUR, &offset);
+ thefile->ungetchar = (unsigned char)ch;
+ return APR_SUCCESS;
}