2 * $RCSId: xc/lib/fontconfig/src/fccache.c,v 1.12 2002/08/22 07:36:44 keithp Exp $
4 * Copyright © 2000 Keith Packard
5 * Copyright © 2005 Patrick Lam
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of Keith Packard not be used in
12 * advertising or publicity pertaining to distribution of the software without
13 * specific, written prior permission. Keith Packard makes no
14 * representations about the suitability of this software for any purpose. It
15 * is provided "as is" without express or implied warranty.
17 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23 * PERFORMANCE OF THIS SOFTWARE.
30 #include <sys/types.h>
31 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
33 # include <sys/mman.h>
38 #define ENDIAN_TEST 0x12345678
39 #define MACHINE_SIGNATURE_SIZE (9 + 5*20 + 1)
40 /* for when we don't have sysconf: */
41 #define FC_HARDCODED_PAGESIZE 8192
48 FcDirCacheOpen (FcConfig
*config
, const FcChar8
*dir
, FcChar8
**cache_path
);
51 FcCacheSkipToArch (int fd
, const char * arch
);
54 FcCacheCopyOld (int fd
, int fd_orig
, off_t start
);
57 FcDirCacheProduce (FcFontSet
*set
, FcCache
* metadata
);
60 FcDirCacheConsume (int fd
, const char * dir
, FcFontSet
*set
, FcConfig
*config
);
63 FcCacheNextOffset(off_t w
);
66 FcCacheMachineSignature (void);
69 FcCacheHaveBank (int bank
);
72 FcCacheAddBankDir (int bank
, const char * dir
);
80 static void MD5Init(struct MD5Context
*ctx
);
81 static void MD5Update(struct MD5Context
*ctx
, unsigned char *buf
, unsigned len
);
82 static void MD5Final(unsigned char digest
[16], struct MD5Context
*ctx
);
83 static void MD5Transform(FcChar32 buf
[4], FcChar32 in
[16]);
85 #define FC_DBG_CACHE_REF 1024
88 FcCacheReadString (int fd
, char *dest
, int len
)
96 size
= read (fd
, dest
, len
-1);
101 slen
= strlen (dest
);
103 lseek (fd
, slen
- size
+ 1, SEEK_CUR
);
104 return slen
< len
? dest
: 0;
111 FcCacheSkipString (int fd
)
117 while ( (size
= read (fd
, buf
, sizeof (buf
)-1)) > 0)
123 lseek (fd
, slen
- size
+ 1, SEEK_CUR
);
130 FcCacheWriteString (int fd
, const char *chars
)
132 if (write (fd
, chars
, strlen(chars
)+1) != strlen(chars
)+1)
138 FcGlobalCacheDirDestroy (FcGlobalCacheDir
*d
)
140 FcStrSetDestroy (d
->subdirs
);
141 FcMemFree (FC_MEM_STRING
, strlen (d
->name
)+1);
143 FcMemFree (FC_MEM_CACHE
, sizeof (FcGlobalCacheDir
));
148 FcGlobalCacheCreate (void)
150 FcGlobalCache
*cache
;
152 cache
= malloc (sizeof (FcGlobalCache
));
155 FcMemAlloc (FC_MEM_CACHE
, sizeof (FcGlobalCache
));
157 cache
->updated
= FcFalse
;
163 FcGlobalCacheDestroy (FcGlobalCache
*cache
)
165 FcGlobalCacheDir
*d
, *next
;
167 for (d
= cache
->dirs
; d
; d
= next
)
170 FcGlobalCacheDirDestroy (d
);
172 FcMemFree (FC_MEM_CACHE
, sizeof (FcGlobalCache
));
179 FcGlobalCacheLoad (FcGlobalCache
*cache
,
181 const FcChar8
*cache_file
,
184 char name_buf
[FC_MAX_FILE_LEN
];
185 FcGlobalCacheDir
*d
, *next
;
186 FcFileTime config_time
= FcConfigModifiedTime (config
);
187 char * current_arch_machine_name
;
188 char candidate_arch_machine_name
[MACHINE_SIGNATURE_SIZE
+ 9];
189 off_t current_arch_start
;
191 struct stat cache_stat
, dir_stat
;
192 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
194 if (stat ((char *) cache_file
, &cache_stat
) < 0)
197 cache
->fd
= open ((char *) cache_file
, O_RDONLY
| O_BINARY
);
201 cache
->updated
= FcFalse
;
203 if (!FcCacheReadString (cache
->fd
, name_buf
, sizeof (name_buf
)))
204 goto bail_and_destroy
;
205 if (strcmp (name_buf
, FC_GLOBAL_MAGIC_COOKIE
) != 0)
206 goto bail_and_destroy
;
208 current_arch_machine_name
= FcCacheMachineSignature ();
209 current_arch_start
= FcCacheSkipToArch(cache
->fd
,
210 current_arch_machine_name
);
211 if (current_arch_start
< 0)
214 lseek (cache
->fd
, current_arch_start
, SEEK_SET
);
215 if (!FcCacheReadString (cache
->fd
, candidate_arch_machine_name
,
216 sizeof (candidate_arch_machine_name
)))
217 goto bail_and_destroy
;
218 if (strlen(candidate_arch_machine_name
) == 0)
219 goto bail_and_destroy
;
225 if (!FcCacheReadString (cache
->fd
, name_buf
, sizeof (name_buf
)) ||
229 /* Directory must be older than the global cache file; also
230 cache must be newer than the config file. */
231 if (stat ((char *) name_buf
, &dir_stat
) < 0 ||
232 dir_stat
.st_mtime
> cache_stat
.st_mtime
||
233 (config_time
.set
&& cache_stat
.st_mtime
< config_time
.time
))
238 FcStrSetAdd (staleDirs
, (FcChar8
*)name_buf
);
241 while (FcCacheReadString (cache
->fd
, subdirName
,
242 sizeof (subdirName
)) &&
246 if (read (cache
->fd
, &md
, sizeof (FcCache
)) != sizeof(FcCache
))
248 perror ("read metadata");
251 off
= FcCacheNextOffset (lseek(cache
->fd
, 0, SEEK_CUR
)) + md
.count
;
252 if (lseek (cache
->fd
, off
, SEEK_SET
) != off
)
260 d
= malloc (sizeof (FcGlobalCacheDir
));
264 d
->next
= cache
->dirs
;
267 d
->name
= (char *)FcStrCopy ((FcChar8
*)name_buf
);
269 d
->state
= FcGCDirFileRead
;
271 d
->subdirs
= FcStrSetCreate();
274 if (!FcCacheReadString (cache
->fd
, subdirName
,
275 sizeof (subdirName
)) ||
276 !strlen (subdirName
))
278 FcStrSetAdd (d
->subdirs
, (FcChar8
*)subdirName
);
281 d
->offset
= lseek (cache
->fd
, 0, SEEK_CUR
);
282 if (read (cache
->fd
, &d
->metadata
, sizeof (FcCache
)) != sizeof (FcCache
))
284 targ
= FcCacheNextOffset (lseek(cache
->fd
, 0, SEEK_CUR
)) + d
->metadata
.count
;
285 if (lseek (cache
->fd
, targ
, SEEK_SET
) != targ
)
291 for (d
= cache
->dirs
; d
; d
= next
)
306 if (stat ((char *) cache_file
, &cache_stat
) == 0)
307 unlink ((char *)cache_file
);
314 FcGlobalCacheReadDir (FcFontSet
*set
, FcStrSet
*dirs
, FcGlobalCache
* cache
, const char *dir
, FcConfig
*config
)
323 if (!(dir
= (char *)FcConfigNormalizeFontDir (config
, (FcChar8
*)dir
)))
324 return FcFalse
; /* non-existing directory */
326 for (d
= cache
->dirs
; d
; d
= d
->next
)
328 if (strcmp (d
->name
, dir
) == 0)
330 if (d
->state
== FcGCDirDisabled
)
333 if (d
->state
== FcGCDirFileRead
)
335 lseek (cache
->fd
, d
->offset
, SEEK_SET
);
336 if (!FcDirCacheConsume (cache
->fd
, d
->name
, set
, config
))
339 for (i
= 0; i
< d
->subdirs
->num
; i
++)
340 FcStrSetAdd (dirs
, (FcChar8
*)d
->subdirs
->strs
[i
]);
342 d
->state
= FcGCDirConsumed
;
351 static FcGlobalCacheDir
*
352 FcGlobalCacheDirFind (FcGlobalCache
*cache
, const char *name
)
354 FcGlobalCacheDir
* d
;
359 for (d
= cache
->dirs
; d
; d
= d
->next
)
360 if (strcmp((const char *)d
->name
, (const char *)name
) == 0)
367 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
369 const char *orig_name
,
377 name
= (char *)FcConfigNormalizeFontDir (config
, (FcChar8
*)orig_name
);
380 fprintf(stderr
, "Invalid directory name %s\n", orig_name
);
384 d
= FcGlobalCacheDirFind (cache
, name
);
388 d
= malloc (sizeof (FcGlobalCacheDir
));
391 d
->next
= cache
->dirs
;
394 /* free old resources */
395 FcStrFree ((FcChar8
*)d
->name
);
397 FcStrSetDestroy (d
->subdirs
);
400 cache
->updated
= FcTrue
;
402 d
->name
= (char *)FcStrCopy ((FcChar8
*)name
);
403 d
->ent
= FcDirCacheProduce (set
, &d
->metadata
);
405 d
->subdirs
= FcStrSetCreate();
406 d
->state
= FcGCDirUpdated
;
407 for (i
= 0; i
< dirs
->num
; i
++)
408 FcStrSetAdd (d
->subdirs
, dirs
->strs
[i
]);
413 FcGlobalCacheSave (FcGlobalCache
*cache
,
414 const FcChar8
*cache_file
,
418 FcGlobalCacheDir
*dir
;
420 off_t current_arch_start
= 0, truncate_to
;
421 char * current_arch_machine_name
, * header
;
426 #if defined (HAVE_GETUID) && defined (HAVE_GETEUID)
427 /* Set-UID programs can't safely update the cache */
428 if (getuid () != geteuid ())
432 atomic
= FcAtomicCreate (cache_file
);
436 if (!FcAtomicLock (atomic
))
438 fd
= open ((char *) FcAtomicNewFile(atomic
), O_RDWR
| O_CREAT
| O_BINARY
,
442 FcCacheWriteString (fd
, FC_GLOBAL_MAGIC_COOKIE
);
444 fd_orig
= open ((char *) FcAtomicOrigFile(atomic
), O_RDONLY
| O_BINARY
);
446 current_arch_machine_name
= FcCacheMachineSignature ();
448 current_arch_start
= 0;
450 current_arch_start
= FcCacheSkipToArch (fd_orig
,
451 current_arch_machine_name
);
453 if (current_arch_start
< 0)
455 off_t i
= lseek(fd_orig
, 0, SEEK_END
);
456 if (i
< strlen (FC_GLOBAL_MAGIC_COOKIE
)+1)
457 i
= strlen (FC_GLOBAL_MAGIC_COOKIE
)+1;
458 current_arch_start
= FcCacheNextOffset (i
);
461 if (!FcCacheCopyOld(fd
, fd_orig
, current_arch_start
))
464 current_arch_start
= lseek(fd
, 0, SEEK_CUR
);
465 #if defined (HAVE_FTRUNCATE)
466 if (ftruncate (fd
, current_arch_start
) == -1)
469 #if defined (HAVE_CHSIZE)
470 if (chsize (fd
, current_arch_start
) == -1)
477 header
= malloc (10 + strlen (current_arch_machine_name
));
481 truncate_to
= current_arch_start
+ strlen(current_arch_machine_name
) + 11;
482 for (dir
= cache
->dirs
; dir
; dir
= dir
->next
)
486 if (dir
->state
== FcGCDirDisabled
)
488 truncate_to
+= strlen(dir
->name
) + 1;
489 truncate_to
+= sizeof (FcCache
);
490 truncate_to
= FcCacheNextOffset (truncate_to
);
491 truncate_to
+= dir
->metadata
.count
;
493 for (i
= 0; i
< dir
->subdirs
->size
; i
++)
494 truncate_to
+= strlen((char *)dir
->subdirs
->strs
[i
]) + 1;
497 truncate_to
-= current_arch_start
;
499 sprintf (header
, "%8x ", (int)truncate_to
);
500 strcat (header
, current_arch_machine_name
);
501 if (!FcCacheWriteString (fd
, header
))
506 for (dir
= cache
->dirs
; dir
; dir
= dir
->next
)
512 if (!dir
->name
|| dir
->state
== FcGCDirDisabled
)
514 d
= (const char *)FcConfigNormalizeFontDir (config
, (const FcChar8
*)dir
->name
);
518 if (dir
->metadata
.count
&& !dir
->ent
)
520 if (dir
->state
== FcGCDirUpdated
|| fd_orig
< 0)
522 fprintf(stderr
, "Invalid metadata entry for %s, skipping...\n", d
);
525 /* copy the old content */
526 dir
->ent
= malloc (dir
->metadata
.count
);
529 perror("malloc error");
532 off
= FcCacheNextOffset (dir
->offset
+ sizeof(FcCache
));
533 if (lseek (fd_orig
, off
, SEEK_SET
) != off
)
539 if (read (fd_orig
, dir
->ent
, dir
->metadata
.count
)
540 != dir
->metadata
.count
)
548 FcCacheWriteString (fd
, d
);
550 for (i
= 0; i
< dir
->subdirs
->size
; i
++)
551 FcCacheWriteString (fd
, (char *)dir
->subdirs
->strs
[i
]);
552 FcCacheWriteString (fd
, "");
554 if (write (fd
, &dir
->metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
556 perror ("write metadata");
560 off
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
561 if (lseek (fd
, off
, SEEK_SET
) != off
)
567 if (dir
->metadata
.count
)
569 if (write (fd
, dir
->ent
, dir
->metadata
.count
) != dir
->metadata
.count
)
571 perror ("write dirent");
578 FcCacheWriteString (fd
, "");
580 if (close (fd
) == -1)
586 if (!FcAtomicReplaceOrig (atomic
))
589 FcAtomicUnlock (atomic
);
590 FcAtomicDestroy (atomic
);
592 cache
->updated
= FcFalse
;
603 FcAtomicDeleteNew (atomic
);
605 FcAtomicUnlock (atomic
);
607 FcAtomicDestroy (atomic
);
612 * Find the next presumably-mmapable offset after the supplied file
616 FcCacheNextOffset(off_t w
)
618 static long pagesize
= -1;
624 #if defined (HAVE_SYSCONF)
625 pagesize
= sysconf(_SC_PAGESIZE
);
627 pagesize
= FC_HARDCODED_PAGESIZE
;
629 if (w
% pagesize
== 0)
632 return ((w
/ pagesize
)+1)*pagesize
;
635 /* return the address of the segment for the provided arch,
636 * or -1 if arch not found */
638 FcCacheSkipToArch (int fd
, const char * arch
)
640 char candidate_arch_machine_name_count
[MACHINE_SIGNATURE_SIZE
+ 9];
641 char * candidate_arch
;
642 off_t current_arch_start
= 0;
644 lseek (fd
, 0, SEEK_SET
);
645 FcCacheSkipString (fd
);
646 current_arch_start
= lseek (fd
, 0, SEEK_CUR
);
648 /* skip arches that are not the current arch */
653 if (lseek (fd
, current_arch_start
, SEEK_SET
) != current_arch_start
)
656 if (FcCacheReadString (fd
, candidate_arch_machine_name_count
,
657 sizeof (candidate_arch_machine_name_count
)) == 0)
659 if (!strlen(candidate_arch_machine_name_count
))
661 bs
= strtol(candidate_arch_machine_name_count
, &candidate_arch
, 16);
663 /* count = 0 should probably be distinguished from the !bs condition */
664 if (!bs
|| bs
< strlen (candidate_arch_machine_name_count
))
667 candidate_arch
++; /* skip leading space */
669 if (strcmp (candidate_arch
, arch
)==0)
670 return current_arch_start
;
671 current_arch_start
+= bs
;
672 current_arch_start
= FcCacheNextOffset (current_arch_start
);
676 /* Cuts out the segment at the file pointer (moves everything else
677 * down to cover it), and leaves the file pointer at the end of the
680 FcCacheCopyOld (int fd
, int fd_orig
, off_t start
)
682 char * buf
= malloc (8192);
683 char candidate_arch_machine_name
[MACHINE_SIGNATURE_SIZE
+ 9];
685 int c
, bytes_skipped
;
692 lseek (fd
, 0, SEEK_SET
); lseek (fd_orig
, 0, SEEK_SET
);
693 FcCacheSkipString (fd
); FcCacheSkipString (fd_orig
);
700 if ((c
= read (fd_orig
, buf
, b
)) <= 0)
702 if (write (fd
, buf
, c
) < 0)
709 lseek (fd
, start
, SEEK_SET
);
710 if (FcCacheReadString (fd
, candidate_arch_machine_name
,
711 sizeof (candidate_arch_machine_name
)) == 0)
713 if (!strlen(candidate_arch_machine_name
))
716 bs
= strtol(candidate_arch_machine_name
, 0, 16);
723 lseek (fd
, start
+bs
+bytes_skipped
, SEEK_SET
);
724 if ((c
= read (fd
, buf
, 8192)) <= 0)
726 lseek (fd
, start
+bytes_skipped
, SEEK_SET
);
727 if (write (fd
, buf
, c
) < 0)
732 lseek (fd
, start
+bytes_skipped
, SEEK_SET
);
743 /* Does not check that the cache has the appropriate arch section. */
744 /* Also, this can be fooled if the original location has a stale
745 * cache, and the hashed location has an up-to-date cache. Oh well,
746 * sucks to be you in that case! */
748 FcDirCacheValid (const FcChar8
*dir
, FcConfig
*config
)
750 struct stat file_stat
, dir_stat
;
753 if (stat ((char *) dir
, &dir_stat
) < 0)
756 fd
= FcDirCacheOpen (config
, dir
, NULL
);
760 if (fstat (fd
, &file_stat
) < 0)
766 * If the directory has been modified more recently than
767 * the cache file, the cache is not valid
769 if (dir_stat
.st_mtime
> file_stat
.st_mtime
)
779 /* Assumes that the cache file in 'dir' exists.
780 * Checks that the cache has the appropriate arch section. */
782 FcDirCacheHasCurrentArch (const FcChar8
*dir
, FcConfig
*config
)
785 off_t current_arch_start
;
786 char *current_arch_machine_name
;
788 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
790 fd
= FcDirCacheOpen (config
, dir
, NULL
);
794 current_arch_machine_name
= FcCacheMachineSignature();
795 current_arch_start
= FcCacheSkipToArch(fd
, current_arch_machine_name
);
797 if (current_arch_start
>= 0)
799 if (lseek (fd
, current_arch_start
, SEEK_SET
) != current_arch_start
)
802 FcCacheSkipString (fd
);
804 while (FcCacheReadString (fd
, subdirName
, sizeof (subdirName
)) && strlen (subdirName
) > 0)
807 if (read(fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
810 if (metadata
.magic
!= FC_CACHE_MAGIC
)
816 if (current_arch_start
< 0)
827 #define CACHEBASE_LEN (1 + 32 + sizeof (FC_CACHE_SUFFIX))
829 static const char bin2hex
[] = { '0', '1', '2', '3',
832 'c', 'd', 'e', 'f' };
835 FcDirCacheBasename (const FcChar8
* dir
, FcChar8 cache_base
[CACHEBASE_LEN
])
837 unsigned char hash
[16];
840 struct MD5Context ctx
;
843 MD5Update (&ctx
, (unsigned char *)dir
, strlen ((char *) dir
));
845 MD5Final (hash
, &ctx
);
848 hex_hash
= cache_base
+ 1;
849 for (cnt
= 0; cnt
< 16; ++cnt
)
851 hex_hash
[2*cnt
] = bin2hex
[hash
[cnt
] >> 4];
852 hex_hash
[2*cnt
+1] = bin2hex
[hash
[cnt
] & 0xf];
855 strcat ((char *) cache_base
, FC_CACHE_SUFFIX
);
861 FcDirCacheUnlink (const FcChar8
*dir
, FcConfig
*config
)
864 FcChar8
*cache_hashed
= NULL
;
865 FcChar8 cache_base
[CACHEBASE_LEN
];
868 char dir_buf
[FC_MAX_FILE_LEN
];
870 dir
= FcConfigNormalizeFontDir (config
, dir
);
872 FcDirCacheBasename (dir
, cache_base
);
874 list
= FcStrListCreate (config
->cacheDirs
);
878 while ((cache_dir
= FcStrListNext (list
)))
880 cache_hashed
= FcStrPlus (cache_dir
, cache_base
);
883 fd
= open((char *) cache_hashed
, O_RDONLY
| O_BINARY
);
884 FcStrFree (cache_hashed
);
887 if (FcCacheReadString (fd
, dir_buf
, sizeof (dir_buf
)) &&
888 strcmp (dir_buf
, (char *) dir
) == 0)
891 if (unlink ((char *) cache_hashed
) < 0)
897 FcStrListDone (list
);
898 /* return FcFalse if something went wrong */
905 FcCacheReadDirs (FcConfig
* config
, FcGlobalCache
* cache
,
906 FcStrList
*list
, FcFontSet
* set
, FcStrSet
*processed_dirs
)
916 * Read in the results from 'list'.
918 while ((dir
= FcStrListNext (list
)))
920 if (!FcConfigAcceptFilename (config
, dir
))
923 /* Skip this directory if already updated
924 * to avoid the looped directories via symlinks
925 * Clearly a dir not in fonts.conf shouldn't be globally cached.
927 dir
= (FcChar8
*)FcConfigNormalizeFontDir (config
, dir
);
931 if (FcStrSetMember (processed_dirs
, dir
))
933 if (!FcStrSetAdd (processed_dirs
, dir
))
936 subdirs
= FcStrSetCreate ();
939 fprintf (stderr
, "Can't create directory set\n");
944 if (access ((char *) dir
, X_OK
) < 0)
952 fprintf (stderr
, "\"%s\": ", dir
);
956 FcStrSetDestroy (subdirs
);
959 if (stat ((char *) dir
, &statb
) == -1)
961 fprintf (stderr
, "\"%s\": ", dir
);
963 FcStrSetDestroy (subdirs
);
967 if (!S_ISDIR (statb
.st_mode
))
969 fprintf (stderr
, "\"%s\": not a directory, skipping\n", dir
);
970 FcStrSetDestroy (subdirs
);
973 if (FcDirCacheValid (dir
, config
) &&
974 FcDirCacheHasCurrentArch (dir
, config
) &&
975 FcDirCacheRead (set
, subdirs
, dir
, config
))
977 /* if an old entry is found in the global cache, disable it */
978 if ((d
= FcGlobalCacheDirFind (cache
, (const char *)dir
)) != NULL
)
980 d
->state
= FcGCDirDisabled
;
981 /* save the updated config later without this entry */
982 cache
->updated
= FcTrue
;
987 if (FcDebug () & FC_DBG_FONTSET
)
988 printf ("cache scan dir %s\n", dir
);
990 FcDirScanConfig (set
, subdirs
, cache
,
991 config
->blanks
, dir
, FcFalse
, config
);
993 sublist
= FcStrListCreate (subdirs
);
994 FcStrSetDestroy (subdirs
);
997 fprintf (stderr
, "Can't create subdir list in \"%s\"\n", dir
);
1001 ret
+= FcCacheReadDirs (config
, cache
, sublist
, set
, processed_dirs
);
1003 FcStrListDone (list
);
1008 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
)
1010 FcFontSet
*s
= FcFontSetCreate();
1011 FcStrSet
*processed_dirs
;
1016 processed_dirs
= FcStrSetCreate();
1017 if (!processed_dirs
)
1020 if (FcCacheReadDirs (config
, cache
, FcConfigGetConfigDirs (config
), s
, processed_dirs
))
1023 FcStrSetDestroy (processed_dirs
);
1027 FcStrSetDestroy (processed_dirs
);
1029 FcFontSetDestroy (s
);
1033 /* Opens the cache file for 'dir' for reading.
1034 * This searches the list of cache dirs for the relevant cache file,
1035 * returning the first one found.
1038 FcDirCacheOpen (FcConfig
*config
, const FcChar8
*dir
, FcChar8
**cache_path
)
1041 FcChar8
*cache_hashed
= NULL
;
1042 FcChar8 cache_base
[CACHEBASE_LEN
];
1045 char dir_buf
[FC_MAX_FILE_LEN
];
1047 FcDirCacheBasename (dir
, cache_base
);
1049 list
= FcStrListCreate (config
->cacheDirs
);
1053 while ((cache_dir
= FcStrListNext (list
)))
1055 cache_hashed
= FcStrPlus (cache_dir
, cache_base
);
1058 fd
= open((char *) cache_hashed
, O_RDONLY
| O_BINARY
);
1061 FcStrFree (cache_hashed
);
1063 FcStrListDone (list
);
1068 if (!FcCacheReadString (fd
, dir_buf
, sizeof (dir_buf
)) ||
1069 strcmp (dir_buf
, (char *) dir
) != 0)
1072 FcStrFree (cache_hashed
);
1077 *cache_path
= cache_hashed
;
1079 FcStrFree (cache_hashed
);
1084 /* read serialized state from the cache file */
1086 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
)
1089 char *current_arch_machine_name
;
1090 char candidate_arch_machine_name
[9+MACHINE_SIGNATURE_SIZE
];
1091 off_t current_arch_start
= 0;
1092 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
1094 fd
= FcDirCacheOpen (config
, dir
, NULL
);
1098 current_arch_machine_name
= FcCacheMachineSignature();
1099 current_arch_start
= FcCacheSkipToArch(fd
,
1100 current_arch_machine_name
);
1101 if (current_arch_start
< 0)
1104 lseek (fd
, current_arch_start
, SEEK_SET
);
1105 if (FcCacheReadString (fd
, candidate_arch_machine_name
,
1106 sizeof (candidate_arch_machine_name
)) == 0)
1109 while (FcCacheReadString (fd
, subdirName
, sizeof (subdirName
)) && strlen (subdirName
) > 0)
1110 FcStrSetAdd (dirs
, (FcChar8
*)subdirName
);
1112 if (!FcDirCacheConsume (fd
, (const char *)dir
, set
, config
))
1125 FcDirCacheConsume (int fd
, const char * dir
, FcFontSet
*set
, FcConfig
*config
)
1128 void * current_dir_block
;
1131 if (read(fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
1133 if (metadata
.magic
!= FC_CACHE_MAGIC
)
1136 if (!metadata
.count
)
1138 pos
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
1139 lseek (fd
, pos
, SEEK_SET
);
1141 FcConfigAddFontDir (config
, (FcChar8
*)dir
);
1145 pos
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
1147 /* This is not failsafe (multi-arches can break it),
1148 * but fd has got to have at least as many bytes as
1149 * metadata.count, or something's going to go horribly wrong. */
1150 if (pos
== (off_t
)-1)
1153 endpos
= lseek (fd
, 0, SEEK_END
);
1154 if (endpos
== (off_t
)-1 || endpos
- pos
< metadata
.count
)
1156 if (lseek (fd
, pos
, SEEK_SET
) == -1)
1159 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
1160 current_dir_block
= mmap (0, metadata
.count
,
1161 PROT_READ
, MAP_SHARED
, fd
, pos
);
1162 if (current_dir_block
== MAP_FAILED
)
1164 #elif defined(_WIN32)
1168 hFileMap
= CreateFileMapping((HANDLE
) _get_osfhandle(fd
), NULL
, PAGE_READONLY
, 0, 0, NULL
);
1169 if (hFileMap
== NULL
)
1172 current_dir_block
= MapViewOfFile (hFileMap
, FILE_MAP_READ
, 0, 0, metadata
.count
+ pos
);
1173 if (current_dir_block
== NULL
)
1175 CloseHandle (hFileMap
);
1179 current_dir_block
= (void *)((char *)current_dir_block
+ pos
);
1182 current_dir_block
= malloc (metadata
.count
);
1183 if (!current_dir_block
)
1186 /* could also use CreateMappedViewOfFile under MinGW... */
1187 if (read (fd
, current_dir_block
, metadata
.count
) != metadata
.count
)
1190 lseek (fd
, pos
+metadata
.count
, SEEK_SET
);
1192 FcCacheAddBankDir (metadata
.bank
, dir
);
1194 FcConfigAddFontDir (config
, (FcChar8
*)dir
);
1196 if (!FcFontSetUnserialize (&metadata
, set
, current_dir_block
))
1201 #if !(defined(HAVE_MMAP) || defined(__CYGWIN__))
1202 free (current_dir_block
);
1208 FcDirCacheProduce (FcFontSet
*set
, FcCache
*metadata
)
1210 void * current_dir_block
, * final_dir_block
;
1211 static unsigned int rand_state
= 0;
1212 int bank
, needed_bytes_no_align
;
1214 #if defined (HAVE_RAND_R)
1216 rand_state
= time(0L);
1217 bank
= rand_r(&rand_state
);
1219 while (FcCacheHaveBank(bank
))
1220 bank
= rand_r(&rand_state
);
1229 while (FcCacheHaveBank(bank
))
1233 memset (metadata
, 0, sizeof(FcCache
));
1235 needed_bytes_no_align
= FcFontSetNeededBytes (set
);
1236 metadata
->count
= needed_bytes_no_align
+
1237 FcFontSetNeededBytesAlign ();
1238 metadata
->magic
= FC_CACHE_MAGIC
;
1239 metadata
->bank
= bank
;
1241 if (!needed_bytes_no_align
) /* not a failure, no fonts to write */
1243 /* no, you don't really need to write any bytes at all. */
1244 metadata
->count
= 0;
1248 current_dir_block
= malloc (metadata
->count
);
1249 if (!current_dir_block
)
1251 /* shut up valgrind */
1252 memset (current_dir_block
, 0, metadata
->count
);
1253 final_dir_block
= FcFontSetDistributeBytes (metadata
, current_dir_block
);
1255 if ((void *)((char *)current_dir_block
+metadata
->count
) < final_dir_block
)
1258 if (!FcFontSetSerialize (bank
, set
))
1261 return current_dir_block
;
1264 free (current_dir_block
);
1269 FcMakeDirectory (const FcChar8
*dir
)
1274 if (strlen ((char *) dir
) == 0)
1277 parent
= FcStrDirname (dir
);
1280 if (access ((char *) parent
, W_OK
|X_OK
) == 0)
1281 ret
= mkdir ((char *) dir
, 0777) == 0;
1282 else if (access ((char *) parent
, F_OK
) == -1)
1283 ret
= FcMakeDirectory (parent
) && (mkdir ((char *) dir
, 0777) == 0);
1290 /* write serialized state to the cache file */
1292 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
*dirs
, const FcChar8
*dir
, FcConfig
*config
)
1294 FcChar8 cache_base
[CACHEBASE_LEN
];
1295 FcChar8
*cache_hashed
;
1296 int fd
, fd_orig
, i
, dirs_count
;
1299 off_t current_arch_start
= 0, truncate_to
;
1301 char *current_arch_machine_name
, * header
;
1302 void *current_dir_block
= 0;
1305 dir
= FcConfigNormalizeFontDir (FcConfigGetCurrent(), dir
);
1310 * Check for an existing cache file and dump stuff in the same place
1312 fd
= FcDirCacheOpen (config
, dir
, &cache_hashed
);
1317 list
= FcStrListCreate (config
->cacheDirs
);
1320 while ((cache_dir
= FcStrListNext (list
))) {
1321 if (access ((char *) cache_dir
, W_OK
|X_OK
) == 0)
1324 * If the directory doesn't exist, try to create it
1326 if (access ((char *) cache_dir
, F_OK
) == -1) {
1327 if (FcMakeDirectory (cache_dir
))
1331 FcStrListDone (list
);
1334 FcDirCacheBasename (dir
, cache_base
);
1335 cache_hashed
= FcStrPlus (cache_dir
, cache_base
);
1340 current_dir_block
= FcDirCacheProduce (set
, &metadata
);
1342 if (metadata
.count
&& !current_dir_block
)
1345 if (FcDebug () & FC_DBG_CACHE
)
1346 printf ("FcDirCacheWriteDir dir \"%s\" file \"%s\"\n",
1349 atomic
= FcAtomicCreate ((FcChar8
*)cache_hashed
);
1353 if (!FcAtomicLock (atomic
))
1356 /* open the original file to save relevant portions */
1357 fd_orig
= open((char *)FcAtomicOrigFile (atomic
), O_RDONLY
| O_BINARY
);
1359 fd
= open((char *)FcAtomicNewFile (atomic
), O_RDWR
| O_CREAT
| O_BINARY
, 0666);
1363 FcCacheWriteString (fd
, (char *) dir
);
1365 current_arch_machine_name
= FcCacheMachineSignature ();
1366 current_arch_start
= 0;
1369 current_arch_start
=
1370 FcCacheSkipToArch(fd_orig
, current_arch_machine_name
);
1372 if (current_arch_start
< 0)
1374 off_t offset
= lseek(fd_orig
, 0, SEEK_END
);
1375 current_arch_start
= FcCacheNextOffset (offset
);
1378 if (fd_orig
!= -1 && !FcCacheCopyOld(fd
, fd_orig
, current_arch_start
))
1384 current_arch_start
= lseek(fd
, 0, SEEK_CUR
);
1385 #if defined (HAVE_FTRUNCATE)
1386 if (ftruncate (fd
, current_arch_start
) == -1)
1389 #if defined (HAVE_CHSIZE)
1390 if (chsize (fd
, current_arch_start
) == -1)
1397 /* allocate space for subdir names in this block */
1399 for (i
= 0; i
< dirs
->size
; i
++)
1400 dirs_count
+= strlen((char *)dirs
->strs
[i
]) + 1;
1403 /* now write the address of the next offset */
1404 truncate_to
= FcCacheNextOffset (FcCacheNextOffset (current_arch_start
+ sizeof (FcCache
) + dirs_count
) + metadata
.count
) - current_arch_start
;
1405 header
= malloc (10 + strlen (current_arch_machine_name
));
1408 sprintf (header
, "%8x ", (int)truncate_to
);
1409 strcat (header
, current_arch_machine_name
);
1410 if (!FcCacheWriteString (fd
, header
))
1413 for (i
= 0; i
< dirs
->size
; i
++)
1414 FcCacheWriteString (fd
, (char *)dirs
->strs
[i
]);
1415 FcCacheWriteString (fd
, "");
1417 if (write (fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
1419 perror("write metadata");
1424 off_t off
= FcCacheNextOffset (lseek(fd
, 0, SEEK_END
));
1425 if (lseek (fd
, off
, SEEK_SET
) != off
)
1427 else if (write (fd
, current_dir_block
, metadata
.count
) !=
1429 perror("write current_dir_block");
1430 free (current_dir_block
);
1431 current_dir_block
= 0;
1434 /* this actually serves to pad out the cache file, if needed */
1435 #if defined (HAVE_FTRUNCATE)
1436 if (ftruncate (fd
, current_arch_start
+ truncate_to
) == -1)
1439 #if defined (HAVE_CHSIZE)
1440 if (chsize (fd
, current_arch_start
+ truncate_to
) == -1)
1449 if (!FcAtomicReplaceOrig(atomic
))
1451 FcStrFree ((FcChar8
*)cache_hashed
);
1452 FcAtomicUnlock (atomic
);
1453 FcAtomicDestroy (atomic
);
1461 FcAtomicUnlock (atomic
);
1463 FcAtomicDestroy (atomic
);
1465 FcStrFree ((FcChar8
*)cache_hashed
);
1466 if (current_dir_block
)
1467 free (current_dir_block
);
1472 FcCacheMachineSignature ()
1474 static char buf
[MACHINE_SIGNATURE_SIZE
];
1475 int32_t magic
= ENDIAN_TEST
;
1476 char * m
= (char *)&magic
;
1478 sprintf (buf
, "%2x%2x%2x%2x "
1479 "%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x "
1480 "%4x %4x %4x %4x %4x %4x %4x %4x\n",
1481 m
[0], m
[1], m
[2], m
[3],
1482 (unsigned int)sizeof (char),
1483 (unsigned int)sizeof (char *),
1484 (unsigned int)sizeof (int),
1485 (unsigned int)sizeof (FcPattern
),
1486 (unsigned int)sizeof (FcPatternEltPtr
),
1487 (unsigned int)sizeof (struct _FcPatternElt
*),
1488 (unsigned int)sizeof (FcPatternElt
),
1489 (unsigned int)sizeof (FcObjectPtr
),
1490 (unsigned int)sizeof (FcValueListPtr
),
1491 (unsigned int)sizeof (FcValue
),
1492 (unsigned int)sizeof (FcValueBinding
),
1493 (unsigned int)sizeof (struct _FcValueList
*),
1494 (unsigned int)sizeof (FcCharSet
),
1495 (unsigned int)sizeof (FcCharLeaf
**),
1496 (unsigned int)sizeof (FcChar16
*),
1497 (unsigned int)sizeof (FcChar16
),
1498 (unsigned int)sizeof (FcCharLeaf
),
1499 (unsigned int)sizeof (FcChar32
),
1500 (unsigned int)sizeof (FcCache
),
1501 #if defined (HAVE_SYSCONF)
1502 (unsigned int)sysconf(_SC_PAGESIZE
));
1504 (unsigned int)FC_HARDCODED_PAGESIZE
);
1510 static int banks_ptr
= 0, banks_alloc
= 0;
1511 int * _fcBankId
= 0, * _fcBankIdx
= 0;
1512 static const char ** bankDirs
= 0;
1515 FcCacheHaveBank (int bank
)
1519 if (bank
< FC_BANK_FIRST
)
1522 for (i
= 0; i
< banks_ptr
; i
++)
1523 if (_fcBankId
[i
] == bank
)
1530 FcCacheBankToIndexMTF (int bank
)
1534 for (i
= 0; i
< banks_ptr
; i
++)
1535 if (_fcBankId
[_fcBankIdx
[i
]] == bank
)
1537 int t
= _fcBankIdx
[i
];
1539 for (j
= i
; j
> 0; j
--)
1540 _fcBankIdx
[j
] = _fcBankIdx
[j
-1];
1545 if (banks_ptr
>= banks_alloc
)
1550 b
= realloc (_fcBankId
, (banks_alloc
+ 4) * sizeof(int));
1555 bidx
= realloc (_fcBankIdx
, (banks_alloc
+ 4) * sizeof(int));
1560 bds
= realloc (bankDirs
, (banks_alloc
+ 4) * sizeof (char *));
1569 _fcBankId
[i
] = bank
;
1575 FcCacheAddBankDir (int bank
, const char * dir
)
1577 int bi
= FcCacheBankToIndexMTF (bank
);
1582 bankDirs
[bi
] = (const char *)FcStrCopy ((FcChar8
*)dir
);
1586 FcCacheFindBankDir (int bank
)
1588 int bi
= FcCacheBankToIndex (bank
);
1589 return bankDirs
[bi
];
1593 * This code implements the MD5 message-digest algorithm.
1594 * The algorithm is due to Ron Rivest. This code was
1595 * written by Colin Plumb in 1993, no copyright is claimed.
1596 * This code is in the public domain; do with it what you wish.
1598 * Equivalent code is available from RSA Data Security, Inc.
1599 * This code has been tested against that, and is equivalent,
1600 * except that you don't need to include two pages of legalese
1603 * To compute the message digest of a chunk of bytes, declare an
1604 * MD5Context structure, pass it to MD5Init, call MD5Update as
1605 * needed on buffers full of bytes, and then call MD5Final, which
1606 * will fill a supplied 16-byte array with the digest.
1610 #define byteReverse(buf, len) /* Nothing */
1613 * Note: this code is harmless on little-endian machines.
1615 void byteReverse(unsigned char *buf
, unsigned longs
)
1619 t
= (FcChar32
) ((unsigned) buf
[3] << 8 | buf
[2]) << 16 |
1620 ((unsigned) buf
[1] << 8 | buf
[0]);
1621 *(FcChar32
*) buf
= t
;
1628 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
1629 * initialization constants.
1631 static void MD5Init(struct MD5Context
*ctx
)
1633 ctx
->buf
[0] = 0x67452301;
1634 ctx
->buf
[1] = 0xefcdab89;
1635 ctx
->buf
[2] = 0x98badcfe;
1636 ctx
->buf
[3] = 0x10325476;
1643 * Update context to reflect the concatenation of another buffer full
1646 static void MD5Update(struct MD5Context
*ctx
, unsigned char *buf
, unsigned len
)
1650 /* Update bitcount */
1653 if ((ctx
->bits
[0] = t
+ ((FcChar32
) len
<< 3)) < t
)
1654 ctx
->bits
[1]++; /* Carry from low to high */
1655 ctx
->bits
[1] += len
>> 29;
1657 t
= (t
>> 3) & 0x3f; /* Bytes already in shsInfo->data */
1659 /* Handle any leading odd-sized chunks */
1662 unsigned char *p
= (unsigned char *) ctx
->in
+ t
;
1666 memcpy(p
, buf
, len
);
1670 byteReverse(ctx
->in
, 16);
1671 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1675 /* Process data in 64-byte chunks */
1678 memcpy(ctx
->in
, buf
, 64);
1679 byteReverse(ctx
->in
, 16);
1680 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1685 /* Handle any remaining bytes of data. */
1687 memcpy(ctx
->in
, buf
, len
);
1691 * Final wrapup - pad to 64-byte boundary with the bit pattern
1692 * 1 0* (64-bit count of bits processed, MSB-first)
1694 static void MD5Final(unsigned char digest
[16], struct MD5Context
*ctx
)
1699 /* Compute number of bytes mod 64 */
1700 count
= (ctx
->bits
[0] >> 3) & 0x3F;
1702 /* Set the first char of padding to 0x80. This is safe since there is
1703 always at least one byte free */
1704 p
= ctx
->in
+ count
;
1707 /* Bytes of padding needed to make 64 bytes */
1708 count
= 64 - 1 - count
;
1710 /* Pad out to 56 mod 64 */
1712 /* Two lots of padding: Pad the first block to 64 bytes */
1713 memset(p
, 0, count
);
1714 byteReverse(ctx
->in
, 16);
1715 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1717 /* Now fill the next block with 56 bytes */
1718 memset(ctx
->in
, 0, 56);
1720 /* Pad block to 56 bytes */
1721 memset(p
, 0, count
- 8);
1723 byteReverse(ctx
->in
, 14);
1725 /* Append length in bits and transform */
1726 ((FcChar32
*) ctx
->in
)[14] = ctx
->bits
[0];
1727 ((FcChar32
*) ctx
->in
)[15] = ctx
->bits
[1];
1729 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1730 byteReverse((unsigned char *) ctx
->buf
, 4);
1731 memcpy(digest
, ctx
->buf
, 16);
1732 memset(ctx
, 0, sizeof(ctx
)); /* In case it's sensitive */
1736 /* The four core functions - F1 is optimized somewhat */
1738 /* #define F1(x, y, z) (x & y | ~x & z) */
1739 #define F1(x, y, z) (z ^ (x & (y ^ z)))
1740 #define F2(x, y, z) F1(z, x, y)
1741 #define F3(x, y, z) (x ^ y ^ z)
1742 #define F4(x, y, z) (y ^ (x | ~z))
1744 /* This is the central step in the MD5 algorithm. */
1745 #define MD5STEP(f, w, x, y, z, data, s) \
1746 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
1749 * The core of the MD5 algorithm, this alters an existing MD5 hash to
1750 * reflect the addition of 16 longwords of new data. MD5Update blocks
1751 * the data and converts bytes into longwords for this routine.
1753 static void MD5Transform(FcChar32 buf
[4], FcChar32 in
[16])
1755 register FcChar32 a
, b
, c
, d
;
1762 MD5STEP(F1
, a
, b
, c
, d
, in
[0] + 0xd76aa478, 7);
1763 MD5STEP(F1
, d
, a
, b
, c
, in
[1] + 0xe8c7b756, 12);
1764 MD5STEP(F1
, c
, d
, a
, b
, in
[2] + 0x242070db, 17);
1765 MD5STEP(F1
, b
, c
, d
, a
, in
[3] + 0xc1bdceee, 22);
1766 MD5STEP(F1
, a
, b
, c
, d
, in
[4] + 0xf57c0faf, 7);
1767 MD5STEP(F1
, d
, a
, b
, c
, in
[5] + 0x4787c62a, 12);
1768 MD5STEP(F1
, c
, d
, a
, b
, in
[6] + 0xa8304613, 17);
1769 MD5STEP(F1
, b
, c
, d
, a
, in
[7] + 0xfd469501, 22);
1770 MD5STEP(F1
, a
, b
, c
, d
, in
[8] + 0x698098d8, 7);
1771 MD5STEP(F1
, d
, a
, b
, c
, in
[9] + 0x8b44f7af, 12);
1772 MD5STEP(F1
, c
, d
, a
, b
, in
[10] + 0xffff5bb1, 17);
1773 MD5STEP(F1
, b
, c
, d
, a
, in
[11] + 0x895cd7be, 22);
1774 MD5STEP(F1
, a
, b
, c
, d
, in
[12] + 0x6b901122, 7);
1775 MD5STEP(F1
, d
, a
, b
, c
, in
[13] + 0xfd987193, 12);
1776 MD5STEP(F1
, c
, d
, a
, b
, in
[14] + 0xa679438e, 17);
1777 MD5STEP(F1
, b
, c
, d
, a
, in
[15] + 0x49b40821, 22);
1779 MD5STEP(F2
, a
, b
, c
, d
, in
[1] + 0xf61e2562, 5);
1780 MD5STEP(F2
, d
, a
, b
, c
, in
[6] + 0xc040b340, 9);
1781 MD5STEP(F2
, c
, d
, a
, b
, in
[11] + 0x265e5a51, 14);
1782 MD5STEP(F2
, b
, c
, d
, a
, in
[0] + 0xe9b6c7aa, 20);
1783 MD5STEP(F2
, a
, b
, c
, d
, in
[5] + 0xd62f105d, 5);
1784 MD5STEP(F2
, d
, a
, b
, c
, in
[10] + 0x02441453, 9);
1785 MD5STEP(F2
, c
, d
, a
, b
, in
[15] + 0xd8a1e681, 14);
1786 MD5STEP(F2
, b
, c
, d
, a
, in
[4] + 0xe7d3fbc8, 20);
1787 MD5STEP(F2
, a
, b
, c
, d
, in
[9] + 0x21e1cde6, 5);
1788 MD5STEP(F2
, d
, a
, b
, c
, in
[14] + 0xc33707d6, 9);
1789 MD5STEP(F2
, c
, d
, a
, b
, in
[3] + 0xf4d50d87, 14);
1790 MD5STEP(F2
, b
, c
, d
, a
, in
[8] + 0x455a14ed, 20);
1791 MD5STEP(F2
, a
, b
, c
, d
, in
[13] + 0xa9e3e905, 5);
1792 MD5STEP(F2
, d
, a
, b
, c
, in
[2] + 0xfcefa3f8, 9);
1793 MD5STEP(F2
, c
, d
, a
, b
, in
[7] + 0x676f02d9, 14);
1794 MD5STEP(F2
, b
, c
, d
, a
, in
[12] + 0x8d2a4c8a, 20);
1796 MD5STEP(F3
, a
, b
, c
, d
, in
[5] + 0xfffa3942, 4);
1797 MD5STEP(F3
, d
, a
, b
, c
, in
[8] + 0x8771f681, 11);
1798 MD5STEP(F3
, c
, d
, a
, b
, in
[11] + 0x6d9d6122, 16);
1799 MD5STEP(F3
, b
, c
, d
, a
, in
[14] + 0xfde5380c, 23);
1800 MD5STEP(F3
, a
, b
, c
, d
, in
[1] + 0xa4beea44, 4);
1801 MD5STEP(F3
, d
, a
, b
, c
, in
[4] + 0x4bdecfa9, 11);
1802 MD5STEP(F3
, c
, d
, a
, b
, in
[7] + 0xf6bb4b60, 16);
1803 MD5STEP(F3
, b
, c
, d
, a
, in
[10] + 0xbebfbc70, 23);
1804 MD5STEP(F3
, a
, b
, c
, d
, in
[13] + 0x289b7ec6, 4);
1805 MD5STEP(F3
, d
, a
, b
, c
, in
[0] + 0xeaa127fa, 11);
1806 MD5STEP(F3
, c
, d
, a
, b
, in
[3] + 0xd4ef3085, 16);
1807 MD5STEP(F3
, b
, c
, d
, a
, in
[6] + 0x04881d05, 23);
1808 MD5STEP(F3
, a
, b
, c
, d
, in
[9] + 0xd9d4d039, 4);
1809 MD5STEP(F3
, d
, a
, b
, c
, in
[12] + 0xe6db99e5, 11);
1810 MD5STEP(F3
, c
, d
, a
, b
, in
[15] + 0x1fa27cf8, 16);
1811 MD5STEP(F3
, b
, c
, d
, a
, in
[2] + 0xc4ac5665, 23);
1813 MD5STEP(F4
, a
, b
, c
, d
, in
[0] + 0xf4292244, 6);
1814 MD5STEP(F4
, d
, a
, b
, c
, in
[7] + 0x432aff97, 10);
1815 MD5STEP(F4
, c
, d
, a
, b
, in
[14] + 0xab9423a7, 15);
1816 MD5STEP(F4
, b
, c
, d
, a
, in
[5] + 0xfc93a039, 21);
1817 MD5STEP(F4
, a
, b
, c
, d
, in
[12] + 0x655b59c3, 6);
1818 MD5STEP(F4
, d
, a
, b
, c
, in
[3] + 0x8f0ccc92, 10);
1819 MD5STEP(F4
, c
, d
, a
, b
, in
[10] + 0xffeff47d, 15);
1820 MD5STEP(F4
, b
, c
, d
, a
, in
[1] + 0x85845dd1, 21);
1821 MD5STEP(F4
, a
, b
, c
, d
, in
[8] + 0x6fa87e4f, 6);
1822 MD5STEP(F4
, d
, a
, b
, c
, in
[15] + 0xfe2ce6e0, 10);
1823 MD5STEP(F4
, c
, d
, a
, b
, in
[6] + 0xa3014314, 15);
1824 MD5STEP(F4
, b
, c
, d
, a
, in
[13] + 0x4e0811a1, 21);
1825 MD5STEP(F4
, a
, b
, c
, d
, in
[4] + 0xf7537e82, 6);
1826 MD5STEP(F4
, d
, a
, b
, c
, in
[11] + 0xbd3af235, 10);
1827 MD5STEP(F4
, c
, d
, a
, b
, in
[2] + 0x2ad7d2bb, 15);
1828 MD5STEP(F4
, b
, c
, d
, a
, in
[9] + 0xeb86d391, 21);