]> pd.if.org Git - pdclib/blobdiff - platform/win32/functions/_PDCLIB/_PDCLIB_open.c
Cosmetic comment fixes.
[pdclib] / platform / win32 / functions / _PDCLIB / _PDCLIB_open.c
index bfdb8975c49bfb9726306749e7a1a1444670f390..21c899566915f480cea53d6b74ec9fbd0d149c71 100644 (file)
@@ -1,23 +1,21 @@
-/* $Id$ */
-
 /* _PDCLIB_open( char const * const, int )
 
    This file is part of the Public Domain C Library (PDCLib).
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is a stub implementation of open.
-*/
-
 #include <stdio.h>
 #include <errno.h>
 
 #ifndef REGTEST
-#include <_PDCLIB_glue.h>
+#include "_PDCLIB_glue.h"
 #include <windows.h>
 
+extern const _PDCLIB_fileops_t _PDCLIB_fileops;
+
 void _PDCLIB_w32errno(void);
-HANDLE _PDCLIB_open( char const * const filename, unsigned int mode )
+bool _PDCLIB_open( _PDCLIB_fd_t * pFd, const _PDCLIB_fileops_t ** pOps,
+                   char const * const filename, unsigned int mode )
 {
     DWORD desiredAccess;
     DWORD creationDisposition;
@@ -51,7 +49,7 @@ HANDLE _PDCLIB_open( char const * const filename, unsigned int mode )
         break;
     default: /* Invalid mode */
         errno = EINVAL;
-        return NULL;
+        return false;
     }
 
     HANDLE fd = CreateFileA(filename, desiredAccess, 
@@ -59,8 +57,23 @@ HANDLE _PDCLIB_open( char const * const filename, unsigned int mode )
         NULL, creationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
 
     if(fd == INVALID_HANDLE_VALUE) {
+#if 0
+        DWORD dw = GetLastError();
+        char* msgBuf;
+        FormatMessage(
+            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
+            FORMAT_MESSAGE_FROM_SYSTEM |
+            FORMAT_MESSAGE_IGNORE_INSERTS,
+            NULL,
+            dw,
+            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+            (LPSTR) &msgBuf,
+            0, NULL );
+
+        fprintf(stderr, "Error: %s\n", msgBuf);
+#endif
         _PDCLIB_w32errno();
-        return NULL;
+        return false;
     }
 
     if(mode & _PDCLIB_FAPPEND) {
@@ -70,17 +83,19 @@ HANDLE _PDCLIB_open( char const * const filename, unsigned int mode )
         if(!ok) {
             _PDCLIB_w32errno();
             CloseHandle(fd);
-            return NULL;
+            return false;
         }
     }
 
-    return fd;
+    pFd->pointer = fd;
+    *pOps = &_PDCLIB_fileops;
+    return true;
 }
 
 #endif
 
 #ifdef TEST
-#include <_PDCLIB_test.h>
+#include "_PDCLIB_test.h"
 
 #include <stdlib.h>
 #include <string.h>