Source code of Windows XP (NT5)
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.

96 lines
2.4 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. strprof.c
  7. NLS/DBCS-aware string class: GetPrivateProfileString method
  8. This file contains the implementation of the GetPrivateProfileString method
  9. for the NLS_STR class. It is separate so that clients of NLS_STR who
  10. do not use this operator need not link to it.
  11. FILE HISTORY:
  12. 04/08/93 gregj Created
  13. */
  14. #include "npcommon.h"
  15. extern "C"
  16. {
  17. #include <netlib.h>
  18. }
  19. #if defined(DEBUG)
  20. static const CHAR szFileName[] = __FILE__;
  21. #define _FILENAME_DEFINED_ONCE szFileName
  22. #endif
  23. #include <npassert.h>
  24. #include <npstring.h>
  25. /*******************************************************************
  26. NAME: NLS_STR::GetPrivateProfileString
  27. SYNOPSIS: Loads a string from an INI file.
  28. ENTRY: pszFile - name of INI file to read.
  29. pszSection - name of section (excluding square brackets).
  30. pszKey - key name to retrieve.
  31. pszDefault - default value if key not found.
  32. EXIT: String contains the value associated with the key.
  33. NOTES: The string is truncated if it's being loaded into an
  34. owner-alloc string and doesn't entirely fit.
  35. No character-set assumptions are made about the string.
  36. If the character set of the string being loaded is
  37. different from the ambient set of the NLS_STR, use
  38. SetOEM() or SetAnsi() to make the NLS_STR correct.
  39. HISTORY:
  40. gregj 04/08/93 Created
  41. ********************************************************************/
  42. VOID NLS_STR::GetPrivateProfileString( const CHAR *pszFile,
  43. const CHAR *pszSection,
  44. const CHAR *pszKey,
  45. const CHAR *pszDefault /* = NULL */ )
  46. {
  47. static CHAR szNull[] = "";
  48. if (QueryError())
  49. return;
  50. if (pszDefault == NULL)
  51. pszDefault = szNull;
  52. if (!IsOwnerAlloc() && !QueryAllocSize()) {
  53. if (!realloc( MAX_RES_STR_LEN )) {
  54. ReportError( WN_OUT_OF_MEMORY );
  55. return;
  56. }
  57. }
  58. INT cbCopied;
  59. for (;;) { /* really just tries twice */
  60. cbCopied = ::GetPrivateProfileString( pszSection, pszKey,
  61. pszDefault, _pchData, _cbData, pszFile );
  62. if (IsOwnerAlloc() || cbCopied < QueryAllocSize() - 1 ||
  63. (QueryAllocSize() >= MAX_RES_STR_LEN))
  64. break; /* string fit, or can't grow */
  65. if (!realloc( MAX_RES_STR_LEN ))
  66. break; /* tried to grow, but couldn't */
  67. }
  68. _cchLen = cbCopied;
  69. IncVers();
  70. }