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
1.8 KiB

  1. /*
  2. Modifications:
  3. 01.25.94 Joe Holman Created to log errs while copying a single file.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <windows.h>
  9. #include <time.h>
  10. #include "general.h"
  11. FILE* logFile;
  12. void Msg ( const char * szFormat, ... ) {
  13. va_list vaArgs;
  14. va_start ( vaArgs, szFormat );
  15. vprintf ( szFormat, vaArgs );
  16. vfprintf ( logFile, szFormat, vaArgs );
  17. va_end ( vaArgs );
  18. }
  19. void Header(argv)
  20. char* argv[];
  21. {
  22. time_t t;
  23. Msg ("\n=========== MCOPY =============\n");
  24. Msg("Log file: %s\n", argv[1]);
  25. Msg("SrcFile: %s\n",argv[2]);
  26. Msg("DstFile: %s\n",argv[3]);
  27. time(&t);
  28. Msg("Time: %s",ctime(&t));
  29. Msg("================================\n\n");
  30. }
  31. void Usage()
  32. {
  33. printf("PURPOSE: Copies a single file.\n");
  34. printf("\n");
  35. printf("PARAMETERS:\n");
  36. printf("\n");
  37. printf("[LogFile] - Path to append a log of actions and errors.\n");
  38. printf("[SrcFile] - Path of src file location.\n");
  39. printf("[DstFile] - Path of dst file location.\n");
  40. }
  41. __cdecl main(int argc, char * argv[] ) {
  42. BOOL b;
  43. if (argc!=4) {
  44. Usage();
  45. return(1);
  46. }
  47. if ((logFile=fopen(argv[1],"a"))==NULL) {
  48. printf("ERROR Couldn't open log file %s\n",argv[1]);
  49. return(1);
  50. }
  51. Header(argv);
  52. SetFileAttributes ( argv[3], FILE_ATTRIBUTE_NORMAL );
  53. b = CopyFile ( argv[2], argv[3], FALSE );
  54. if ( !b ) {
  55. Msg ( "ERROR: CopyFile ( %s, %s ), gle = %ld\n",
  56. argv[2], argv[3], GetLastError() );
  57. }
  58. else {
  59. // If no error, set the file attributes to NORMAL.
  60. //
  61. if ( !SetFileAttributes ( argv[3], FILE_ATTRIBUTE_NORMAL ) ) {
  62. Msg ( "ERROR: SetFileAttributes on %s, gle = %ld\n", argv[3], GetLastError() );
  63. }
  64. }
  65. fclose(logFile);
  66. return(0);
  67. }