G:/ScriptBasic/source/uniqfnam.c

Go to the documentation of this file.
00001 /* 
00002 FILE:   uniqfnam.c
00003 HEADER: uniqfnam.h
00004 
00005 --GNU LGPL
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public
00017 License along with this library; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 TO_HEADER:
00021 
00022 #define UNIQ_FILE_NAME_LENGTH 32
00023 
00024 */
00025 
00026 
00027 /*POD
00028 =H Creating unique file name
00029 =abstract
00030 The function in this file is used to create a unique file name for
00031 internal storage. This is used in code cache and preprocessing
00032 operations.
00033 
00034 =toc
00035 
00036 CUT*/
00037 
00038 #include <string.h>
00039 
00040 #include "tools/global.h"
00041 #include "tools/md5.h"
00042 
00043 /*POD
00044 =section uniqfnam
00045 =H Calculate unique file name
00046 
00047 The input file name should be the name of a file including the full path
00048 to the file name. The function calculates the MD5 digest of the file name,
00049 which is a 16-byte number and converts it to ASCII and copies the result to
00050 the output argument T<pszOutputFileName>. The argument T<pszOutputFileName>
00051 should point to a buffer of at least 33 characters (32 characters plus the
00052 ZCHAR).
00053 
00054 /*FUNCTION*/
00055 void uniqfnam(char *pszInputFileName,
00056               char *pszOutputFileName
00057   ){
00058 /*noverbatim
00059 CUT*/
00060   MD5_CTX MyContext;
00061   unsigned char digest[16];
00062   int i;
00063 
00064   /* calculate the MD5 digest of the file name */
00065   MD5Init(&MyContext);
00066   MD5Update(&MyContext, pszInputFileName, strlen(pszInputFileName));
00067   MD5Final(digest,&MyContext);
00068 
00069   /* convert the digest to ASCII */
00070   for( i = 0 ; i < 16 ; i++ ){
00071     pszOutputFileName[2*i] = 'A' + (digest[i]&0x0F);
00072     digest[i] >>= 4;
00073     pszOutputFileName[2*i+1] = 'A' + (digest[i]&0x0F);
00074     }
00075   pszOutputFileName[32] = (char)0;
00076   }

Generated on Sun Mar 12 23:56:32 2006 for ScriptBasic by  doxygen 1.4.6-NO