stoddard 99/09/30 14:10:18
Modified: src/lib/apr/file_io/win32 readwrite.c
Log:
Win32: Implement ap_ungetc()
Revision Changes Path
1.3 +38 -0 apache-2.0/src/lib/apr/file_io/win32/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/readwrite.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- readwrite.c 1999/09/24 18:49:03 1.2
+++ readwrite.c 1999/09/30 21:10:15 1.3
@@ -60,6 +60,8 @@
#include "apr_errno.h"
#include <windows.h>
+#define GetFilePointer(hfile) SetFilePointer(hfile,0,NULL, FILE_CURRENT)
+
ap_status_t ap_read(struct file_t *thefile, void *buf, ap_ssize_t *nbytes)
{
DWORD bread;
@@ -131,6 +133,42 @@
if (!WriteFile(thefile->filehand, &ch, 1, &bwrote, NULL)) {
return APR_EEXIST;
}
+ return APR_SUCCESS;
+}
+
+ap_status_t ap_ungetc(ap_file_t *thefile, char ch)
+{
+ /*
+ * Your application must provide its own serialization (locking) if
+ * it allows multiple threads to access the same file handle
+ * concurrently.
+ *
+ * ToDo: This function does not use the char ch argument. Could add
+ * gorpy code to read the file after the SetFilePointer() call to
+ * make sure the character pushed back on the stream is the same as
+ * arg ch. Then, need to SetFilePointer() once more to reset the
+ * file pointer to the point before the read. Yech... Just assume
+ * the caller knows what he is doing. There may be a nifty Win32
+ * call for this I've not discovered....
+ */
+
+ /* SetFilePointer is only valid for a file device ...*/
+ if (GetFileType(thefile->filehand) != FILE_TYPE_DISK) {
+ return !APR_SUCCESS; /* is there no generic failure code? */
+ }
+ /* that's buffered... */
+ if (!thefile->buffered) {
+ return !APR_SUCCESS; /* is there no generic failure code? */
+ }
+ /* and the file pointer is not pointing to the start of the file. */
+ if (GetFilePointer(thefile->filehand)) {
+ if (SetFilePointer(thefile->filehand, -1, NULL, FILE_CURRENT)
+ == 0xFFFFFFFF) {
+ return !APR_SUCCESS;
+ }
+ }
+
+ thefile->stated = 0;
return APR_SUCCESS;
}