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.
27 #include "../fc-arch/fcarch.h"
31 #include <sys/types.h>
32 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
34 # include <sys/mman.h>
39 #define ENDIAN_TEST 0x12345678
40 #define MACHINE_SIGNATURE_SIZE (9 + 5*20 + 1)
41 /* for when we don't have sysconf: */
42 #define FC_HARDCODED_PAGESIZE 8192
49 FcDirCacheOpen (FcConfig
*config
, const FcChar8
*dir
, FcChar8
**cache_path
);
52 FcCacheSkipToArch (int fd
, const char * arch
);
55 FcCacheCopyOld (int fd
, int fd_orig
, off_t start
);
58 FcDirCacheProduce (FcFontSet
*set
, FcCache
* metadata
);
61 FcDirCacheConsume (int fd
, const char * dir
, FcFontSet
*set
, FcConfig
*config
);
64 FcCacheNextOffset(off_t w
);
67 FcCacheMachineSignature (void);
70 FcCacheHaveBank (int bank
);
73 FcCacheAddBankDir (int bank
, const char * dir
);
81 static void MD5Init(struct MD5Context
*ctx
);
82 static void MD5Update(struct MD5Context
*ctx
, unsigned char *buf
, unsigned len
);
83 static void MD5Final(unsigned char digest
[16], struct MD5Context
*ctx
);
84 static void MD5Transform(FcChar32 buf
[4], FcChar32 in
[16]);
86 #define FC_DBG_CACHE_REF 1024
89 FcCacheReadString (int fd
, char *dest
, int len
)
97 size
= read (fd
, dest
, len
-1);
102 slen
= strlen (dest
);
104 lseek (fd
, slen
- size
+ 1, SEEK_CUR
);
105 return slen
< len
? dest
: 0;
112 FcCacheSkipString (int fd
)
118 while ( (size
= read (fd
, buf
, sizeof (buf
)-1)) > 0)
124 lseek (fd
, slen
- size
+ 1, SEEK_CUR
);
131 FcCacheWriteString (int fd
, const char *chars
)
133 if (write (fd
, chars
, strlen(chars
)+1) != strlen(chars
)+1)
139 FcGlobalCacheDirDestroy (FcGlobalCacheDir
*d
)
141 FcStrSetDestroy (d
->subdirs
);
142 FcMemFree (FC_MEM_STRING
, strlen (d
->name
)+1);
144 FcMemFree (FC_MEM_CACHE
, sizeof (FcGlobalCacheDir
));
149 FcGlobalCacheCreate (void)
151 FcGlobalCache
*cache
;
153 cache
= malloc (sizeof (FcGlobalCache
));
156 FcMemAlloc (FC_MEM_CACHE
, sizeof (FcGlobalCache
));
158 cache
->updated
= FcFalse
;
164 FcGlobalCacheDestroy (FcGlobalCache
*cache
)
166 FcGlobalCacheDir
*d
, *next
;
168 for (d
= cache
->dirs
; d
; d
= next
)
171 FcGlobalCacheDirDestroy (d
);
173 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
)
323 for (d
= cache
->dirs
; d
; d
= d
->next
)
325 if (strcmp (d
->name
, dir
) == 0)
327 if (d
->state
== FcGCDirDisabled
)
330 if (d
->state
== FcGCDirFileRead
)
332 lseek (cache
->fd
, d
->offset
, SEEK_SET
);
333 if (!FcDirCacheConsume (cache
->fd
, d
->name
, set
, config
))
336 for (i
= 0; i
< d
->subdirs
->num
; i
++)
337 FcStrSetAdd (dirs
, (FcChar8
*)d
->subdirs
->strs
[i
]);
339 d
->state
= FcGCDirConsumed
;
348 static FcGlobalCacheDir
*
349 FcGlobalCacheDirFind (FcGlobalCache
*cache
, const char *name
)
351 FcGlobalCacheDir
* d
;
356 for (d
= cache
->dirs
; d
; d
= d
->next
)
357 if (strcmp((const char *)d
->name
, (const char *)name
) == 0)
364 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
373 d
= FcGlobalCacheDirFind (cache
, name
);
377 d
= malloc (sizeof (FcGlobalCacheDir
));
380 d
->next
= cache
->dirs
;
383 /* free old resources */
384 FcStrFree ((FcChar8
*)d
->name
);
386 FcStrSetDestroy (d
->subdirs
);
389 cache
->updated
= FcTrue
;
391 d
->name
= (char *)FcStrCopy ((FcChar8
*)name
);
392 d
->ent
= FcDirCacheProduce (set
, &d
->metadata
);
394 d
->subdirs
= FcStrSetCreate();
395 d
->state
= FcGCDirUpdated
;
396 for (i
= 0; i
< dirs
->num
; i
++)
397 FcStrSetAdd (d
->subdirs
, dirs
->strs
[i
]);
402 FcGlobalCacheSave (FcGlobalCache
*cache
,
403 const FcChar8
*cache_file
,
407 FcGlobalCacheDir
*dir
;
409 off_t current_arch_start
= 0, truncate_to
;
410 char * current_arch_machine_name
, * header
;
415 #if defined (HAVE_GETUID) && defined (HAVE_GETEUID)
416 /* Set-UID programs can't safely update the cache */
417 if (getuid () != geteuid ())
421 atomic
= FcAtomicCreate (cache_file
);
425 if (!FcAtomicLock (atomic
))
427 fd
= open ((char *) FcAtomicNewFile(atomic
), O_RDWR
| O_CREAT
| O_BINARY
,
431 FcCacheWriteString (fd
, FC_GLOBAL_MAGIC_COOKIE
);
433 fd_orig
= open ((char *) FcAtomicOrigFile(atomic
), O_RDONLY
| O_BINARY
);
435 current_arch_machine_name
= FcCacheMachineSignature ();
437 current_arch_start
= 0;
439 current_arch_start
= FcCacheSkipToArch (fd_orig
,
440 current_arch_machine_name
);
442 if (current_arch_start
< 0)
444 off_t i
= lseek(fd_orig
, 0, SEEK_END
);
445 if (i
< strlen (FC_GLOBAL_MAGIC_COOKIE
)+1)
446 i
= strlen (FC_GLOBAL_MAGIC_COOKIE
)+1;
447 current_arch_start
= FcCacheNextOffset (i
);
450 if (!FcCacheCopyOld(fd
, fd_orig
, current_arch_start
))
453 current_arch_start
= lseek(fd
, 0, SEEK_CUR
);
454 #if defined (HAVE_FTRUNCATE)
455 if (ftruncate (fd
, current_arch_start
) == -1)
458 #if defined (HAVE_CHSIZE)
459 if (chsize (fd
, current_arch_start
) == -1)
466 header
= malloc (10 + strlen (current_arch_machine_name
));
470 truncate_to
= current_arch_start
+ strlen(current_arch_machine_name
) + 11;
471 for (dir
= cache
->dirs
; dir
; dir
= dir
->next
)
475 if (dir
->state
== FcGCDirDisabled
)
477 truncate_to
+= strlen(dir
->name
) + 1;
478 truncate_to
+= sizeof (FcCache
);
479 truncate_to
= FcCacheNextOffset (truncate_to
);
480 truncate_to
+= dir
->metadata
.count
;
482 for (i
= 0; i
< dir
->subdirs
->size
; i
++)
483 truncate_to
+= strlen((char *)dir
->subdirs
->strs
[i
]) + 1;
486 truncate_to
-= current_arch_start
;
488 sprintf (header
, "%8x ", (int)truncate_to
);
489 strcat (header
, current_arch_machine_name
);
490 if (!FcCacheWriteString (fd
, header
))
495 for (dir
= cache
->dirs
; dir
; dir
= dir
->next
)
501 if (!dir
->name
|| dir
->state
== FcGCDirDisabled
)
507 if (dir
->metadata
.count
&& !dir
->ent
)
509 if (dir
->state
== FcGCDirUpdated
|| fd_orig
< 0)
511 fprintf(stderr
, "Invalid metadata entry for %s, skipping...\n", d
);
514 /* copy the old content */
515 dir
->ent
= malloc (dir
->metadata
.count
);
518 perror("malloc error");
521 off
= FcCacheNextOffset (dir
->offset
+ sizeof(FcCache
));
522 if (lseek (fd_orig
, off
, SEEK_SET
) != off
)
528 if (read (fd_orig
, dir
->ent
, dir
->metadata
.count
)
529 != dir
->metadata
.count
)
537 FcCacheWriteString (fd
, d
);
539 for (i
= 0; i
< dir
->subdirs
->size
; i
++)
540 FcCacheWriteString (fd
, (char *)dir
->subdirs
->strs
[i
]);
541 FcCacheWriteString (fd
, "");
543 if (write (fd
, &dir
->metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
545 perror ("write metadata");
549 off
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
550 if (lseek (fd
, off
, SEEK_SET
) != off
)
556 if (dir
->metadata
.count
)
558 if (write (fd
, dir
->ent
, dir
->metadata
.count
) != dir
->metadata
.count
)
560 perror ("write dirent");
567 FcCacheWriteString (fd
, "");
569 if (close (fd
) == -1)
575 if (!FcAtomicReplaceOrig (atomic
))
578 FcAtomicUnlock (atomic
);
579 FcAtomicDestroy (atomic
);
581 cache
->updated
= FcFalse
;
592 FcAtomicDeleteNew (atomic
);
594 FcAtomicUnlock (atomic
);
596 FcAtomicDestroy (atomic
);
601 * Find the next presumably-mmapable offset after the supplied file
605 FcCacheNextOffset(off_t w
)
607 static long pagesize
= -1;
613 #if defined (HAVE_SYSCONF)
614 pagesize
= sysconf(_SC_PAGESIZE
);
616 pagesize
= FC_HARDCODED_PAGESIZE
;
618 if (w
% pagesize
== 0)
621 return ((w
/ pagesize
)+1)*pagesize
;
624 /* return the address of the segment for the provided arch,
625 * or -1 if arch not found */
627 FcCacheSkipToArch (int fd
, const char * arch
)
629 char candidate_arch_machine_name_count
[MACHINE_SIGNATURE_SIZE
+ 9];
630 char * candidate_arch
;
631 off_t current_arch_start
= 0;
633 lseek (fd
, 0, SEEK_SET
);
634 FcCacheSkipString (fd
);
635 current_arch_start
= lseek (fd
, 0, SEEK_CUR
);
637 /* skip arches that are not the current arch */
642 if (lseek (fd
, current_arch_start
, SEEK_SET
) != current_arch_start
)
645 if (FcCacheReadString (fd
, candidate_arch_machine_name_count
,
646 sizeof (candidate_arch_machine_name_count
)) == 0)
648 if (!strlen(candidate_arch_machine_name_count
))
650 bs
= strtol(candidate_arch_machine_name_count
, &candidate_arch
, 16);
652 /* count = 0 should probably be distinguished from the !bs condition */
653 if (!bs
|| bs
< strlen (candidate_arch_machine_name_count
))
656 candidate_arch
++; /* skip leading space */
658 if (strcmp (candidate_arch
, arch
)==0)
659 return current_arch_start
;
660 current_arch_start
+= bs
;
661 current_arch_start
= FcCacheNextOffset (current_arch_start
);
665 /* Cuts out the segment at the file pointer (moves everything else
666 * down to cover it), and leaves the file pointer at the end of the
669 FcCacheCopyOld (int fd
, int fd_orig
, off_t start
)
671 char * buf
= malloc (8192);
672 char candidate_arch_machine_name
[MACHINE_SIGNATURE_SIZE
+ 9];
674 int c
, bytes_skipped
;
681 lseek (fd
, 0, SEEK_SET
); lseek (fd_orig
, 0, SEEK_SET
);
682 FcCacheSkipString (fd
); FcCacheSkipString (fd_orig
);
689 if ((c
= read (fd_orig
, buf
, b
)) <= 0)
691 if (write (fd
, buf
, c
) < 0)
698 lseek (fd
, start
, SEEK_SET
);
699 if (FcCacheReadString (fd
, candidate_arch_machine_name
,
700 sizeof (candidate_arch_machine_name
)) == 0)
702 if (!strlen(candidate_arch_machine_name
))
705 bs
= strtol(candidate_arch_machine_name
, 0, 16);
712 lseek (fd
, start
+bs
+bytes_skipped
, SEEK_SET
);
713 if ((c
= read (fd
, buf
, 8192)) <= 0)
715 lseek (fd
, start
+bytes_skipped
, SEEK_SET
);
716 if (write (fd
, buf
, c
) < 0)
721 lseek (fd
, start
+bytes_skipped
, SEEK_SET
);
732 /* Does not check that the cache has the appropriate arch section. */
734 FcDirCacheValid (const FcChar8
*dir
, FcConfig
*config
)
738 fd
= FcDirCacheOpen (config
, dir
, NULL
);
747 /* Assumes that the cache file in 'dir' exists.
748 * Checks that the cache has the appropriate arch section. */
750 FcDirCacheHasCurrentArch (const FcChar8
*dir
, FcConfig
*config
)
753 off_t current_arch_start
;
754 char *current_arch_machine_name
;
756 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
758 fd
= FcDirCacheOpen (config
, dir
, NULL
);
762 current_arch_machine_name
= FcCacheMachineSignature();
763 current_arch_start
= FcCacheSkipToArch(fd
, current_arch_machine_name
);
765 if (current_arch_start
>= 0)
767 if (lseek (fd
, current_arch_start
, SEEK_SET
) != current_arch_start
)
770 FcCacheSkipString (fd
);
772 while (FcCacheReadString (fd
, subdirName
, sizeof (subdirName
)) && strlen (subdirName
) > 0)
775 if (read(fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
778 if (metadata
.magic
!= FC_CACHE_MAGIC
)
784 if (current_arch_start
< 0)
795 #define CACHEBASE_LEN (1 + 32 + 1 + sizeof (FC_ARCHITECTURE) + sizeof (FC_CACHE_SUFFIX))
797 static const char bin2hex
[] = { '0', '1', '2', '3',
800 'c', 'd', 'e', 'f' };
803 FcDirCacheBasename (const FcChar8
* dir
, FcChar8 cache_base
[CACHEBASE_LEN
])
805 unsigned char hash
[16];
808 struct MD5Context ctx
;
811 MD5Update (&ctx
, (unsigned char *)dir
, strlen ((char *) dir
));
813 MD5Final (hash
, &ctx
);
816 hex_hash
= cache_base
+ 1;
817 for (cnt
= 0; cnt
< 16; ++cnt
)
819 hex_hash
[2*cnt
] = bin2hex
[hash
[cnt
] >> 4];
820 hex_hash
[2*cnt
+1] = bin2hex
[hash
[cnt
] & 0xf];
823 strcat ((char *) cache_base
, "-" FC_ARCHITECTURE FC_CACHE_SUFFIX
);
829 FcDirCacheUnlink (const FcChar8
*dir
, FcConfig
*config
)
832 FcChar8
*cache_hashed
= NULL
;
833 FcChar8 cache_base
[CACHEBASE_LEN
];
836 char dir_buf
[FC_MAX_FILE_LEN
];
838 FcDirCacheBasename (dir
, cache_base
);
840 list
= FcStrListCreate (config
->cacheDirs
);
844 while ((cache_dir
= FcStrListNext (list
)))
846 cache_hashed
= FcStrPlus (cache_dir
, cache_base
);
849 fd
= open((char *) cache_hashed
, O_RDONLY
| O_BINARY
);
850 FcStrFree (cache_hashed
);
853 if (FcCacheReadString (fd
, dir_buf
, sizeof (dir_buf
)) &&
854 strcmp (dir_buf
, (char *) dir
) == 0)
857 if (unlink ((char *) cache_hashed
) < 0)
863 FcStrListDone (list
);
864 /* return FcFalse if something went wrong */
871 FcCacheReadDirs (FcConfig
* config
, FcGlobalCache
* cache
,
872 FcStrList
*list
, FcFontSet
* set
, FcStrSet
*processed_dirs
)
881 * Read in the results from 'list'.
883 while ((dir
= FcStrListNext (list
)))
885 if (!FcConfigAcceptFilename (config
, dir
))
888 /* Skip this directory if already updated
889 * to avoid the looped directories via symlinks
890 * Clearly a dir not in fonts.conf shouldn't be globally cached.
893 if (FcStrSetMember (processed_dirs
, dir
))
895 if (!FcStrSetAdd (processed_dirs
, dir
))
898 subdirs
= FcStrSetCreate ();
901 fprintf (stderr
, "Can't create directory set\n");
906 if (FcDirCacheRead (set
, subdirs
, dir
, config
))
908 /* if an old entry is found in the global cache, disable it */
909 if ((d
= FcGlobalCacheDirFind (cache
, (const char *)dir
)) != NULL
)
911 d
->state
= FcGCDirDisabled
;
912 /* save the updated config later without this entry */
913 cache
->updated
= FcTrue
;
918 if (FcDebug () & FC_DBG_FONTSET
)
919 printf ("cache scan dir %s\n", dir
);
921 FcDirScanConfig (set
, subdirs
, cache
,
922 config
->blanks
, dir
, FcFalse
, config
);
924 sublist
= FcStrListCreate (subdirs
);
925 FcStrSetDestroy (subdirs
);
928 fprintf (stderr
, "Can't create subdir list in \"%s\"\n", dir
);
932 ret
+= FcCacheReadDirs (config
, cache
, sublist
, set
, processed_dirs
);
934 FcStrListDone (list
);
939 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
)
941 FcFontSet
*s
= FcFontSetCreate();
942 FcStrSet
*processed_dirs
;
947 processed_dirs
= FcStrSetCreate();
951 if (FcCacheReadDirs (config
, cache
, FcConfigGetConfigDirs (config
), s
, processed_dirs
))
954 FcStrSetDestroy (processed_dirs
);
958 FcStrSetDestroy (processed_dirs
);
960 FcFontSetDestroy (s
);
964 /* Opens the cache file for 'dir' for reading.
965 * This searches the list of cache dirs for the relevant cache file,
966 * returning the first one found.
969 FcDirCacheOpen (FcConfig
*config
, const FcChar8
*dir
, FcChar8
**cache_path
)
972 FcChar8
*cache_hashed
= NULL
;
973 FcChar8 cache_base
[CACHEBASE_LEN
];
976 char dir_buf
[FC_MAX_FILE_LEN
];
977 struct stat file_stat
, dir_stat
;
979 if (stat ((char *) dir
, &dir_stat
) < 0)
982 FcDirCacheBasename (dir
, cache_base
);
984 list
= FcStrListCreate (config
->cacheDirs
);
988 while ((cache_dir
= FcStrListNext (list
)))
990 cache_hashed
= FcStrPlus (cache_dir
, cache_base
);
993 fd
= open((char *) cache_hashed
, O_RDONLY
| O_BINARY
);
995 if (fstat (fd
, &file_stat
) >= 0 &&
996 dir_stat
.st_mtime
<= file_stat
.st_mtime
)
1003 FcStrFree (cache_hashed
);
1004 cache_hashed
= NULL
;
1006 FcStrListDone (list
);
1011 if (!FcCacheReadString (fd
, dir_buf
, sizeof (dir_buf
)) ||
1012 strcmp (dir_buf
, (char *) dir
) != 0)
1015 FcStrFree (cache_hashed
);
1020 *cache_path
= cache_hashed
;
1022 FcStrFree (cache_hashed
);
1027 /* read serialized state from the cache file */
1029 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
)
1032 char *current_arch_machine_name
;
1033 char candidate_arch_machine_name
[9+MACHINE_SIGNATURE_SIZE
];
1034 off_t current_arch_start
= 0;
1035 char subdirName
[FC_MAX_FILE_LEN
+ 1 + 12 + 1];
1037 fd
= FcDirCacheOpen (config
, dir
, NULL
);
1041 current_arch_machine_name
= FcCacheMachineSignature();
1042 current_arch_start
= FcCacheSkipToArch(fd
,
1043 current_arch_machine_name
);
1044 if (current_arch_start
< 0)
1047 lseek (fd
, current_arch_start
, SEEK_SET
);
1048 if (FcCacheReadString (fd
, candidate_arch_machine_name
,
1049 sizeof (candidate_arch_machine_name
)) == 0)
1052 while (FcCacheReadString (fd
, subdirName
, sizeof (subdirName
)) && strlen (subdirName
) > 0)
1053 FcStrSetAdd (dirs
, (FcChar8
*)subdirName
);
1055 if (!FcDirCacheConsume (fd
, (const char *)dir
, set
, config
))
1068 FcDirCacheConsume (int fd
, const char * dir
, FcFontSet
*set
, FcConfig
*config
)
1071 void * current_dir_block
;
1074 if (read(fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
1076 if (metadata
.magic
!= FC_CACHE_MAGIC
)
1079 if (!metadata
.count
)
1081 pos
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
1082 lseek (fd
, pos
, SEEK_SET
);
1084 FcConfigAddFontDir (config
, (FcChar8
*)dir
);
1088 pos
= FcCacheNextOffset (lseek(fd
, 0, SEEK_CUR
));
1090 /* This is not failsafe (multi-arches can break it),
1091 * but fd has got to have at least as many bytes as
1092 * metadata.count, or something's going to go horribly wrong. */
1093 if (pos
== (off_t
)-1)
1096 endpos
= lseek (fd
, 0, SEEK_END
);
1097 if (endpos
== (off_t
)-1 || endpos
- pos
< metadata
.count
)
1099 if (lseek (fd
, pos
, SEEK_SET
) == -1)
1102 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
1103 current_dir_block
= mmap (0, metadata
.count
,
1104 PROT_READ
, MAP_SHARED
, fd
, pos
);
1105 if (current_dir_block
== MAP_FAILED
)
1107 #elif defined(_WIN32)
1111 hFileMap
= CreateFileMapping((HANDLE
) _get_osfhandle(fd
), NULL
, PAGE_READONLY
, 0, 0, NULL
);
1112 if (hFileMap
== NULL
)
1115 current_dir_block
= MapViewOfFile (hFileMap
, FILE_MAP_READ
, 0, 0, metadata
.count
+ pos
);
1116 if (current_dir_block
== NULL
)
1118 CloseHandle (hFileMap
);
1122 current_dir_block
= (void *)((char *)current_dir_block
+ pos
);
1125 current_dir_block
= malloc (metadata
.count
);
1126 if (!current_dir_block
)
1129 /* could also use CreateMappedViewOfFile under MinGW... */
1130 if (read (fd
, current_dir_block
, metadata
.count
) != metadata
.count
)
1133 lseek (fd
, pos
+metadata
.count
, SEEK_SET
);
1135 FcCacheAddBankDir (metadata
.bank
, dir
);
1137 FcConfigAddFontDir (config
, (FcChar8
*)dir
);
1139 if (!FcFontSetUnserialize (&metadata
, set
, current_dir_block
))
1144 #if !(defined(HAVE_MMAP) || defined(__CYGWIN__))
1145 free (current_dir_block
);
1151 FcDirCacheProduce (FcFontSet
*set
, FcCache
*metadata
)
1153 void * current_dir_block
, * final_dir_block
;
1154 static unsigned int rand_state
= 0;
1155 int bank
, needed_bytes_no_align
;
1157 #if defined (HAVE_RAND_R)
1159 rand_state
= time(0L);
1160 bank
= rand_r(&rand_state
);
1162 while (FcCacheHaveBank(bank
))
1163 bank
= rand_r(&rand_state
);
1172 while (FcCacheHaveBank(bank
))
1176 memset (metadata
, 0, sizeof(FcCache
));
1178 needed_bytes_no_align
= FcFontSetNeededBytes (set
);
1179 metadata
->count
= needed_bytes_no_align
+
1180 FcFontSetNeededBytesAlign ();
1181 metadata
->magic
= FC_CACHE_MAGIC
;
1182 metadata
->bank
= bank
;
1184 if (!needed_bytes_no_align
) /* not a failure, no fonts to write */
1186 /* no, you don't really need to write any bytes at all. */
1187 metadata
->count
= 0;
1191 current_dir_block
= malloc (metadata
->count
);
1192 if (!current_dir_block
)
1194 /* shut up valgrind */
1195 memset (current_dir_block
, 0, metadata
->count
);
1196 final_dir_block
= FcFontSetDistributeBytes (metadata
, current_dir_block
);
1198 if ((void *)((char *)current_dir_block
+metadata
->count
) < final_dir_block
)
1201 if (!FcFontSetSerialize (bank
, set
))
1204 return current_dir_block
;
1207 free (current_dir_block
);
1212 FcMakeDirectory (const FcChar8
*dir
)
1217 if (strlen ((char *) dir
) == 0)
1220 parent
= FcStrDirname (dir
);
1223 if (access ((char *) parent
, W_OK
|X_OK
) == 0)
1224 ret
= mkdir ((char *) dir
, 0777) == 0;
1225 else if (access ((char *) parent
, F_OK
) == -1)
1226 ret
= FcMakeDirectory (parent
) && (mkdir ((char *) dir
, 0777) == 0);
1233 /* write serialized state to the cache file */
1235 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
*dirs
, const FcChar8
*dir
, FcConfig
*config
)
1237 FcChar8 cache_base
[CACHEBASE_LEN
];
1238 FcChar8
*cache_hashed
;
1239 int fd
, fd_orig
, i
, dirs_count
;
1242 off_t current_arch_start
= 0, truncate_to
;
1244 char *current_arch_machine_name
, * header
;
1245 void *current_dir_block
= 0;
1246 FcChar8
*cache_dir
= NULL
;
1250 * Write it to the first directory in the list which is writable
1253 list
= FcStrListCreate (config
->cacheDirs
);
1256 while ((test_dir
= FcStrListNext (list
))) {
1257 if (access ((char *) test_dir
, W_OK
|X_OK
) == 0)
1259 cache_dir
= test_dir
;
1265 * If the directory doesn't exist, try to create it
1267 if (access ((char *) test_dir
, F_OK
) == -1) {
1268 if (FcMakeDirectory (test_dir
))
1270 cache_dir
= test_dir
;
1276 FcStrListDone (list
);
1279 FcDirCacheBasename (dir
, cache_base
);
1280 cache_hashed
= FcStrPlus (cache_dir
, cache_base
);
1284 current_dir_block
= FcDirCacheProduce (set
, &metadata
);
1286 if (metadata
.count
&& !current_dir_block
)
1289 if (FcDebug () & FC_DBG_CACHE
)
1290 printf ("FcDirCacheWriteDir dir \"%s\" file \"%s\"\n",
1293 atomic
= FcAtomicCreate ((FcChar8
*)cache_hashed
);
1297 if (!FcAtomicLock (atomic
))
1300 /* open the original file to save relevant portions */
1301 fd_orig
= open((char *)FcAtomicOrigFile (atomic
), O_RDONLY
| O_BINARY
);
1303 fd
= open((char *)FcAtomicNewFile (atomic
), O_RDWR
| O_CREAT
| O_BINARY
, 0666);
1307 FcCacheWriteString (fd
, (char *) dir
);
1309 current_arch_machine_name
= FcCacheMachineSignature ();
1310 current_arch_start
= 0;
1313 current_arch_start
=
1314 FcCacheSkipToArch(fd_orig
, current_arch_machine_name
);
1316 if (current_arch_start
< 0)
1318 off_t offset
= lseek(fd_orig
, 0, SEEK_END
);
1319 current_arch_start
= FcCacheNextOffset (offset
);
1322 if (fd_orig
!= -1 && !FcCacheCopyOld(fd
, fd_orig
, current_arch_start
))
1328 current_arch_start
= lseek(fd
, 0, SEEK_CUR
);
1329 #if defined (HAVE_FTRUNCATE)
1330 if (ftruncate (fd
, current_arch_start
) == -1)
1333 #if defined (HAVE_CHSIZE)
1334 if (chsize (fd
, current_arch_start
) == -1)
1341 /* allocate space for subdir names in this block */
1343 for (i
= 0; i
< dirs
->size
; i
++)
1344 dirs_count
+= strlen((char *)dirs
->strs
[i
]) + 1;
1347 /* now write the address of the next offset */
1348 truncate_to
= FcCacheNextOffset (FcCacheNextOffset (current_arch_start
+ sizeof (FcCache
) + dirs_count
) + metadata
.count
) - current_arch_start
;
1349 header
= malloc (10 + strlen (current_arch_machine_name
));
1352 sprintf (header
, "%8x ", (int)truncate_to
);
1353 strcat (header
, current_arch_machine_name
);
1354 if (!FcCacheWriteString (fd
, header
))
1357 for (i
= 0; i
< dirs
->size
; i
++)
1358 FcCacheWriteString (fd
, (char *)dirs
->strs
[i
]);
1359 FcCacheWriteString (fd
, "");
1361 if (write (fd
, &metadata
, sizeof(FcCache
)) != sizeof(FcCache
))
1363 perror("write metadata");
1368 off_t off
= FcCacheNextOffset (lseek(fd
, 0, SEEK_END
));
1369 if (lseek (fd
, off
, SEEK_SET
) != off
)
1371 else if (write (fd
, current_dir_block
, metadata
.count
) !=
1373 perror("write current_dir_block");
1374 free (current_dir_block
);
1375 current_dir_block
= 0;
1378 /* this actually serves to pad out the cache file, if needed */
1379 #if defined (HAVE_FTRUNCATE)
1380 if (ftruncate (fd
, current_arch_start
+ truncate_to
) == -1)
1383 #if defined (HAVE_CHSIZE)
1384 if (chsize (fd
, current_arch_start
+ truncate_to
) == -1)
1393 if (!FcAtomicReplaceOrig(atomic
))
1395 FcStrFree ((FcChar8
*)cache_hashed
);
1396 FcAtomicUnlock (atomic
);
1397 FcAtomicDestroy (atomic
);
1405 FcAtomicUnlock (atomic
);
1407 FcAtomicDestroy (atomic
);
1409 FcStrFree ((FcChar8
*)cache_hashed
);
1410 if (current_dir_block
)
1411 free (current_dir_block
);
1416 FcCacheMachineSignature ()
1418 static char buf
[MACHINE_SIGNATURE_SIZE
];
1419 int32_t magic
= ENDIAN_TEST
;
1420 char * m
= (char *)&magic
;
1422 sprintf (buf
, "%2x%2x%2x%2x "
1423 "%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x "
1424 "%4x %4x %4x %4x %4x %4x %4x %4x\n",
1425 m
[0], m
[1], m
[2], m
[3],
1426 (unsigned int)sizeof (char),
1427 (unsigned int)sizeof (char *),
1428 (unsigned int)sizeof (int),
1429 (unsigned int)sizeof (FcPattern
),
1430 (unsigned int)sizeof (FcPatternEltPtr
),
1431 (unsigned int)sizeof (struct _FcPatternElt
*),
1432 (unsigned int)sizeof (FcPatternElt
),
1433 (unsigned int)sizeof (FcObjectPtr
),
1434 (unsigned int)sizeof (FcValueListPtr
),
1435 (unsigned int)sizeof (FcValue
),
1436 (unsigned int)sizeof (FcValueBinding
),
1437 (unsigned int)sizeof (struct _FcValueList
*),
1438 (unsigned int)sizeof (FcCharSet
),
1439 (unsigned int)sizeof (FcCharLeaf
**),
1440 (unsigned int)sizeof (FcChar16
*),
1441 (unsigned int)sizeof (FcChar16
),
1442 (unsigned int)sizeof (FcCharLeaf
),
1443 (unsigned int)sizeof (FcChar32
),
1444 (unsigned int)sizeof (FcCache
),
1445 #if defined (HAVE_SYSCONF)
1446 (unsigned int)sysconf(_SC_PAGESIZE
));
1448 (unsigned int)FC_HARDCODED_PAGESIZE
);
1454 static int banks_ptr
= 0, banks_alloc
= 0;
1455 int * _fcBankId
= 0, * _fcBankIdx
= 0;
1456 static const char ** bankDirs
= 0;
1459 FcCacheHaveBank (int bank
)
1463 if (bank
< FC_BANK_FIRST
)
1466 for (i
= 0; i
< banks_ptr
; i
++)
1467 if (_fcBankId
[i
] == bank
)
1474 FcCacheBankToIndexMTF (int bank
)
1478 for (i
= 0; i
< banks_ptr
; i
++)
1479 if (_fcBankId
[_fcBankIdx
[i
]] == bank
)
1481 int t
= _fcBankIdx
[i
];
1483 for (j
= i
; j
> 0; j
--)
1484 _fcBankIdx
[j
] = _fcBankIdx
[j
-1];
1489 if (banks_ptr
>= banks_alloc
)
1494 b
= realloc (_fcBankId
, (banks_alloc
+ 4) * sizeof(int));
1499 bidx
= realloc (_fcBankIdx
, (banks_alloc
+ 4) * sizeof(int));
1504 bds
= realloc (bankDirs
, (banks_alloc
+ 4) * sizeof (char *));
1513 _fcBankId
[i
] = bank
;
1519 FcCacheAddBankDir (int bank
, const char * dir
)
1521 int bi
= FcCacheBankToIndexMTF (bank
);
1526 bankDirs
[bi
] = (const char *)FcStrCopy ((FcChar8
*)dir
);
1530 FcCacheFindBankDir (int bank
)
1532 int bi
= FcCacheBankToIndex (bank
);
1533 return bankDirs
[bi
];
1537 * This code implements the MD5 message-digest algorithm.
1538 * The algorithm is due to Ron Rivest. This code was
1539 * written by Colin Plumb in 1993, no copyright is claimed.
1540 * This code is in the public domain; do with it what you wish.
1542 * Equivalent code is available from RSA Data Security, Inc.
1543 * This code has been tested against that, and is equivalent,
1544 * except that you don't need to include two pages of legalese
1547 * To compute the message digest of a chunk of bytes, declare an
1548 * MD5Context structure, pass it to MD5Init, call MD5Update as
1549 * needed on buffers full of bytes, and then call MD5Final, which
1550 * will fill a supplied 16-byte array with the digest.
1554 #define byteReverse(buf, len) /* Nothing */
1557 * Note: this code is harmless on little-endian machines.
1559 void byteReverse(unsigned char *buf
, unsigned longs
)
1563 t
= (FcChar32
) ((unsigned) buf
[3] << 8 | buf
[2]) << 16 |
1564 ((unsigned) buf
[1] << 8 | buf
[0]);
1565 *(FcChar32
*) buf
= t
;
1572 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
1573 * initialization constants.
1575 static void MD5Init(struct MD5Context
*ctx
)
1577 ctx
->buf
[0] = 0x67452301;
1578 ctx
->buf
[1] = 0xefcdab89;
1579 ctx
->buf
[2] = 0x98badcfe;
1580 ctx
->buf
[3] = 0x10325476;
1587 * Update context to reflect the concatenation of another buffer full
1590 static void MD5Update(struct MD5Context
*ctx
, unsigned char *buf
, unsigned len
)
1594 /* Update bitcount */
1597 if ((ctx
->bits
[0] = t
+ ((FcChar32
) len
<< 3)) < t
)
1598 ctx
->bits
[1]++; /* Carry from low to high */
1599 ctx
->bits
[1] += len
>> 29;
1601 t
= (t
>> 3) & 0x3f; /* Bytes already in shsInfo->data */
1603 /* Handle any leading odd-sized chunks */
1606 unsigned char *p
= (unsigned char *) ctx
->in
+ t
;
1610 memcpy(p
, buf
, len
);
1614 byteReverse(ctx
->in
, 16);
1615 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1619 /* Process data in 64-byte chunks */
1622 memcpy(ctx
->in
, buf
, 64);
1623 byteReverse(ctx
->in
, 16);
1624 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1629 /* Handle any remaining bytes of data. */
1631 memcpy(ctx
->in
, buf
, len
);
1635 * Final wrapup - pad to 64-byte boundary with the bit pattern
1636 * 1 0* (64-bit count of bits processed, MSB-first)
1638 static void MD5Final(unsigned char digest
[16], struct MD5Context
*ctx
)
1643 /* Compute number of bytes mod 64 */
1644 count
= (ctx
->bits
[0] >> 3) & 0x3F;
1646 /* Set the first char of padding to 0x80. This is safe since there is
1647 always at least one byte free */
1648 p
= ctx
->in
+ count
;
1651 /* Bytes of padding needed to make 64 bytes */
1652 count
= 64 - 1 - count
;
1654 /* Pad out to 56 mod 64 */
1656 /* Two lots of padding: Pad the first block to 64 bytes */
1657 memset(p
, 0, count
);
1658 byteReverse(ctx
->in
, 16);
1659 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1661 /* Now fill the next block with 56 bytes */
1662 memset(ctx
->in
, 0, 56);
1664 /* Pad block to 56 bytes */
1665 memset(p
, 0, count
- 8);
1667 byteReverse(ctx
->in
, 14);
1669 /* Append length in bits and transform */
1670 ((FcChar32
*) ctx
->in
)[14] = ctx
->bits
[0];
1671 ((FcChar32
*) ctx
->in
)[15] = ctx
->bits
[1];
1673 MD5Transform(ctx
->buf
, (FcChar32
*) ctx
->in
);
1674 byteReverse((unsigned char *) ctx
->buf
, 4);
1675 memcpy(digest
, ctx
->buf
, 16);
1676 memset(ctx
, 0, sizeof(ctx
)); /* In case it's sensitive */
1680 /* The four core functions - F1 is optimized somewhat */
1682 /* #define F1(x, y, z) (x & y | ~x & z) */
1683 #define F1(x, y, z) (z ^ (x & (y ^ z)))
1684 #define F2(x, y, z) F1(z, x, y)
1685 #define F3(x, y, z) (x ^ y ^ z)
1686 #define F4(x, y, z) (y ^ (x | ~z))
1688 /* This is the central step in the MD5 algorithm. */
1689 #define MD5STEP(f, w, x, y, z, data, s) \
1690 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
1693 * The core of the MD5 algorithm, this alters an existing MD5 hash to
1694 * reflect the addition of 16 longwords of new data. MD5Update blocks
1695 * the data and converts bytes into longwords for this routine.
1697 static void MD5Transform(FcChar32 buf
[4], FcChar32 in
[16])
1699 register FcChar32 a
, b
, c
, d
;
1706 MD5STEP(F1
, a
, b
, c
, d
, in
[0] + 0xd76aa478, 7);
1707 MD5STEP(F1
, d
, a
, b
, c
, in
[1] + 0xe8c7b756, 12);
1708 MD5STEP(F1
, c
, d
, a
, b
, in
[2] + 0x242070db, 17);
1709 MD5STEP(F1
, b
, c
, d
, a
, in
[3] + 0xc1bdceee, 22);
1710 MD5STEP(F1
, a
, b
, c
, d
, in
[4] + 0xf57c0faf, 7);
1711 MD5STEP(F1
, d
, a
, b
, c
, in
[5] + 0x4787c62a, 12);
1712 MD5STEP(F1
, c
, d
, a
, b
, in
[6] + 0xa8304613, 17);
1713 MD5STEP(F1
, b
, c
, d
, a
, in
[7] + 0xfd469501, 22);
1714 MD5STEP(F1
, a
, b
, c
, d
, in
[8] + 0x698098d8, 7);
1715 MD5STEP(F1
, d
, a
, b
, c
, in
[9] + 0x8b44f7af, 12);
1716 MD5STEP(F1
, c
, d
, a
, b
, in
[10] + 0xffff5bb1, 17);
1717 MD5STEP(F1
, b
, c
, d
, a
, in
[11] + 0x895cd7be, 22);
1718 MD5STEP(F1
, a
, b
, c
, d
, in
[12] + 0x6b901122, 7);
1719 MD5STEP(F1
, d
, a
, b
, c
, in
[13] + 0xfd987193, 12);
1720 MD5STEP(F1
, c
, d
, a
, b
, in
[14] + 0xa679438e, 17);
1721 MD5STEP(F1
, b
, c
, d
, a
, in
[15] + 0x49b40821, 22);
1723 MD5STEP(F2
, a
, b
, c
, d
, in
[1] + 0xf61e2562, 5);
1724 MD5STEP(F2
, d
, a
, b
, c
, in
[6] + 0xc040b340, 9);
1725 MD5STEP(F2
, c
, d
, a
, b
, in
[11] + 0x265e5a51, 14);
1726 MD5STEP(F2
, b
, c
, d
, a
, in
[0] + 0xe9b6c7aa, 20);
1727 MD5STEP(F2
, a
, b
, c
, d
, in
[5] + 0xd62f105d, 5);
1728 MD5STEP(F2
, d
, a
, b
, c
, in
[10] + 0x02441453, 9);
1729 MD5STEP(F2
, c
, d
, a
, b
, in
[15] + 0xd8a1e681, 14);
1730 MD5STEP(F2
, b
, c
, d
, a
, in
[4] + 0xe7d3fbc8, 20);
1731 MD5STEP(F2
, a
, b
, c
, d
, in
[9] + 0x21e1cde6, 5);
1732 MD5STEP(F2
, d
, a
, b
, c
, in
[14] + 0xc33707d6, 9);
1733 MD5STEP(F2
, c
, d
, a
, b
, in
[3] + 0xf4d50d87, 14);
1734 MD5STEP(F2
, b
, c
, d
, a
, in
[8] + 0x455a14ed, 20);
1735 MD5STEP(F2
, a
, b
, c
, d
, in
[13] + 0xa9e3e905, 5);
1736 MD5STEP(F2
, d
, a
, b
, c
, in
[2] + 0xfcefa3f8, 9);
1737 MD5STEP(F2
, c
, d
, a
, b
, in
[7] + 0x676f02d9, 14);
1738 MD5STEP(F2
, b
, c
, d
, a
, in
[12] + 0x8d2a4c8a, 20);
1740 MD5STEP(F3
, a
, b
, c
, d
, in
[5] + 0xfffa3942, 4);
1741 MD5STEP(F3
, d
, a
, b
, c
, in
[8] + 0x8771f681, 11);
1742 MD5STEP(F3
, c
, d
, a
, b
, in
[11] + 0x6d9d6122, 16);
1743 MD5STEP(F3
, b
, c
, d
, a
, in
[14] + 0xfde5380c, 23);
1744 MD5STEP(F3
, a
, b
, c
, d
, in
[1] + 0xa4beea44, 4);
1745 MD5STEP(F3
, d
, a
, b
, c
, in
[4] + 0x4bdecfa9, 11);
1746 MD5STEP(F3
, c
, d
, a
, b
, in
[7] + 0xf6bb4b60, 16);
1747 MD5STEP(F3
, b
, c
, d
, a
, in
[10] + 0xbebfbc70, 23);
1748 MD5STEP(F3
, a
, b
, c
, d
, in
[13] + 0x289b7ec6, 4);
1749 MD5STEP(F3
, d
, a
, b
, c
, in
[0] + 0xeaa127fa, 11);
1750 MD5STEP(F3
, c
, d
, a
, b
, in
[3] + 0xd4ef3085, 16);
1751 MD5STEP(F3
, b
, c
, d
, a
, in
[6] + 0x04881d05, 23);
1752 MD5STEP(F3
, a
, b
, c
, d
, in
[9] + 0xd9d4d039, 4);
1753 MD5STEP(F3
, d
, a
, b
, c
, in
[12] + 0xe6db99e5, 11);
1754 MD5STEP(F3
, c
, d
, a
, b
, in
[15] + 0x1fa27cf8, 16);
1755 MD5STEP(F3
, b
, c
, d
, a
, in
[2] + 0xc4ac5665, 23);
1757 MD5STEP(F4
, a
, b
, c
, d
, in
[0] + 0xf4292244, 6);
1758 MD5STEP(F4
, d
, a
, b
, c
, in
[7] + 0x432aff97, 10);
1759 MD5STEP(F4
, c
, d
, a
, b
, in
[14] + 0xab9423a7, 15);
1760 MD5STEP(F4
, b
, c
, d
, a
, in
[5] + 0xfc93a039, 21);
1761 MD5STEP(F4
, a
, b
, c
, d
, in
[12] + 0x655b59c3, 6);
1762 MD5STEP(F4
, d
, a
, b
, c
, in
[3] + 0x8f0ccc92, 10);
1763 MD5STEP(F4
, c
, d
, a
, b
, in
[10] + 0xffeff47d, 15);
1764 MD5STEP(F4
, b
, c
, d
, a
, in
[1] + 0x85845dd1, 21);
1765 MD5STEP(F4
, a
, b
, c
, d
, in
[8] + 0x6fa87e4f, 6);
1766 MD5STEP(F4
, d
, a
, b
, c
, in
[15] + 0xfe2ce6e0, 10);
1767 MD5STEP(F4
, c
, d
, a
, b
, in
[6] + 0xa3014314, 15);
1768 MD5STEP(F4
, b
, c
, d
, a
, in
[13] + 0x4e0811a1, 21);
1769 MD5STEP(F4
, a
, b
, c
, d
, in
[4] + 0xf7537e82, 6);
1770 MD5STEP(F4
, d
, a
, b
, c
, in
[11] + 0xbd3af235, 10);
1771 MD5STEP(F4
, c
, d
, a
, b
, in
[2] + 0x2ad7d2bb, 15);
1772 MD5STEP(F4
, b
, c
, d
, a
, in
[9] + 0xeb86d391, 21);