Feature request: Add "save to fd" function #7
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It would avoid some TOCTOU issues in
scrot
(https://github.com/resurrecting-open-source-projects/scrot/issues/215). And it looks like file handling got centralized recently for the savers (c3d5249
) so shouldn't be difficult to add, I think.Right, fine with me, will do.
However, for symmetry with imlib_load_fd() I think it would have to be save to fd like:
void imlib_save_image_fd(int fd, const char *file);
Either
FILE *
orfd
should work fine for scrot's purposes.The function should also communicate error like the
_with_errno_return
functions.The others don't have a documented way to communicate the exact nature of errors, scrot already made the mistake of adding code that incorrectly pokes into imlib's implementation details to try to get errno values.
Following the style of other functions in imlib, the one scrot needs would be declared like this:
At some point I thought I was going in that direction - having functions with and without error returns.
However, that turned out to become rather messy, IMO.
Instead (although not documented too well), the last error from any load (immediate) or save operation can be fetched with imlib_get_error() (as of v1.10.0).
As of the next release also errors from implicit deferred data loads can be fetched.
I intend to keep the file name parameter, again for symmetry with imlib_load_image_fd().
Ideally, the library would only have functions with informative error return values. Programs that don't care about the exact nature of the error can simply check that the function didn't succeed and not do anything about the information contained in the error code.
A filename parameter would make imlib_save_image_fd useless, we're back to TOCTTOU baked into the API. It doesn't make sense to do this either, fds don't even necessarily have filenames. There are pipes, sockets, and so on, but even a fd that is a regular file doesn't need to have a name:
I don't think so. The "filename" in
load_fd
is only used as an extension guess. The same is probably going to be true forsave_fd
. E.gimlib_save_image_fd(fd, ".png");
Feature request: Add "save to FILE *" functionto Feature request: Add "save to fd" functionAdded now.
And yes, the file parameter is only used to determine the output file format if it isn't already set in the image (e.g. using imlib_image_set_format()).
scrot doesn't care so this issue is solved, but does it really have to close the fd?
Wait, I just noticed.
ce0ac1eeff/src/lib/api.c (L1940)
stdout could be the same file as the fd. A library shouldn't produce output like this.
Right, forgot to clean out a bit of debug.
The fd is closed because load_fd does so.
load_fd() does so because at the time it was argued that it was the right thing to do, as various other image loading APIs do so.
But yeah, it still seems somewhat strange to me as well.
This looks about right. So closing the issue.
Also - closing the fd seems dubious to me as well. But better to be consistent, I think. The caller just needs to dup the fd before passing it to imlib2.