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 (const FcChar8
* dir
);
51 FcDirCacheHashName (char * cache_file
, int collisions
);
54 FcCacheSkipToArch (int fd
, const char * arch
);
57 FcCacheCopyOld (int fd
, int fd_orig
, off_t start
);
60 FcDirCacheProduce (FcFontSet
*set
, FcCache
* metadata
);
63 FcDirCacheConsume (int fd
, const char * dir
, FcFontSet
*set
, FcConfig
*config
);
66 FcCacheNextOffset(off_t w
);
69 FcCacheMachineSignature (void);
72 FcCacheHaveBank (int bank
);
75 FcCacheAddBankDir (int bank
, const char * dir
);
83 static void MD5Init(struct MD5Context
*ctx
);
84 static void MD5Update(struct MD5Context
*ctx
, unsigned char *buf
, unsigned len
);
85 static void MD5Final(unsigned char digest
[16], struct MD5Context
*ctx
);
86 static void MD5Transform(FcChar32 buf
[4], FcChar32 in
[16]);
88 #define FC_DBG_CACHE_REF 1024
91 FcCacheReadString (int fd
, char *dest
, int len
)
99 size
= read (fd
, dest
, len
-1);
104 slen
= strlen (dest
);
106 lseek (fd
, slen
- size
+ 1, SEEK_CUR
);
107 return slen
< len
? dest
: 0;
114 FcCacheSkipString (int fd
)
120 while ( (size
= read (fd
, buf
, sizeof (buf
)-1)) > 0)
126 lseek (fd
, slen
- size
+ 1, SEEK_CUR
);
133 FcCacheWriteString (int fd
, const char *chars
)
135 if (write (fd
, chars
, strlen(chars
)+1) != strlen(chars
)+1)
141 FcGlobalCacheDirDestroy (FcGlobalCacheDir
*d
)
143 FcStrSetDestroy (d
->subdirs
);
144 FcMemFree (FC_MEM_STRING
, strlen (d
->name
)+1);
146 FcMemFree (FC_MEM_CACHE
, sizeof (FcGlobalCacheDir
));
151 FcGlobalCacheCreate (void)
153 FcGlobalCache
*cache
;
155 cache
= malloc (sizeof (FcGlobalCache
));
158 FcMemAlloc (FC_MEM_CACHE
, sizeof (FcGlobalCache
));
160 cache
->updated
= FcFalse
;
166 FcGlobalCacheDestroy (FcGlobalCache
*cache
)
168 FcGlobalCacheDir
*d
, *next
;
170 for (d
= cache
->dirs
; d
; d
= next
)
173 FcGlobalCacheDirDestroy (d
);
175 FcMemFree (FC_MEM_CACHE
, sizeof (FcGlobalCache
));
180 FcGlobalCacheLoad (FcGlobalCache
*cache
,
182 const FcChar8
*cache_file
,
185 char name_buf
[FC_MAX_FILE_LEN
];
186 FcGlobalCacheDir
*d
, *next
;
187 FcFileTime config_time
= FcConfigModifiedTime (config
);
188 char * current_arch_machine_name
;
189 char candidate_arch_machine_name
[MACHINE_SIGNATURE_SIZE
+ 9];
190 off_t current_arch_start
;
192 struct stat cache_stat
, dir_stat
;
193 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
195 if (stat ((char *) cache_file
, &cache_stat
) < 0)
198 cache
->fd
= open ((char *) cache_file
, O_RDONLY
| O_BINARY
);
202 cache
->updated
= FcFalse
;
204 if (!FcCacheReadString (cache
->fd
, name_buf
, sizeof (name_buf
)))
205 goto bail_and_destroy
;
206 if (strcmp (name_buf
, FC_GLOBAL_MAGIC_COOKIE
) != 0)
207 goto bail_and_destroy
;
209 current_arch_machine_name
= FcCacheMachineSignature ();
210 current_arch_start
= FcCacheSkipToArch(cache
->fd
,
211 current_arch_machine_name
);
212 if (current_arch_start
< 0)
215 lseek (cache
->fd
, current_arch_start
, SEEK_SET
);
216 if (!FcCacheReadString (cache
->fd
, candidate_arch_machine_name
,
217 sizeof (candidate_arch_machine_name
)))
218 goto bail_and_destroy
;
219 if (strlen(candidate_arch_machine_name
) == 0)
220 goto bail_and_destroy
;
226 if (!FcCacheReadString (cache
->fd
, name_buf
, sizeof (name_buf
)) ||
230 /* Directory must be older than the global cache file; also
231 cache must be newer than the config file. */
232 if (stat ((char *) name_buf
, &dir_stat
) < 0 ||
233 dir_stat
.st_mtime
> cache_stat
.st_mtime
||
234 (config_time
.set
&& cache_stat
.st_mtime
< config_time
.time
))
239 FcStrSetAdd (staleDirs
, (FcChar8
*)name_buf
);
242 while (FcCacheReadString (cache
->fd
, subdirName
,
243 sizeof (subdirName
)) &&
247 if (read (cache
->fd
, &md
, sizeof (FcCache
)) != sizeof(FcCache
))
249 perror ("read metadata");
252 off
= FcCacheNextOffset (lseek(cache
->fd
, 0, SEEK_CUR
)) + md
.count
;
253 if (lseek (cache
->fd
, off
, SEEK_SET
) != off
)
261 d
= malloc (sizeof (FcGlobalCacheDir
));
265 d
->next
= cache
->dirs
;
268 d
->name
= (char *)FcStrCopy ((FcChar8
*)name_buf
);
270 d
->state
= FcGCDirFileRead
;
272 d
->subdirs
= FcStrSetCreate();
275 if (!FcCacheReadString (cache
->fd
, subdirName
,
276 sizeof (subdirName
)) ||
277 !strlen (subdirName
))
279 FcStrSetAdd (d
->subdirs
, (FcChar8
*)subdirName
);
282 d
->offset
= lseek (cache
->fd
, 0, SEEK_CUR
);
283 if (read (cache
->fd
, &d
->metadata
, sizeof (FcCache
)) != sizeof (FcCache
))
285 targ
= FcCacheNextOffset (lseek(cache
->fd
, 0, SEEK_CUR
)) + d
->metadata
.count
;
286 if (lseek (cache
->fd
, targ
, SEEK_SET
) != targ
)
292 for (d
= cache
->dirs
; d
; d
= next
)
307 if (stat ((char *) cache_file
, &cache_stat
) == 0)
308 unlink ((char *)cache_file
);
315 FcGlobalCacheReadDir (FcFontSet
*set
, FcStrSet
*dirs
, FcGlobalCache
* cache
, const char *dir
, FcConfig
*config
)
324 if (!(dir
= (char *)FcConfigNormalizeFontDir (config
, (FcChar8
*)dir
)))
325 return FcFalse
; /* non-existing directory */
327 for (d
= cache
->dirs
; d
; d
= d
->next
)
329 if (strcmp (d
->name
, dir
) == 0)
331 if (d
->state
== FcGCDirDisabled
)
334 if (d
->state
== FcGCDirFileRead
)
336 lseek (cache
->fd
, d
->offset
, SEEK_SET
);
337 if (!FcDirCacheConsume (cache
->fd
, d
->name
, set
, config
))
340 for (i
= 0; i
< d
->subdirs
->num
; i
++)
341 FcStrSetAdd (dirs
, (FcChar8
*)d
->subdirs
->strs
[i
]);
343 d
->state
= FcGCDirConsumed
;
352 static FcGlobalCacheDir
*
353 FcGlobalCacheDirFind (FcGlobalCache
*cache
, const char *name
)
355 FcGlobalCacheDir
* d
;
360 for (d
= cache
->dirs
; d
; d
= d
->next
)
361 if (strcmp((const char *)d
->name
, (const char *)name
) == 0)
368 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
370 const char *orig_name
,
378 name
= (char *)FcConfigNormalizeFontDir (config
, (FcChar8
*)orig_name
);
381 fprintf(stderr
, "Invalid directory name %s\n", orig_name
);
385 d
= FcGlobalCacheDirFind (cache
, name
);
389 d
= malloc (sizeof (FcGlobalCacheDir
));
392 d
->next
= cache
->dirs
;
395 /* free old resources */
396 FcStrFree ((FcChar8
*)d
->name
);
398 FcStrSetDestroy (d
->subdirs
);
401 cache
->updated
= FcTrue
;
403 d
->name
= (char *)FcStrCopy ((FcChar8
*)name
);
404 d
->ent
= FcDirCacheProduce (set
, &d
->metadata
);
406 d
->subdirs
= FcStrSetCreate();
407 d
->state
= FcGCDirUpdated
;
408 for (i
= 0; i
< dirs
->num
; i
++)
409 FcStrSetAdd (d
->subdirs
, dirs
->strs
[i
]);
414 FcGlobalCacheSave (FcGlobalCache
*cache
,
415 const FcChar8
*cache_file
,
419 FcGlobalCacheDir
*dir
;
421 off_t current_arch_start
= 0, truncate_to
;
422 char * current_arch_machine_name
, * header
;
427 #if defined (HAVE_GETUID) && defined (HAVE_GETEUID)
428 /* Set-UID programs can't safely update the cache */
429 if (getuid () != geteuid ())
433 atomic
= FcAtomicCreate (cache_file
);
437 if (!FcAtomicLock (atomic
))
439 fd
= open ((char *) FcAtomicNewFile(atomic
), O_RDWR
| O_CREAT
| O_BINARY
,
443 FcCacheWriteString (fd
, FC_GLOBAL_MAGIC_COOKIE
);
445 fd_orig
= open ((char *) FcAtomicOrigFile(atomic
), O_RDONLY
| O_BINARY
);
447 current_arch_machine_name
= FcCacheMachineSignature ();
449 current_arch_start
= 0;
451 current_arch_start
= FcCacheSkipToArch (fd_orig
,
452 current_arch_machine_name
);
454 if (current_arch_start
< 0)
456 off_t i
= lseek(fd_orig
, 0, SEEK_END
);
457 if (i
< strlen (FC_GLOBAL_MAGIC_COOKIE
)+1)
458 i
= strlen (FC_GLOBAL_MAGIC_COOKIE
)+1;
459 current_arch_start
= FcCacheNextOffset (i
);
462 if (!FcCacheCopyOld(fd
, fd_orig
, current_arch_start
))
465 current_arch_start
= lseek(fd
, 0, SEEK_CUR
);
466 #if defined (HAVE_FTRUNCATE)
467 if (ftruncate (fd
, current_arch_start
) == -1)
470 #if defined (HAVE_CHSIZE)
471 if (chsize (fd
, current_arch_start
) == -1)
478 header
= malloc (10 + strlen (current_arch_machine_name
));
482 truncate_to
= current_arch_start
+ strlen(current_arch_machine_name
) + 11;
483 for (dir
= cache
->dirs
; dir
; dir
= dir
->next
)
487 if (dir
->state
== FcGCDirDisabled
)
489 truncate_to
+= strlen(dir
->name
) + 1;
490 truncate_to
+= sizeof (FcCache
);
491 truncate_to
= FcCacheNextOffset (truncate_to
);
492 truncate_to
+= dir
->metadata
.count
;
494 for (i
= 0; i
< dir
->subdirs
->size
; i
++)
495 truncate_to
+= strlen((char *)dir
->subdirs
->strs
[i
]) + 1;
498 truncate_to
-= current_arch_start
;
500 sprintf (header
, "%8x ", (int)truncate_to
);
501 strcat (header
, current_arch_machine_name
);
502 if (!FcCacheWriteString (fd
, header
))
507 for (dir
= cache
->dirs
; dir
; dir
= dir
->next
)
513 if (!dir
->name
|| dir
->state
== FcGCDirDisabled
)
515 d
= (const char *)FcConfigNormalizeFontDir (config
, (const FcChar8
*)dir
->name
);
519 if (dir
->metadata
.count
&& !dir
->ent
)
521 if (dir
->state
== FcGCDirUpdated
|| fd_orig
< 0)
523 fprintf(stderr
, "Invalid metadata entry for %s, skipping...\n", d
);
526 /* copy the old content */
527 dir
->ent
= malloc (dir
->metadata
.count
);
530 perror("malloc error");
533 off
= FcCacheNextOffset (dir
->offset
+ sizeof(FcCache
));
534 if (lseek (fd_orig
, off
, SEEK_SET
) != off
)
540 if (read (fd_orig
, dir
->ent
, dir
->metadata
.count
)
541 != dir
->metadata
.count
)
549 FcCacheWriteString (fd
, d
);
551 for (i
= 0; i
< dir
->subdirs
->size
; i
++)
552 FcCacheWriteString (fd
, (char *)dir
->subdirs
->strs
[i
]);
553 FcCacheWriteString (fd
, "");
555 if (write (fd
, &dir
->metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
557 perror ("write metadata");
561 off
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
562 if (lseek (fd
, off
, SEEK_SET
) != off
)
568 if (dir
->metadata
.count
)
570 if (write (fd
, dir
->ent
, dir
->metadata
.count
) != dir
->metadata
.count
)
572 perror ("write dirent");
579 FcCacheWriteString (fd
, "");
581 if (close (fd
) == -1)
587 if (!FcAtomicReplaceOrig (atomic
))
590 FcAtomicUnlock (atomic
);
591 FcAtomicDestroy (atomic
);
593 cache
->updated
= FcFalse
;
604 FcAtomicDeleteNew (atomic
);
606 FcAtomicUnlock (atomic
);
608 FcAtomicDestroy (atomic
);
613 * Find the next presumably-mmapable offset after the supplied file
617 FcCacheNextOffset(off_t w
)
619 static long pagesize
= -1;
625 #if defined (HAVE_SYSCONF)
626 pagesize
= sysconf(_SC_PAGESIZE
);
628 pagesize
= FC_HARDCODED_PAGESIZE
;
630 if (w
% pagesize
== 0)
633 return ((w
/ pagesize
)+1)*pagesize
;
636 /* return the address of the segment for the provided arch,
637 * or -1 if arch not found */
639 FcCacheSkipToArch (int fd
, const char * arch
)
641 char candidate_arch_machine_name_count
[MACHINE_SIGNATURE_SIZE
+ 9];
642 char * candidate_arch
;
643 off_t current_arch_start
= 0;
645 lseek (fd
, 0, SEEK_SET
);
646 FcCacheSkipString (fd
);
647 current_arch_start
= lseek (fd
, 0, SEEK_CUR
);
649 /* skip arches that are not the current arch */
654 if (lseek (fd
, current_arch_start
, SEEK_SET
) != current_arch_start
)
657 if (FcCacheReadString (fd
, candidate_arch_machine_name_count
,
658 sizeof (candidate_arch_machine_name_count
)) == 0)
660 if (!strlen(candidate_arch_machine_name_count
))
662 bs
= strtol(candidate_arch_machine_name_count
, &candidate_arch
, 16);
664 /* count = 0 should probably be distinguished from the !bs condition */
665 if (!bs
|| bs
< strlen (candidate_arch_machine_name_count
))
668 candidate_arch
++; /* skip leading space */
670 if (strcmp (candidate_arch
, arch
)==0)
671 return current_arch_start
;
672 current_arch_start
+= bs
;
673 current_arch_start
= FcCacheNextOffset (current_arch_start
);
677 /* Cuts out the segment at the file pointer (moves everything else
678 * down to cover it), and leaves the file pointer at the end of the
681 FcCacheCopyOld (int fd
, int fd_orig
, off_t start
)
683 char * buf
= malloc (8192);
684 char candidate_arch_machine_name
[MACHINE_SIGNATURE_SIZE
+ 9];
686 int c
, bytes_skipped
;
693 lseek (fd
, 0, SEEK_SET
); lseek (fd_orig
, 0, SEEK_SET
);
694 FcCacheSkipString (fd
); FcCacheSkipString (fd_orig
);
701 if ((c
= read (fd_orig
, buf
, b
)) <= 0)
703 if (write (fd
, buf
, c
) < 0)
710 lseek (fd
, start
, SEEK_SET
);
711 if (FcCacheReadString (fd
, candidate_arch_machine_name
,
712 sizeof (candidate_arch_machine_name
)) == 0)
714 if (!strlen(candidate_arch_machine_name
))
717 bs
= strtol(candidate_arch_machine_name
, 0, 16);
724 lseek (fd
, start
+bs
+bytes_skipped
, SEEK_SET
);
725 if ((c
= read (fd
, buf
, 8192)) <= 0)
727 lseek (fd
, start
+bytes_skipped
, SEEK_SET
);
728 if (write (fd
, buf
, c
) < 0)
733 lseek (fd
, start
+bytes_skipped
, SEEK_SET
);
744 /* Does not check that the cache has the appropriate arch section. */
745 /* Also, this can be fooled if the original location has a stale
746 * cache, and the hashed location has an up-to-date cache. Oh well,
747 * sucks to be you in that case! */
749 FcDirCacheValid (const FcChar8
*dir
)
751 struct stat file_stat
, dir_stat
;
754 if (stat ((char *) dir
, &dir_stat
) < 0)
757 fd
= FcDirCacheOpen (dir
);
761 if (fstat (fd
, &file_stat
) < 0)
767 * If the directory has been modified more recently than
768 * the cache file, the cache is not valid
770 if (dir_stat
.st_mtime
> file_stat
.st_mtime
)
780 /* Assumes that the cache file in 'dir' exists.
781 * Checks that the cache has the appropriate arch section. */
783 FcDirCacheHasCurrentArch (const FcChar8
*dir
)
786 off_t current_arch_start
;
787 char *current_arch_machine_name
;
789 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
791 fd
= FcDirCacheOpen (dir
);
795 current_arch_machine_name
= FcCacheMachineSignature();
796 current_arch_start
= FcCacheSkipToArch(fd
, current_arch_machine_name
);
798 if (current_arch_start
>= 0)
800 if (lseek (fd
, current_arch_start
, SEEK_SET
) != current_arch_start
)
803 FcCacheSkipString (fd
);
805 while (FcCacheReadString (fd
, subdirName
, sizeof (subdirName
)) && strlen (subdirName
) > 0)
808 if (read(fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
811 if (metadata
.magic
!= FC_CACHE_MAGIC
)
817 if (current_arch_start
< 0)
829 FcDirCacheUnlink (const FcChar8
*dir
, FcConfig
*config
)
832 char *cache_hashed
= 0;
834 struct stat cache_stat
;
835 char name_buf
[FC_MAX_FILE_LEN
];
837 dir
= FcConfigNormalizeFontDir (config
, dir
);
838 cache_file
= (char *)FcStrPlus (dir
, (FcChar8
*) "/" FC_DIR_CACHE_FILE
);
842 /* First remove normal cache file. */
843 if (stat ((char *) cache_file
, &cache_stat
) == 0)
844 unlink ((char *)cache_file
);
846 /* Next remove any applicable hashed files. */
847 fd
= -1; collisions
= 0;
851 FcStrFree ((FcChar8
*)cache_hashed
);
853 cache_hashed
= FcDirCacheHashName (cache_file
, collisions
++);
859 fd
= open(cache_hashed
, O_RDONLY
| O_BINARY
);
862 FcStrFree ((FcChar8
*)cache_hashed
);
863 FcStrFree ((FcChar8
*)cache_file
);
867 if (!FcCacheReadString (fd
, name_buf
, sizeof (name_buf
)) || !strlen(name_buf
))
869 FcStrFree ((FcChar8
*)cache_hashed
);
872 } while (strcmp (name_buf
, cache_file
) != 0);
876 if (stat ((char *) cache_hashed
, &cache_stat
) == 0 &&
877 unlink ((char *)cache_hashed
) != 0)
879 FcStrFree ((FcChar8
*)cache_hashed
);
883 FcStrFree ((FcChar8
*)cache_file
);
884 FcStrFree ((FcChar8
*)cache_hashed
);
888 FcStrFree ((FcChar8
*)cache_file
);
893 FcCacheReadDirs (FcConfig
* config
, FcGlobalCache
* cache
,
894 FcStrList
*list
, FcFontSet
* set
, FcStrSet
*processed_dirs
)
904 * Read in the results from 'list'.
906 while ((dir
= FcStrListNext (list
)))
908 if (!FcConfigAcceptFilename (config
, dir
))
911 /* Skip this directory if already updated
912 * to avoid the looped directories via symlinks
913 * Clearly a dir not in fonts.conf shouldn't be globally cached.
915 dir
= (FcChar8
*)FcConfigNormalizeFontDir (config
, dir
);
919 if (FcStrSetMember (processed_dirs
, dir
))
921 if (!FcStrSetAdd (processed_dirs
, dir
))
924 subdirs
= FcStrSetCreate ();
927 fprintf (stderr
, "Can't create directory set\n");
932 if (access ((char *) dir
, X_OK
) < 0)
940 fprintf (stderr
, "\"%s\": ", dir
);
944 FcStrSetDestroy (subdirs
);
947 if (stat ((char *) dir
, &statb
) == -1)
949 fprintf (stderr
, "\"%s\": ", dir
);
951 FcStrSetDestroy (subdirs
);
955 if (!S_ISDIR (statb
.st_mode
))
957 fprintf (stderr
, "\"%s\": not a directory, skipping\n", dir
);
958 FcStrSetDestroy (subdirs
);
961 if (FcDirCacheValid (dir
) &&
962 FcDirCacheHasCurrentArch (dir
) &&
963 FcDirCacheRead (set
, subdirs
, dir
, config
))
965 /* if an old entry is found in the global cache, disable it */
966 if ((d
= FcGlobalCacheDirFind (cache
, (const char *)dir
)) != NULL
)
968 d
->state
= FcGCDirDisabled
;
969 /* save the updated config later without this entry */
970 cache
->updated
= FcTrue
;
975 if (FcDebug () & FC_DBG_FONTSET
)
976 printf ("cache scan dir %s\n", dir
);
978 FcDirScanConfig (set
, subdirs
, cache
,
979 config
->blanks
, dir
, FcFalse
, config
);
981 sublist
= FcStrListCreate (subdirs
);
982 FcStrSetDestroy (subdirs
);
985 fprintf (stderr
, "Can't create subdir list in \"%s\"\n", dir
);
989 ret
+= FcCacheReadDirs (config
, cache
, sublist
, set
, processed_dirs
);
991 FcStrListDone (list
);
996 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
)
998 FcFontSet
*s
= FcFontSetCreate();
999 FcStrSet
*processed_dirs
;
1004 processed_dirs
= FcStrSetCreate();
1005 if (!processed_dirs
)
1008 if (FcCacheReadDirs (config
, cache
, FcConfigGetConfigDirs (config
), s
, processed_dirs
))
1011 FcStrSetDestroy (processed_dirs
);
1015 FcStrSetDestroy (processed_dirs
);
1017 FcFontSetDestroy (s
);
1021 static const char bin2hex
[] = { '0', '1', '2', '3',
1024 'c', 'd', 'e', 'f' };
1027 FcDirCacheHashName (char * cache_file
, int collisions
)
1029 unsigned char hash
[16], hex_hash
[33];
1031 unsigned char uscore
= '_';
1034 struct MD5Context ctx
;
1037 MD5Update (&ctx
, (unsigned char *)cache_file
, strlen (cache_file
));
1039 for (i
= 0; i
< collisions
; i
++)
1040 MD5Update (&ctx
, &uscore
, 1);
1042 MD5Final (hash
, &ctx
);
1044 for (cnt
= 0; cnt
< 16; ++cnt
)
1046 hex_hash
[2*cnt
] = bin2hex
[hash
[cnt
] >> 4];
1047 hex_hash
[2*cnt
+1] = bin2hex
[hash
[cnt
] & 0xf];
1051 tmp
= FcStrPlus ((FcChar8
*)hex_hash
, (FcChar8
*)FC_CACHE_SUFFIX
);
1055 cache_hashed
= (char *)FcStrPlus ((FcChar8
*)PKGCACHEDIR
"/", tmp
);
1058 return cache_hashed
;
1061 /* Opens the hashed name for cache_file.
1062 * This would fail in the unlikely event of a collision and subsequent
1063 * removal of the file which originally caused the collision. */
1065 FcDirCacheOpen (const FcChar8
*dir
)
1068 int fd
= -1, collisions
= 0;
1069 char *cache_file
, *cache_hashed
;
1070 char name_buf
[FC_MAX_FILE_LEN
];
1071 struct stat dir_stat
;
1073 if (stat ((char *)dir
, &dir_stat
) == -1)
1076 cache_file
= (char *)FcStrPlus (dir
, (FcChar8
*) "/" FC_DIR_CACHE_FILE
);
1084 FcChar8
*name_buf_dir
;
1089 cache_hashed
= FcDirCacheHashName (cache_file
, collisions
++);
1092 FcStrFree ((FcChar8
*)cache_file
);
1096 fd
= open(cache_hashed
, O_RDONLY
| O_BINARY
);
1097 FcStrFree ((FcChar8
*)cache_hashed
);
1101 if (!FcCacheReadString (fd
, name_buf
, sizeof (name_buf
)) ||
1105 name_buf_dir
= FcStrDirname ((FcChar8
*)name_buf
);
1106 if (stat ((char *)name_buf_dir
, &c
) == -1)
1108 FcStrFree (name_buf_dir
);
1111 FcStrFree (name_buf_dir
);
1112 found
= (c
.st_ino
== dir_stat
.st_ino
) && (c
.st_dev
== dir_stat
.st_dev
);
1115 if (!found
|| fd
< 0)
1119 fd
= open(cache_file
, O_RDONLY
| O_BINARY
);
1122 FcStrFree ((FcChar8
*)cache_file
);
1126 /* read serialized state from the cache file */
1128 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
)
1131 char *current_arch_machine_name
;
1132 char candidate_arch_machine_name
[9+MACHINE_SIGNATURE_SIZE
];
1133 off_t current_arch_start
= 0;
1134 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
1136 fd
= FcDirCacheOpen (dir
);
1140 current_arch_machine_name
= FcCacheMachineSignature();
1141 current_arch_start
= FcCacheSkipToArch(fd
,
1142 current_arch_machine_name
);
1143 if (current_arch_start
< 0)
1146 lseek (fd
, current_arch_start
, SEEK_SET
);
1147 if (FcCacheReadString (fd
, candidate_arch_machine_name
,
1148 sizeof (candidate_arch_machine_name
)) == 0)
1151 while (FcCacheReadString (fd
, subdirName
, sizeof (subdirName
)) && strlen (subdirName
) > 0)
1152 FcStrSetAdd (dirs
, (FcChar8
*)subdirName
);
1154 if (!FcDirCacheConsume (fd
, (const char *)dir
, set
, config
))
1167 FcDirCacheConsume (int fd
, const char * dir
, FcFontSet
*set
, FcConfig
*config
)
1170 void * current_dir_block
;
1173 if (read(fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
1175 if (metadata
.magic
!= FC_CACHE_MAGIC
)
1178 if (!metadata
.count
)
1180 pos
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
1181 lseek (fd
, pos
, SEEK_SET
);
1183 FcConfigAddFontDir (config
, (FcChar8
*)dir
);
1187 pos
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
1189 /* This is not failsafe (multi-arches can break it),
1190 * but fd has got to have at least as many bytes as
1191 * metadata.count, or something's going to go horribly wrong. */
1192 if (pos
== (off_t
)-1)
1195 endpos
= lseek (fd
, 0, SEEK_END
);
1196 if (endpos
== (off_t
)-1 || endpos
- pos
< metadata
.count
)
1198 if (lseek (fd
, pos
, SEEK_SET
) == -1)
1201 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
1202 current_dir_block
= mmap (0, metadata
.count
,
1203 PROT_READ
, MAP_SHARED
, fd
, pos
);
1204 if (current_dir_block
== MAP_FAILED
)
1206 #elif defined(_WIN32)
1210 hFileMap
= CreateFileMapping((HANDLE
) _get_osfhandle(fd
), NULL
, PAGE_READONLY
, 0, 0, NULL
);
1211 if (hFileMap
== NULL
)
1214 current_dir_block
= MapViewOfFile (hFileMap
, FILE_MAP_READ
, 0, 0, metadata
.count
+ pos
);
1215 if (current_dir_block
== NULL
)
1217 CloseHandle (hFileMap
);
1221 current_dir_block
= (void *)((char *)current_dir_block
+ pos
);
1224 current_dir_block
= malloc (metadata
.count
);
1225 if (!current_dir_block
)
1228 /* could also use CreateMappedViewOfFile under MinGW... */
1229 if (read (fd
, current_dir_block
, metadata
.count
) != metadata
.count
)
1232 lseek (fd
, pos
+metadata
.count
, SEEK_SET
);
1234 FcCacheAddBankDir (metadata
.bank
, dir
);
1236 FcConfigAddFontDir (config
, (FcChar8
*)dir
);
1238 if (!FcFontSetUnserialize (&metadata
, set
, current_dir_block
))
1243 #if !(defined(HAVE_MMAP) || defined(__CYGWIN__))
1244 free (current_dir_block
);
1250 FcDirCacheProduce (FcFontSet
*set
, FcCache
*metadata
)
1252 void * current_dir_block
, * final_dir_block
;
1253 static unsigned int rand_state
= 0;
1254 int bank
, needed_bytes_no_align
;
1256 #if defined (HAVE_RAND_R)
1258 rand_state
= time(0L);
1259 bank
= rand_r(&rand_state
);
1261 while (FcCacheHaveBank(bank
))
1262 bank
= rand_r(&rand_state
);
1271 while (FcCacheHaveBank(bank
))
1275 memset (metadata
, 0, sizeof(FcCache
));
1277 needed_bytes_no_align
= FcFontSetNeededBytes (set
);
1278 metadata
->count
= needed_bytes_no_align
+
1279 FcFontSetNeededBytesAlign ();
1280 metadata
->magic
= FC_CACHE_MAGIC
;
1281 metadata
->bank
= bank
;
1283 if (!needed_bytes_no_align
) /* not a failure, no fonts to write */
1285 /* no, you don't really need to write any bytes at all. */
1286 metadata
->count
= 0;
1290 current_dir_block
= malloc (metadata
->count
);
1291 if (!current_dir_block
)
1293 /* shut up valgrind */
1294 memset (current_dir_block
, 0, metadata
->count
);
1295 final_dir_block
= FcFontSetDistributeBytes (metadata
, current_dir_block
);
1297 if ((void *)((char *)current_dir_block
+metadata
->count
) < final_dir_block
)
1300 if (!FcFontSetSerialize (bank
, set
))
1303 return current_dir_block
;
1306 free (current_dir_block
);
1310 /* write serialized state to the cache file */
1312 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
*dirs
, const FcChar8
*dir
)
1316 int fd
, fd_orig
, i
, dirs_count
;
1319 off_t current_arch_start
= 0, truncate_to
;
1320 char name_buf
[FC_MAX_FILE_LEN
];
1323 char *current_arch_machine_name
, * header
;
1324 void *current_dir_block
= 0;
1326 dir
= FcConfigNormalizeFontDir (FcConfigGetCurrent(), dir
);
1330 cache_file
= (char *)FcStrPlus (dir
, (FcChar8
*) "/" FC_DIR_CACHE_FILE
);
1334 /* Ensure that we're not trampling a cache for some other dir. */
1335 /* This is slightly different from FcDirCacheOpen, since it
1336 * needs the filename, not the file descriptor. */
1337 fd
= -1; collisions
= 0;
1340 cache_hashed
= FcDirCacheHashName (cache_file
, collisions
++);
1346 fd
= open(cache_hashed
, O_RDONLY
| O_BINARY
);
1349 if(!FcCacheReadString (fd
, name_buf
, sizeof (name_buf
)) || !strlen(name_buf
))
1352 FcStrFree ((FcChar8
*)cache_hashed
);
1357 if (strcmp (name_buf
, cache_file
) != 0)
1359 FcStrFree ((FcChar8
*)cache_hashed
);
1366 current_dir_block
= FcDirCacheProduce (set
, &metadata
);
1368 if (metadata
.count
&& !current_dir_block
)
1371 if (FcDebug () & FC_DBG_CACHE
)
1372 printf ("FcDirCacheWriteDir cache_file \"%s\"\n", cache_file
);
1374 atomic
= FcAtomicCreate ((FcChar8
*)cache_hashed
);
1378 if (!FcAtomicLock (atomic
))
1380 /* Now try rewriting the original version of the file. */
1381 FcAtomicDestroy (atomic
);
1383 atomic
= FcAtomicCreate ((FcChar8
*)cache_file
);
1384 fd_orig
= open (cache_file
, O_RDONLY
| O_BINARY
);
1386 fd_orig
= open((char *)FcAtomicOrigFile (atomic
), O_RDONLY
| O_BINARY
);
1388 fd
= open((char *)FcAtomicNewFile (atomic
), O_RDWR
| O_CREAT
| O_BINARY
, 0666);
1393 /* In all cases, try opening the real location of the cache file first. */
1394 /* (even if that's not atomic.) */
1395 fd_orig
= open (cache_file
, O_RDONLY
| O_BINARY
);
1397 fd_orig
= open((char *)FcAtomicOrigFile (atomic
), O_RDONLY
| O_BINARY
);
1399 fd
= open((char *)FcAtomicNewFile (atomic
), O_RDWR
| O_CREAT
| O_BINARY
, 0666);
1403 FcCacheWriteString (fd
, cache_file
);
1405 current_arch_machine_name
= FcCacheMachineSignature ();
1406 current_arch_start
= 0;
1409 current_arch_start
=
1410 FcCacheSkipToArch(fd_orig
, current_arch_machine_name
);
1412 if (current_arch_start
< 0)
1414 off_t offset
= lseek(fd_orig
, 0, SEEK_END
);
1415 current_arch_start
= FcCacheNextOffset (offset
);
1418 if (fd_orig
!= -1 && !FcCacheCopyOld(fd
, fd_orig
, current_arch_start
))
1424 current_arch_start
= lseek(fd
, 0, SEEK_CUR
);
1425 #if defined (HAVE_FTRUNCATE)
1426 if (ftruncate (fd
, current_arch_start
) == -1)
1429 #if defined (HAVE_CHSIZE)
1430 if (chsize (fd
, current_arch_start
) == -1)
1437 /* allocate space for subdir names in this block */
1439 for (i
= 0; i
< dirs
->size
; i
++)
1440 dirs_count
+= strlen((char *)dirs
->strs
[i
]) + 1;
1443 /* now write the address of the next offset */
1444 truncate_to
= FcCacheNextOffset (FcCacheNextOffset (current_arch_start
+ sizeof (FcCache
) + dirs_count
) + metadata
.count
) - current_arch_start
;
1445 header
= malloc (10 + strlen (current_arch_machine_name
));
1448 sprintf (header
, "%8x ", (int)truncate_to
);
1449 strcat (header
, current_arch_machine_name
);
1450 if (!FcCacheWriteString (fd
, header
))
1453 for (i
= 0; i
< dirs
->size
; i
++)
1454 FcCacheWriteString (fd
, (char *)dirs
->strs
[i
]);
1455 FcCacheWriteString (fd
, "");
1457 if (write (fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
1459 perror("write metadata");
1464 off_t off
= FcCacheNextOffset (lseek(fd
, 0, SEEK_END
));
1465 if (lseek (fd
, off
, SEEK_SET
) != off
)
1467 else if (write (fd
, current_dir_block
, metadata
.count
) !=
1469 perror("write current_dir_block");
1470 free (current_dir_block
);
1471 current_dir_block
= 0;
1474 /* this actually serves to pad out the cache file, if needed */
1475 #if defined (HAVE_FTRUNCATE)
1476 if (ftruncate (fd
, current_arch_start
+ truncate_to
) == -1)
1479 #if defined (HAVE_CHSIZE)
1480 if (chsize (fd
, current_arch_start
+ truncate_to
) == -1)
1489 if (!FcAtomicReplaceOrig(atomic
))
1491 FcStrFree ((FcChar8
*)cache_hashed
);
1492 FcStrFree ((FcChar8
*)cache_file
);
1493 FcAtomicUnlock (atomic
);
1494 FcAtomicDestroy (atomic
);
1502 FcAtomicUnlock (atomic
);
1504 FcAtomicDestroy (atomic
);
1506 FcStrFree ((FcChar8
*)cache_hashed
);
1508 unlink ((char *)cache_file
);
1509 FcStrFree ((FcChar8
*)cache_file
);
1510 if (current_dir_block
)
1511 free (current_dir_block
);
1517 FcCacheMachineSignature ()
1519 static char buf
[MACHINE_SIGNATURE_SIZE
];
1520 int32_t magic
= ENDIAN_TEST
;
1521 char * m
= (char *)&magic
;
1523 sprintf (buf
, "%2x%2x%2x%2x "
1524 "%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x "
1525 "%4x %4x %4x %4x %4x %4x %4x %4x\n",
1526 m
[0], m
[1], m
[2], m
[3],
1527 (unsigned int)sizeof (char),
1528 (unsigned int)sizeof (char *),
1529 (unsigned int)sizeof (int),
1530 (unsigned int)sizeof (FcPattern
),
1531 (unsigned int)sizeof (FcPatternEltPtr
),
1532 (unsigned int)sizeof (struct _FcPatternElt
*),
1533 (unsigned int)sizeof (FcPatternElt
),
1534 (unsigned int)sizeof (FcObjectPtr
),
1535 (unsigned int)sizeof (FcValueListPtr
),
1536 (unsigned int)sizeof (FcValue
),
1537 (unsigned int)sizeof (FcValueBinding
),
1538 (unsigned int)sizeof (struct _FcValueList
*),
1539 (unsigned int)sizeof (FcCharSet
),
1540 (unsigned int)sizeof (FcCharLeaf
**),
1541 (unsigned int)sizeof (FcChar16
*),
1542 (unsigned int)sizeof (FcChar16
),
1543 (unsigned int)sizeof (FcCharLeaf
),
1544 (unsigned int)sizeof (FcChar32
),
1545 (unsigned int)sizeof (FcCache
),
1546 #if defined (HAVE_SYSCONF)
1547 (unsigned int)sysconf(_SC_PAGESIZE
));
1549 (unsigned int)FC_HARDCODED_PAGESIZE
);
1555 static int banks_ptr
= 0, banks_alloc
= 0;
1556 int * _fcBankId
= 0, * _fcBankIdx
= 0;
1557 static const char ** bankDirs
= 0;
1560 FcCacheHaveBank (int bank
)
1564 if (bank
< FC_BANK_FIRST
)
1567 for (i
= 0; i
< banks_ptr
; i
++)
1568 if (_fcBankId
[i
] == bank
)
1575 FcCacheBankToIndexMTF (int bank
)
1579 for (i
= 0; i
< banks_ptr
; i
++)
1580 if (_fcBankId
[_fcBankIdx
[i
]] == bank
)
1582 int t
= _fcBankIdx
[i
];
1584 for (j
= i
; j
> 0; j
--)
1585 _fcBankIdx
[j
] = _fcBankIdx
[j
-1];
1590 if (banks_ptr
>= banks_alloc
)
1595 b
= realloc (_fcBankId
, (banks_alloc
+ 4) * sizeof(int));
1600 bidx
= realloc (_fcBankIdx
, (banks_alloc
+ 4) * sizeof(int));
1605 bds
= realloc (bankDirs
, (banks_alloc
+ 4) * sizeof (char *));
1614 _fcBankId
[i
] = bank
;
1620 FcCacheAddBankDir (int bank
, const char * dir
)
1622 int bi
= FcCacheBankToIndexMTF (bank
);
1627 bankDirs
[bi
] = (const char *)FcStrCopy ((FcChar8
*)dir
);
1631 FcCacheFindBankDir (int bank
)
1633 int bi
= FcCacheBankToIndex (bank
);
1634 return bankDirs
[bi
];
1638 * This code implements the MD5 message-digest algorithm.
1639 * The algorithm is due to Ron Rivest. This code was
1640 * written by Colin Plumb in 1993, no copyright is claimed.
1641 * This code is in the public domain; do with it what you wish.
1643 * Equivalent code is available from RSA Data Security, Inc.
1644 * This code has been tested against that, and is equivalent,
1645 * except that you don't need to include two pages of legalese
1648 * To compute the message digest of a chunk of bytes, declare an
1649 * MD5Context structure, pass it to MD5Init, call MD5Update as
1650 * needed on buffers full of bytes, and then call MD5Final, which
1651 * will fill a supplied 16-byte array with the digest.
1655 #define byteReverse(buf, len) /* Nothing */
1658 * Note: this code is harmless on little-endian machines.
1660 void byteReverse(unsigned char *buf
, unsigned longs
)
1664 t
= (FcChar32
) ((unsigned) buf
[3] << 8 | buf
[2]) << 16 |
1665 ((unsigned) buf
[1] << 8 | buf
[0]);
1666 *(FcChar32
*) buf
= t
;
1673 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
1674 * initialization constants.
1676 static void MD5Init(struct MD5Context
*ctx
)
1678 ctx
->buf
[0] = 0x67452301;
1679 ctx
->buf
[1] = 0xefcdab89;
1680 ctx
->buf
[2] = 0x98badcfe;
1681 ctx
->buf
[3] = 0x10325476;
1688 * Update context to reflect the concatenation of another buffer full
1691 static void MD5Update(struct MD5Context
*ctx
, unsigned char *buf
, unsigned len
)
1695 /* Update bitcount */
1698 if ((ctx
->bits
[0] = t
+ ((FcChar32
) len
<< 3)) < t
)
1699 ctx
->bits
[1]++; /* Carry from low to high */
1700 ctx
->bits
[1] += len
>> 29;
1702 t
= (t
>> 3) & 0x3f; /* Bytes already in shsInfo->data */
1704 /* Handle any leading odd-sized chunks */
1707 unsigned char *p
= (unsigned char *) ctx
->in
+ t
;
1711 memcpy(p
, buf
, len
);
1715 byteReverse(ctx
->in
, 16);
1716 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1720 /* Process data in 64-byte chunks */
1723 memcpy(ctx
->in
, buf
, 64);
1724 byteReverse(ctx
->in
, 16);
1725 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1730 /* Handle any remaining bytes of data. */
1732 memcpy(ctx
->in
, buf
, len
);
1736 * Final wrapup - pad to 64-byte boundary with the bit pattern
1737 * 1 0* (64-bit count of bits processed, MSB-first)
1739 static void MD5Final(unsigned char digest
[16], struct MD5Context
*ctx
)
1744 /* Compute number of bytes mod 64 */
1745 count
= (ctx
->bits
[0] >> 3) & 0x3F;
1747 /* Set the first char of padding to 0x80. This is safe since there is
1748 always at least one byte free */
1749 p
= ctx
->in
+ count
;
1752 /* Bytes of padding needed to make 64 bytes */
1753 count
= 64 - 1 - count
;
1755 /* Pad out to 56 mod 64 */
1757 /* Two lots of padding: Pad the first block to 64 bytes */
1758 memset(p
, 0, count
);
1759 byteReverse(ctx
->in
, 16);
1760 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1762 /* Now fill the next block with 56 bytes */
1763 memset(ctx
->in
, 0, 56);
1765 /* Pad block to 56 bytes */
1766 memset(p
, 0, count
- 8);
1768 byteReverse(ctx
->in
, 14);
1770 /* Append length in bits and transform */
1771 ((FcChar32
*) ctx
->in
)[14] = ctx
->bits
[0];
1772 ((FcChar32
*) ctx
->in
)[15] = ctx
->bits
[1];
1774 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1775 byteReverse((unsigned char *) ctx
->buf
, 4);
1776 memcpy(digest
, ctx
->buf
, 16);
1777 memset(ctx
, 0, sizeof(ctx
)); /* In case it's sensitive */
1781 /* The four core functions - F1 is optimized somewhat */
1783 /* #define F1(x, y, z) (x & y | ~x & z) */
1784 #define F1(x, y, z) (z ^ (x & (y ^ z)))
1785 #define F2(x, y, z) F1(z, x, y)
1786 #define F3(x, y, z) (x ^ y ^ z)
1787 #define F4(x, y, z) (y ^ (x | ~z))
1789 /* This is the central step in the MD5 algorithm. */
1790 #define MD5STEP(f, w, x, y, z, data, s) \
1791 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
1794 * The core of the MD5 algorithm, this alters an existing MD5 hash to
1795 * reflect the addition of 16 longwords of new data. MD5Update blocks
1796 * the data and converts bytes into longwords for this routine.
1798 static void MD5Transform(FcChar32 buf
[4], FcChar32 in
[16])
1800 register FcChar32 a
, b
, c
, d
;
1807 MD5STEP(F1
, a
, b
, c
, d
, in
[0] + 0xd76aa478, 7);
1808 MD5STEP(F1
, d
, a
, b
, c
, in
[1] + 0xe8c7b756, 12);
1809 MD5STEP(F1
, c
, d
, a
, b
, in
[2] + 0x242070db, 17);
1810 MD5STEP(F1
, b
, c
, d
, a
, in
[3] + 0xc1bdceee, 22);
1811 MD5STEP(F1
, a
, b
, c
, d
, in
[4] + 0xf57c0faf, 7);
1812 MD5STEP(F1
, d
, a
, b
, c
, in
[5] + 0x4787c62a, 12);
1813 MD5STEP(F1
, c
, d
, a
, b
, in
[6] + 0xa8304613, 17);
1814 MD5STEP(F1
, b
, c
, d
, a
, in
[7] + 0xfd469501, 22);
1815 MD5STEP(F1
, a
, b
, c
, d
, in
[8] + 0x698098d8, 7);
1816 MD5STEP(F1
, d
, a
, b
, c
, in
[9] + 0x8b44f7af, 12);
1817 MD5STEP(F1
, c
, d
, a
, b
, in
[10] + 0xffff5bb1, 17);
1818 MD5STEP(F1
, b
, c
, d
, a
, in
[11] + 0x895cd7be, 22);
1819 MD5STEP(F1
, a
, b
, c
, d
, in
[12] + 0x6b901122, 7);
1820 MD5STEP(F1
, d
, a
, b
, c
, in
[13] + 0xfd987193, 12);
1821 MD5STEP(F1
, c
, d
, a
, b
, in
[14] + 0xa679438e, 17);
1822 MD5STEP(F1
, b
, c
, d
, a
, in
[15] + 0x49b40821, 22);
1824 MD5STEP(F2
, a
, b
, c
, d
, in
[1] + 0xf61e2562, 5);
1825 MD5STEP(F2
, d
, a
, b
, c
, in
[6] + 0xc040b340, 9);
1826 MD5STEP(F2
, c
, d
, a
, b
, in
[11] + 0x265e5a51, 14);
1827 MD5STEP(F2
, b
, c
, d
, a
, in
[0] + 0xe9b6c7aa, 20);
1828 MD5STEP(F2
, a
, b
, c
, d
, in
[5] + 0xd62f105d, 5);
1829 MD5STEP(F2
, d
, a
, b
, c
, in
[10] + 0x02441453, 9);
1830 MD5STEP(F2
, c
, d
, a
, b
, in
[15] + 0xd8a1e681, 14);
1831 MD5STEP(F2
, b
, c
, d
, a
, in
[4] + 0xe7d3fbc8, 20);
1832 MD5STEP(F2
, a
, b
, c
, d
, in
[9] + 0x21e1cde6, 5);
1833 MD5STEP(F2
, d
, a
, b
, c
, in
[14] + 0xc33707d6, 9);
1834 MD5STEP(F2
, c
, d
, a
, b
, in
[3] + 0xf4d50d87, 14);
1835 MD5STEP(F2
, b
, c
, d
, a
, in
[8] + 0x455a14ed, 20);
1836 MD5STEP(F2
, a
, b
, c
, d
, in
[13] + 0xa9e3e905, 5);
1837 MD5STEP(F2
, d
, a
, b
, c
, in
[2] + 0xfcefa3f8, 9);
1838 MD5STEP(F2
, c
, d
, a
, b
, in
[7] + 0x676f02d9, 14);
1839 MD5STEP(F2
, b
, c
, d
, a
, in
[12] + 0x8d2a4c8a, 20);
1841 MD5STEP(F3
, a
, b
, c
, d
, in
[5] + 0xfffa3942, 4);
1842 MD5STEP(F3
, d
, a
, b
, c
, in
[8] + 0x8771f681, 11);
1843 MD5STEP(F3
, c
, d
, a
, b
, in
[11] + 0x6d9d6122, 16);
1844 MD5STEP(F3
, b
, c
, d
, a
, in
[14] + 0xfde5380c, 23);
1845 MD5STEP(F3
, a
, b
, c
, d
, in
[1] + 0xa4beea44, 4);
1846 MD5STEP(F3
, d
, a
, b
, c
, in
[4] + 0x4bdecfa9, 11);
1847 MD5STEP(F3
, c
, d
, a
, b
, in
[7] + 0xf6bb4b60, 16);
1848 MD5STEP(F3
, b
, c
, d
, a
, in
[10] + 0xbebfbc70, 23);
1849 MD5STEP(F3
, a
, b
, c
, d
, in
[13] + 0x289b7ec6, 4);
1850 MD5STEP(F3
, d
, a
, b
, c
, in
[0] + 0xeaa127fa, 11);
1851 MD5STEP(F3
, c
, d
, a
, b
, in
[3] + 0xd4ef3085, 16);
1852 MD5STEP(F3
, b
, c
, d
, a
, in
[6] + 0x04881d05, 23);
1853 MD5STEP(F3
, a
, b
, c
, d
, in
[9] + 0xd9d4d039, 4);
1854 MD5STEP(F3
, d
, a
, b
, c
, in
[12] + 0xe6db99e5, 11);
1855 MD5STEP(F3
, c
, d
, a
, b
, in
[15] + 0x1fa27cf8, 16);
1856 MD5STEP(F3
, b
, c
, d
, a
, in
[2] + 0xc4ac5665, 23);
1858 MD5STEP(F4
, a
, b
, c
, d
, in
[0] + 0xf4292244, 6);
1859 MD5STEP(F4
, d
, a
, b
, c
, in
[7] + 0x432aff97, 10);
1860 MD5STEP(F4
, c
, d
, a
, b
, in
[14] + 0xab9423a7, 15);
1861 MD5STEP(F4
, b
, c
, d
, a
, in
[5] + 0xfc93a039, 21);
1862 MD5STEP(F4
, a
, b
, c
, d
, in
[12] + 0x655b59c3, 6);
1863 MD5STEP(F4
, d
, a
, b
, c
, in
[3] + 0x8f0ccc92, 10);
1864 MD5STEP(F4
, c
, d
, a
, b
, in
[10] + 0xffeff47d, 15);
1865 MD5STEP(F4
, b
, c
, d
, a
, in
[1] + 0x85845dd1, 21);
1866 MD5STEP(F4
, a
, b
, c
, d
, in
[8] + 0x6fa87e4f, 6);
1867 MD5STEP(F4
, d
, a
, b
, c
, in
[15] + 0xfe2ce6e0, 10);
1868 MD5STEP(F4
, c
, d
, a
, b
, in
[6] + 0xa3014314, 15);
1869 MD5STEP(F4
, b
, c
, d
, a
, in
[13] + 0x4e0811a1, 21);
1870 MD5STEP(F4
, a
, b
, c
, d
, in
[4] + 0xf7537e82, 6);
1871 MD5STEP(F4
, d
, a
, b
, c
, in
[11] + 0xbd3af235, 10);
1872 MD5STEP(F4
, c
, d
, a
, b
, in
[2] + 0x2ad7d2bb, 15);
1873 MD5STEP(F4
, b
, c
, d
, a
, in
[9] + 0xeb86d391, 21);