home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / network / eqtree / copy.c next >
C/C++ Source or Header  |  1994-01-18  |  1KB  |  80 lines

  1. /*
  2.  * COPY.c
  3.  *
  4.  * Copy-Routine für große Dateien
  5.  *
  6.  * Autor: SG
  7.  * Stand: 25.1.93
  8.  *
  9.  */
  10.  
  11. #define INCL_BASE
  12. #define INCL_DOS
  13. #define INCL_NOPM
  14. #include <os2.h>
  15. #include <direct.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include <io.h>
  19. #include <sys\types.h>
  20. #include <sys\stat.h>
  21.  
  22. int COMakeWritable(const char *Filename)
  23. {
  24.     return chmod((char *)Filename,S_IWRITE)==0;
  25. }
  26.  
  27. int COPathCreate(const char *Path)
  28. {
  29.     char PathBuf[2048];
  30.     char *Begin,
  31.      *End;
  32.  
  33.     if (strlen(Path)>2047)
  34.     return 0;
  35.     strcpy(PathBuf,Path);
  36.  
  37.     if (Path[1] == ':')
  38.     if (_chdrive(toupper(*PathBuf)-'A'+1)!=0)
  39.         return 0;
  40.     else
  41.         Begin = PathBuf+2;
  42.     else
  43.     Begin = PathBuf;
  44.     chdir("\\");
  45.  
  46.     while (Begin)
  47.     {
  48.     if (*Begin == '\\')
  49.         Begin++;
  50.     if ((End = strchr(Begin,'\\'))!=NULL)
  51.     {
  52.         *End = 0;
  53.         End++;
  54.     }
  55.     else /* Jetzt steht Begin auf dem Dateinamen. Der darf nicht als Verzeichnis angelegt werden */
  56.         return 1;
  57.  
  58.     if (chdir(Begin)!=0)
  59.     {
  60.         if (mkdir(Begin)!=0)
  61.         return 0;
  62.         if (chdir(Begin)!=0)
  63.         return 0;
  64.     }
  65.     Begin = End;
  66.     }
  67. }
  68.  
  69. int COCopy(const char *Source, const char *Dest)
  70. {
  71.     int ret;
  72.  
  73.     if (COPathCreate(Dest)==0)
  74.     return 0;
  75.  
  76.     COMakeWritable(Dest);
  77.     ret = DosCopy((char *)Source,(char *)Dest,DCPY_EXISTING,0);
  78.     return ret;
  79. }
  80.