Counter Strike : Global Offensive Source Code
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.

65 lines
1.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdio.h>
  8. #ifndef _PS3
  9. #include <memory.h>
  10. #endif
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // Copied from sound.cpp in the DLL
  14. char *memfgets( unsigned char *pMemFile, int fileSize, int *pFilePos, char *pBuffer, int bufferSize )
  15. {
  16. int filePos = *pFilePos;
  17. int i, last, stop;
  18. // Bullet-proofing
  19. if ( !pMemFile || !pBuffer )
  20. return NULL;
  21. if ( filePos >= fileSize )
  22. return NULL;
  23. i = filePos;
  24. last = fileSize;
  25. // fgets always NULL terminates, so only read bufferSize-1 characters
  26. if ( last - filePos > (bufferSize-1) )
  27. last = filePos + (bufferSize-1);
  28. stop = 0;
  29. // Stop at the next newline (inclusive) or end of buffer
  30. while ( i < last && !stop )
  31. {
  32. if ( pMemFile[i] == '\n' )
  33. stop = 1;
  34. i++;
  35. }
  36. // If we actually advanced the pointer, copy it over
  37. if ( i != filePos )
  38. {
  39. // We read in size bytes
  40. int size = i - filePos;
  41. // copy it out
  42. memcpy( pBuffer, pMemFile + filePos, sizeof(unsigned char)*size );
  43. // If the buffer isn't full, terminate (this is always true)
  44. if ( size < bufferSize )
  45. pBuffer[size] = 0;
  46. // Update file pointer
  47. *pFilePos = i;
  48. return pBuffer;
  49. }
  50. // No data read, bail
  51. return NULL;
  52. }