Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temporary file creation on Windows. #2683

Merged
merged 1 commit into from Apr 12, 2016
Merged

Conversation

jtanx
Copy link
Contributor

@jtanx jtanx commented Apr 7, 2016

Sigh... there is no mkstemp on Windows. The one that exists
in GLib can't be used because the file handle it returns
belongs to a different CRT instance, for some reason or
another.

Plus, you cannot unlink a file that is in use on Windows.

So roll our own by calling CreateFile directly. The flags
passed to it will ensure that the file created is only
readable by FontForge and that it will be deleted when
the file handle is closed.

This should give the intended behaviour for this function
on Windows.

Fixes #2681. cc @frank-trampe

Sigh... there is no mkstemp on Windows. The one that exists
in GLib can't be used because the file handle it returns
belongs to a different CRT instance, for some reason or
another.

Plus, you cannot unlink a file that is in use on Windows.

So roll our own by calling CreateFile directly. The flags
passed to it will ensure that the file created is only
readable by FontForge and that it will be deleted when
the file handle is closed.

This should give the intended behaviour for this function
on Windows.

Conflicts:
	fontforge/sfd.c
fd = g_mkstemp( template );
printf("MakeTemporaryFile() fd:%d template:%s\n", fd, template );
if ( (ret=fdopen(fd,"rw+"))==NULL ) ret=0;
unlink( template );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (unlink step) would never have worked (even on Linux) because template would not be updated to the actual file name used.

@ghost
Copy link

ghost commented Apr 7, 2016

FWIW, something I did fairly recently in FontAnvil was replace all the temporary-file stuff with a homemade abstraction layer that writes to memory buffers instead. This was a lot of work, but more or less permanently solves the entire category of cross-platform temporary file creation issues.

@JoesCat JoesCat merged commit 6dcc17b into fontforge:master Apr 12, 2016
@JoesCat
Copy link
Contributor

JoesCat commented Apr 12, 2016

Thanks Jeremy!

@jtanx jtanx deleted the tmpfile branch April 13, 2016 00:17
Omnikron13 pushed a commit to Omnikron13/fontforge that referenced this pull request May 31, 2022
Fix temporary file creation on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fontforge crashing when close kerning pairs window on windows
2 participants