Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.8 KiB

4 years ago
  1. /*++
  2. Module Name:
  3. windows\spooler\prtprocs\winprint\support.c
  4. Abstract:
  5. Support routines for WinPrint.
  6. Author:
  7. Tommy Evans (vtommye) 10-22-1993
  8. Revision History:
  9. --*/
  10. #include <windows.h>
  11. #include <winspool.h>
  12. #include <winsplp.h>
  13. #include <wchar.h>
  14. #include "winprint.h"
  15. /*++
  16. *******************************************************************
  17. G e t P r i n t e r I n f o
  18. Routine Description:
  19. This routine allocates the required memory for a
  20. PRINTER_INFO_? structure and retrieves the information
  21. from NT. This returns a pointer to the structure, which
  22. must be freed by the calling routine.
  23. Arguments:
  24. hPrinter HANDLE to the printer the job is in
  25. StructLevel The structure level to get
  26. pErrorCode => field to place error, if one
  27. Return Value:
  28. PUCHAR => buffer where devmode info is if okay
  29. NULL if error - pErrorCode returns error
  30. *******************************************************************
  31. --*/
  32. PUCHAR
  33. GetPrinterInfo(IN HANDLE hPrinter,
  34. IN ULONG StructLevel,
  35. OUT PULONG pErrorCode)
  36. {
  37. ULONG reqbytes, alloc_size;
  38. PUCHAR ptr_info;
  39. USHORT retry = 2;
  40. alloc_size = BASE_PRINTER_BUFFER_SIZE;
  41. /** Allocate a buffer. **/
  42. ptr_info = AllocSplMem(alloc_size);
  43. /** If the buffer isn't big enough, try once more **/
  44. while (retry--) {
  45. /** If the alloc / realloc failed, return error **/
  46. if (!ptr_info) {
  47. *pErrorCode = ERROR_NOT_ENOUGH_MEMORY;
  48. return NULL;
  49. }
  50. /** Go get the printer information **/
  51. if (GetPrinter(
  52. hPrinter,
  53. StructLevel,
  54. (PUCHAR)ptr_info,
  55. alloc_size,
  56. &reqbytes) == TRUE) {
  57. /** Got the info - return it **/
  58. *pErrorCode = 0;
  59. return (PUCHAR)ptr_info;
  60. }
  61. /**
  62. GetPrinter failed - if not because of insufficient buffer, fail
  63. the call. Otherwise, up our hint, re-allocate and try again.
  64. **/
  65. *pErrorCode = GetLastError();
  66. if (*pErrorCode != ERROR_INSUFFICIENT_BUFFER) {
  67. FreeSplMem(ptr_info);
  68. return NULL;
  69. }
  70. /**
  71. Reallocate the buffer and re-try (note that, because we
  72. allocated the buffer as LMEM_FIXED, the LMEM_MOVABLE does
  73. not return a movable allocation, it just allows realloc
  74. to return a different pointer.
  75. **/
  76. alloc_size = reqbytes + 10;
  77. ptr_info = ReallocSplMem(ptr_info, alloc_size, 0);
  78. } /* While re-trying */
  79. if (ptr_info) {
  80. FreeSplMem(ptr_info);
  81. }
  82. *pErrorCode = ERROR_NOT_ENOUGH_MEMORY;
  83. return NULL;
  84. }