Bug 8526

Summary: Workaround for stat() brokenness in Microsoft's C library
Product: fontconfig Reporter: Tor Lillqvist <tml>
Component: libraryAssignee: Keith Packard <keithp>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: high    
Version: 2.3   
Hardware: x86 (IA32)   
OS: Windows (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Suggested patch
Suggested patch, for 2.4.2

Description Tor Lillqvist 2006-10-06 05:40:58 UTC
The below patch should fix a couple of longstanding problems with
fontconfig on Windows that manifest themselves especially in GIMP. The
root cause to the problems is in Microsoft's incredibly stupid stat()
implementation. Basically, stat() returns wrong timestamp fields for
files on NTFS filesystems on machines that use automatic DST
switching.

See for instance http://bugzilla.gnome.org/show_bug.cgi?id=154968 and
http://www.codeproject.com/datetime/dstbugs.asp

The patch is against 2.3.2, I haven't looked at the current code.
Comment 1 Tor Lillqvist 2006-10-06 05:41:24 UTC
Created attachment 7273 [details] [review]
Suggested patch
Comment 2 Keith Packard 2006-10-06 10:35:31 UTC
If you can move this forward to 2.4.1, I can ship it as a part of 2.4.2 which I
need to do in the next few days.
Comment 3 Keith Packard 2006-12-02 13:25:18 UTC
This patch is missing the fstat function which is now used. If you can update
the patch for 2.4, I can commit it. Otherwise, I will not be able to.
Comment 4 Tor Lillqvist 2007-03-01 15:05:36 UTC
Created attachment 8926 [details] [review]
Suggested patch, for 2.4.2

Here is roughly the same patch, for 2.4.2. As fccache.c now looks at more fields in the stat struct I fill in them all. I noticed that fstat() is used only on a fd just after opening it, so on Win32 I just call my stat() replacement before opening instead... Implementing a good replacement for fstat() would be harder because the code in fccache.c wants to compare inode numbers. There are no (readily accessible) inode numbers on Win32, so I fake it with the hash of the full file name, in the case as it is on disk. And fstat() doesn't know the full file name, so it would be rather hard to come up with a inode number to identify the file.

The patch also adds similar handling for the cache directory as for the fonts directory: If a cachedir element in fonts.conf contains the magic string "WINDOWSTEMPDIR_FONTCONFIG_CACHE" it is replaced at runtime with a path under the machine's (or user's) temp folder as returned by GetTempPath(). I don't want to hardcode any pathnames in a fonts.conf intended to be distributed to end-users, most of which who wouldn't know how to edit it anyway. And requiring an installer to edit it gets complicated.
Comment 5 Keith Packard 2007-11-13 16:42:27 UTC
This has been applied in commit 8a3dc4880c1182ea446cdbc0885e956c6517cf83

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.