Leaked source code of windows server 2003
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.

58 lines
1.3 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. RemoveSzFromFile() - remove a specified string from the file
  4. --*/
  5. #include <nt.h>
  6. #include <ntrtl.h>
  7. #include <nturtl.h>
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <nwcfg.hxx>
  12. BOOL
  13. RemoveSzFromFile( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult )
  14. {
  15. FILE * hsrcfile;
  16. FILE * hdesfile;
  17. char * pszTempname;
  18. char szInput[1000];
  19. pszTempname = tmpnam(NULL);
  20. wsprintf(achBuff,"{1}");
  21. *ppszResult = achBuff;
  22. if ( nArgs != 2 )
  23. {
  24. return(FALSE);
  25. }
  26. hsrcfile = fopen(apszArgs[0],"r");
  27. hdesfile = fopen(pszTempname,"w");
  28. if (( hsrcfile != NULL ) && ( hdesfile != NULL ))
  29. {
  30. while (fgets(szInput,1000,hsrcfile))
  31. {
  32. if (_stricmp(szInput,apszArgs[1])!=0)
  33. {
  34. fputs(szInput,hdesfile);
  35. }
  36. }
  37. }
  38. if ( hsrcfile != NULL )
  39. fclose(hsrcfile);
  40. if ( hdesfile != NULL )
  41. fclose(hdesfile);
  42. if (( hsrcfile != NULL ) && ( hdesfile != NULL ))
  43. {
  44. CopyFileA(pszTempname,apszArgs[0], FALSE);
  45. DeleteFileA(pszTempname);
  46. }
  47. wsprintf(achBuff,"{0}");
  48. *ppszResult = achBuff;
  49. return(TRUE);
  50. }