Annotation of ntddk/src/print/lib/mapfile.c, revision 1.1.1.1

1.1       root        1: //--------------------------------------------------------------------------
                      2: //
                      3: // Module Name:  MAPFILE.C
                      4: //
                      5: // Brief Description:  This module contains the PSCRIPT driver's MapFile
                      6: // routine.
                      7: //
                      8: // Author:  Kent Settle (kentse)
                      9: // Created: 05-Nov-1991
                     10: //
                     11: // Copyright (c) 1991 - 1992 Microsoft Corporation
                     12: //--------------------------------------------------------------------------
                     13: 
                     14: #include "stddef.h"
                     15: #include "windows.h"
                     16: #include "winddi.h"
                     17: #include "libproto.h"
                     18: 
                     19: //--------------------------------------------------------------------------
                     20: // PVOID MapFile(pwstr)
                     21: // PWSTR        pwstr;
                     22: //
                     23: // Returns a pointer to the mapped file defined by pwstr.
                     24: //
                     25: // Parameters:
                     26: //   pwstr   UNICODE string containing fully qualified pathname of the
                     27: //           file to map.
                     28: //
                     29: // Returns:
                     30: //   Pointer to mapped memory if success, NULL if error.
                     31: //
                     32: // NOTE:  UnmapViewOfFile will have to be called by the user at some
                     33: //        point to free up this allocation.
                     34: //
                     35: // History:
                     36: //  15:08 on Thu 27 Feb 1992    -by-    Lindsay Harris   [lindsayh]
                     37: //      Change PWSZ -> pwstr {Preferred type for Unicode stuff}
                     38: //
                     39: //   05-Nov-1991    -by-    Kent Settle     [kentse]
                     40: // Wrote it.
                     41: //--------------------------------------------------------------------------
                     42: 
                     43: PVOID MapFile(pwstr)
                     44: PWSTR   pwstr;
                     45: {
                     46:     PVOID   pv;
                     47:     HANDLE  hFile, hFileMap;
                     48: 
                     49:     // open the file we are interested in mapping.
                     50: 
                     51:     if ((hFile = CreateFileW(pwstr, GENERIC_READ, FILE_SHARE_READ,
                     52:                              NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
                     53:                              NULL)) == INVALID_HANDLE_VALUE)
                     54:     {
                     55:         RIP("MapFile: CreateFileW failed.\n");
                     56:         return((PVOID)NULL);
                     57:     }
                     58: 
                     59:     // create the mapping object.
                     60: 
                     61:     if (!(hFileMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY,
                     62:                                         0, 0, (PWSTR)NULL)))
                     63:     {
                     64:         RIP("MapFile: CreateFileMapping failed.\n");
                     65:         return((PVOID)NULL);
                     66:     }
                     67: 
                     68:     // get the pointer mapped to the desired file.
                     69: 
                     70:     if (!(pv = (PVOID)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0)))
                     71:     {
                     72:         RIP("MapFile: MapViewOfFile failed.\n");
                     73:         return((PVOID)NULL);
                     74:     }
                     75: 
                     76:     // now that we have our pointer, we can close the file and the
                     77:     // mapping object.
                     78: 
                     79:     if (!CloseHandle(hFileMap))
                     80:         RIP("MapFile: CloseHandle(hFileMap) failed.\n");
                     81: 
                     82:     if (!CloseHandle(hFile))
                     83:         RIP("MapFile: CloseHandle(hFile) failed.\n");
                     84: 
                     85:     return(pv);
                     86: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.