Changeset 135


Ignore:
Timestamp:
07/22/2009 09:06:18 PM (14 years ago)
Author:
marcus
Message:

r85 | svn | 2009-06-20 23:06:31 +0200 (Sa, 20 Jun 2009) | 1 line

fixed bug overwriting existing files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • SH_SHM/trunk/source/seed_io/seed_tidy.c

    r108 r135  
    112112static void TdFixTbnames( char name[] ); 
    113113int TdQsortCompare( const void *d1, const void *d2 ); 
     114static void TdUniqueFilename( char fname[] ); 
    114115 
    115116 
     
    974975                                nametime.min, chan ); 
    975976                } /*endif*/ 
     977                TdUniqueFilename( fname ); 
    976978                recnum = 1; 
    977979                fd = 1; 
     
    10101012 
    10111013 
     1014 
     1015/*---------------------------------------------------------------------------*/ 
     1016 
     1017 
     1018static void TdUniqueFilename( char fname[] ) 
     1019 
     1020/* Adds counter to filename until a non existing filename is reached 
     1021 * 
     1022 * parameters of routine 
     1023 * char      fname[];        modify; name to be checked/modified 
     1024 */ 
     1025{ 
     1026        /* local variables */ 
     1027        int    cnt;                       /* counter */ 
     1028        FILE   *fp;                       /* file pointer */ 
     1029        char   fnamecopy[cBcFileLth+1];   /* copy of filename */ 
     1030 
     1031        /* executable code */ 
     1032 
     1033        /* if file does not exist, just leave everything unchanged and return */ 
     1034        fp = fopen( fname, "r" ); 
     1035        if  (fp == NULL) 
     1036                return; 
     1037 
     1038        /* if file is already existing change it using a counter */ 
     1039        strcpy( fnamecopy, fname ); 
     1040        cnt = 1; 
     1041        do { 
     1042                fclose( fp ); 
     1043                sprintf( fname, "%s.%d", fnamecopy, cnt ); 
     1044                cnt++; 
     1045                fp = fopen( fname, "r" ); 
     1046        } while (fp != NULL); 
     1047 
     1048} /* end of TdUniqueFilename */ 
    10121049 
    10131050/*---------------------------------------------------------------------------*/ 
Note: See TracChangeset for help on using the changeset viewer.