You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by bj...@hyperreal.org on 1999/10/18 12:23:22 UTC
cvs commit: apache-2.0/src/lib/apr/file_io/os2 fileio.h maperrorcode.c open.c readwrite.c
bjh 99/10/18 03:23:22
Modified: src/lib/apr/file_io/os2 fileio.h maperrorcode.c open.c
readwrite.c
Log:
OS/2: Assorted file I/O cleanups & fixes.
- Implement ap_eof()
- Fix flags passed to DosOpen when reading an existing file
- Invalidate file status info after a write
- add (mostly based on the unix versions) ap_make_iov(), ap_writev(),
ap_putc(), ap_ungetc(), ap_getc(), ap_puts(), ap_flush(), ap_fgets(),
ap_fprintf()
Revision Changes Path
1.3 +3 -2 apache-2.0/src/lib/apr/file_io/os2/fileio.h
Index: fileio.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/os2/fileio.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- fileio.h 1999/10/13 09:38:08 1.2
+++ fileio.h 1999/10/18 10:23:20 1.3
@@ -71,6 +71,7 @@
int buffered;
FILESTATUS3 status;
int validstatus;
+ int eof_hit;
};
struct dir_t {
@@ -82,11 +83,11 @@
};
struct iovec_t {
- struct iovec *iovec;
+ ap_context_t *cntxt;
+ struct iovec *theiov;
};
ap_status_t file_cleanup(void *);
-mode_t get_fileperms(ap_fileperms_t);
long os2date2unix( FDATE os2date, FTIME os2time );
int os2errno( ULONG oserror );
1.2 +3 -2 apache-2.0/src/lib/apr/file_io/os2/maperrorcode.c
Index: maperrorcode.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/os2/maperrorcode.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maperrorcode.c 1999/08/17 15:59:36 1.1
+++ maperrorcode.c 1999/10/18 10:23:21 1.2
@@ -53,12 +53,13 @@
*
*/
+#define INCL_DOSERRORS
+#include "fileio.h"
#include "apr_file_io.h"
#include <errno.h>
#include <string.h>
-
-#define INCL_DOSERRORS
#include <os2.h>
+
int errormap[][2] = {
{ NO_ERROR, APR_SUCCESS },
1.7 +13 -1 apache-2.0/src/lib/apr/file_io/os2/open.c
Index: open.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/os2/open.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- open.c 1999/10/14 14:36:30 1.6
+++ open.c 1999/10/18 10:23:21 1.7
@@ -82,6 +82,7 @@
dafile->cntxt = cntxt;
dafile->isopen = FALSE;
dafile->validstatus = FALSE;
+ dafile->eof_hit = FALSE;
if ((flag & APR_READ) && (flag & APR_WRITE)) {
mflags |= OPEN_ACCESS_READWRITE;
@@ -111,9 +112,11 @@
if (flag & APR_TRUNCATE) {
oflags |= OPEN_ACTION_REPLACE_IF_EXISTS;
+ } else {
+ oflags |= OPEN_ACTION_OPEN_IF_EXISTS;
}
- rv = DosOpen(fname, (HFILE *)&(dafile->filedes), &action, 0, 0, oflags, mflags, NULL);
+ rv = DosOpen(fname, &(dafile->filedes), &action, 0, 0, oflags, mflags, NULL);
if (rv == 0 && (flag & APR_APPEND)) {
ULONG newptr;
@@ -185,3 +188,12 @@
return APR_SUCCESS;
}
+
+
+ap_status_t ap_eof(ap_file_t *fptr)
+{
+ if (!fptr->isopen || fptr->eof_hit == 1) {
+ return APR_EOF;
+ }
+ return APR_SUCCESS;
+}
1.3 +163 -0 apache-2.0/src/lib/apr/file_io/os2/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/os2/readwrite.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- readwrite.c 1999/08/28 08:05:44 1.2
+++ readwrite.c 1999/10/18 10:23:21 1.3
@@ -77,6 +77,11 @@
return os2errno(rc);
}
+ if (bytesread == 0) {
+ thefile->eof_hit = TRUE;
+ return APR_EOF;
+ }
+
*nbytes = bytesread;
return APR_SUCCESS;
}
@@ -101,5 +106,163 @@
}
*nbytes = byteswritten;
+ thefile->validstatus = FALSE;
return APR_SUCCESS;
}
+
+
+
+#ifdef HAVE_WRITEV
+
+ap_status_t ap_make_iov(struct iovec_t **new, struct iovec *iova, ap_context_t *cntxt)
+{
+ (*new) = ap_palloc(cntxt, sizeof(struct iovec_t));
+ if ((*new) == NULL) {
+ return APR_ENOMEM;
+ }
+ (*new)->cntxt = cntxt;
+ (*new)->theiov = iova;
+ return APR_SUCCESS;
+}
+
+
+
+ap_status_t ap_writev(struct file_t *thefile, const struct iovec_t *vec, ap_ssize_t *iocnt)
+{
+ int bytes;
+ if ((bytes = writev(thefile->filedes, vec->theiov, *iocnt)) < 0) {
+ *iocnt = bytes;
+ return errno;
+ }
+ else {
+ *iocnt = bytes;
+ thefile->validstatus = FALSE;
+ return APR_SUCCESS;
+ }
+}
+#endif
+
+
+
+ap_status_t ap_putc(char ch, ap_file_t *thefile)
+{
+ ULONG rc;
+ ULONG byteswritten;
+
+ if (!thefile->isopen) {
+ return APR_EBADF;
+ }
+
+ rc = DosWrite(thefile->filedes, &ch, 1, &byteswritten);
+
+ if (rc) {
+ return os2errno(rc);
+ }
+
+ thefile->validstatus = FALSE;
+ return APR_SUCCESS;
+}
+
+
+
+ap_status_t ap_ungetc(char ch, ap_file_t *thefile)
+{
+ /* Not sure what to do in this case. For now, return SUCCESS. */
+ return APR_SUCCESS;
+}
+
+
+
+ap_status_t ap_getc(char *ch, ap_file_t *thefile)
+{
+ ULONG rc;
+ ULONG bytesread;
+
+ if (!thefile->isopen) {
+ return APR_EBADF;
+ }
+
+ rc = DosRead(thefile->filedes, ch, 1, &bytesread);
+
+ if (rc) {
+ return os2errno(rc);
+ }
+
+ if (bytesread == 0) {
+ thefile->eof_hit = TRUE;
+ return APR_EOF;
+ }
+
+ return APR_SUCCESS;
+}
+
+
+
+ap_status_t ap_puts(char *str, ap_file_t *thefile)
+{
+ ap_ssize_t len;
+
+ len = strlen(str);
+ return ap_write(thefile, str, &len);
+}
+
+
+
+ap_status_t ap_flush(ap_file_t *thefile)
+{
+ /* There isn't anything to do if we aren't buffering the output
+ * so just return success.
+ */
+ return APR_SUCCESS;
+}
+
+
+
+ap_status_t ap_fgets(char *str, int len, ap_file_t *thefile)
+{
+ ssize_t readlen;
+ ap_status_t rv;
+ int i;
+
+ for (i = 0; i < len; i++) {
+ readlen = 1;
+ rv = ap_read(thefile, str+i, &readlen);
+
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+
+ if (str[i] == '\r')
+ i--;
+ else if (str[i] == '\n')
+ break;
+ }
+ return APR_SUCCESS;
+}
+
+
+
+API_EXPORT(int) ap_fprintf(struct file_t *fptr, const char *format, ...)
+{
+ int cc;
+ va_list ap;
+ ap_vformatter_buff_t vbuff;
+ char *buf;
+ int len;
+
+ buf = malloc(HUGE_STRING_LEN);
+ if (buf == NULL) {
+ return 0;
+ }
+ /* save one byte for nul terminator */
+ vbuff.curpos = buf;
+ vbuff.endpos = buf + len - 1;
+ va_start(ap, format);
+ vsprintf(buf, format, ap);
+ len = strlen(buf);
+ cc = ap_write(fptr, buf, &len);
+ va_end(ap);
+ return (cc == -1) ? len : cc;
+}
+
+