home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XS.ZIP / LIB / FILEBKUP.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  3KB  |  105 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       f i l e b k u p                                              */
  3. /*                                                                    */
  4. /*       UUPC/extended file backup routines                           */
  5. /*                                                                    */
  6. /*       Copyright (c) 1991-1992 by Andrew H. Derbyshire;             */
  7. /*       all rights reserved except as granted by UUPC/extended       */
  8. /*       license included with documention.                           */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*                          RCS Information                           */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*
  16.  *    $Header: E:\SRC\UUPC\LIB\RCS\FILEBKUP.C 1.2 1992/11/19 02:57:51 ahd Exp $
  17.  *
  18.  *    Revision history:
  19.  *    $Log: FILEBKUP.C $
  20.  * Revision 1.2  1992/11/19  02:57:51  ahd
  21.  * drop rcsid
  22.  *
  23.  * Revision 1.1  1992/11/16  05:00:26  ahd
  24.  * Initial revision
  25.  *
  26.  */
  27.  
  28.  
  29.  
  30. /*--------------------------------------------------------------------*/
  31. /*                        System include files                        */
  32. /*--------------------------------------------------------------------*/
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <time.h>
  38.  
  39. #ifndef __GNUC__
  40. #include <direct.h>
  41. #endif
  42.  
  43. /*--------------------------------------------------------------------*/
  44. /*                    UUPC/extended include files                     */
  45. /*--------------------------------------------------------------------*/
  46.  
  47. #include "lib.h"
  48. #include "hlib.h"
  49.  
  50. currentfile();
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*    f i l e b k u p                                                 */
  54. /*                                                                    */
  55. /*    Backup a file to the standard UUPC/extended defined             */
  56. /*    extension.                                                      */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. int filebkup( const char *input )
  60. {
  61.    char fdrive[FILENAME_MAX];
  62.    char fpath[FILENAME_MAX];
  63.    char fname[FILENAME_MAX];
  64.    char ftype[FILENAME_MAX];
  65.    char backup[FILENAME_MAX];
  66.  
  67.    if ( !bflag[F_BACKUP] )    /* Are we to not back it up?           */
  68.       return 1;               /* Yes --> Report we did not           */
  69.  
  70. #ifdef __TURBOC__
  71.    fnsplit( input, fdrive, fpath, fname, ftype );
  72.  
  73.    if ( E_backup == NULL )
  74.       strcpy(ftype, ".BAK" );
  75.    else if ( *E_backup == '.' )
  76.       strcpy( ftype, E_backup );
  77.    else {
  78.       *ftype = '.';
  79.       strcpy(  ftype + 1 , E_backup );
  80.    } /* else */
  81.  
  82.    fnmerge( backup, fdrive, fpath, fname, ftype );
  83. #else
  84.  
  85.    if ( E_backup == NULL )
  86.       E_backup = ".BAK";
  87.  
  88.    _splitpath( input , fdrive, fpath, fname, ftype );
  89.    _makepath( backup , fdrive, fpath, fname, E_backup );
  90. #endif /* __TURBOC__ */
  91.  
  92.    remove( backup );
  93.  
  94.    if (rename( input, backup ))
  95.    {
  96.       printerr( backup );
  97.       printmsg(1,"Unable to rename %s to %s\n", input, backup );
  98.       return 1;
  99.  
  100.    } /* if (rename( input, backup )) */
  101.    else
  102.       return 0;
  103.  
  104. } /* filebkup */
  105.