posix_spawn() is designed especially for this purpose, and thus it's
much more lightweight and efficient than manually fork/dup/exec-ing.
on my system, it improves the performance of spawn() by about 10x. given
that we make frequent calls to potentially multiple scripts, the
increased efficiency will add up overtime.
using posix_spawn() also simplifies the logic quite a bit, despite the
very verbose function names. however it does make cleanup a bit more
complicated.
this patch uses the linux kernel style cleanup strategy [0] (which I'm
personally not a huge fan of, but it fits this situation quite nicely)
with a "stack-like" unwinding via `goto`-s.
additionally simplify the spawn() API by taking in {read,write}fd
pointers and returning the pid instead of using some custom struct.
this coincidently also fixes#299
[0]: https://www.kernel.org/doc/html/v4.10/process/coding-style.html?highlight=goto#centralized-exiting-of-functions
* ensure static variables comes after non-static ones
* remove depreciated DATA32 type
* prefer `sizeof(expression)` over `sizeof(Type)`.
* silence a -Wsign warning
* {gif,webp} loader: use a pointer to reduce code-noise
* gif loader: allocate in one place
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/374
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
handle a rare, but possible case of argc being 0, in which case argv[0]
would be null.
note that both POSIX and ISO C standard allow argc to be 0 and in
practice this can be triggered via calling `exec(3)` family of functions
with NULL as the first `argv`.
* run_key_handler: make the logic easier to follow
* remove timeout_t
the typedef is not needed. inline the declaration similar to the other
static structs.
* simplify estrdup
reuse emalloc, instead of calling malloc and null-checking.
* win_clear: initialize `e` right away
* process_bindings: explicitly check against NULL
most pointer checks in the codebase do explicit check.
* use a named constant instead of magic number
also changes the padding from 3 to 4 bytes according to [0]. but i
couldn't find any situtation where this mattered, so perhaps the current
padding is enough. but doesn't hurt adding one more byte.
[0]: https://nullprogram.com/blog/2017/10/06/
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/356
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
* includes are sorted alphabetically
* their grouping and layout is the following:
- nsxiv.h will be the first include
- followed by any internal headers (e.g "commands.h" "config.h")
- followed by system headers (<stdlib.h> etc)
- followed by third party headers (X.h libwebp etc)
* also add `llvm-include-order` check to clang-tidy so that it can catch
unsorted includes during CI.
* rm unused include <sys/types.h>
* move <sys/time.h> to main.c, it's the only file that needs it.
* move TV_* macros to main.c
* let *.c files explicitly include what they need instead of including
them at nsxiv.h
the warnings on r_readdir(), img_load_gif() and strcpy seems to be false
positives. the warning about fmt being unused is valid, but not worth
fixing with additional #ifdef guards.
use `assert` to silence the false positive cases when possible,
otherwise use a NOLINT comment with an explanation.
it's possible for the close() calls to override the errno resulting in
incorrect error message being printed.
call error() immediately to avoid such possibilities.
also refactor a couple conditions to avoid doing multiple checks.
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/321
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
currently, in case of error, r_mkdir will leave the path at a truncated
state.
a7d39b0ab8 is the commit that introduced this change, and in it the
error printing is moved from r_mkdir to the caller, which makes me think
it was probably intentional.
make it so that the function itself prints the error/warning
message and returns the path back to the caller unharmed.
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/322
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
byteorder_t and size_readable is not used anywhere within the code.
byteorder_t seems to be a remain from some time sxiv handled exif data itself instead of relying on a library, introduced in 691c6d7, and probably became irrelevant when libexif was added as dependency again. And size_readable from some time it displayed the file size in the window title, introduced in bad9a70.
* tns_clean_cache: remove unused function arg
* remove malloc casting
* improve consistency
use sizeof(T) at the end
* avoid comparing integers of different signedness
* use Window type for embed and parent
* remove unnecessary comparisons
* remove cpp style comments
* improve consistency: remove comma from the end of enumerator list
* Removed useless _IMAGE_CONFIG defines
* consistency: use the same order as snprintf
* Resolve c89 warnings
Co-authored-by: uidops <uidops@protonmail.com>
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
* remove duplicate comment
* remove empty tabs and blank lines
* move macros and globals ontop
* comment to seprate function implementation
* fix alignment
* switch to *argv[] similar to other suckless code
* kill all empty last lines
* append comment to endif
* reuse existing ARRLEN macro
* comment fall through
* use while (true) everywhere
Co-authored-by: NRK <nrk@disroot.org>
Code under a different license should be kept in a separate file. This
implemention is a single header file with ~65 lines, so it better fits this
requirement.
Fixes#276
Instead of rendering the entire filename at once, Xft will let us do it
character by character. This will allow sxiv to query fontconfig for
a font that can provide any missing codepoints, if needed.
A known issue of this patch is that the "..." dots rendering will not
work properly for very long multibyte filenames. That is because we
cannot easily predict the final width of the rendered filename before
drawing it. I couldn't figure out a clean way to deal with this, so I
ended up just truncating the offending filenames.
- Functions warn() and die() replaced by GNU-like error(3) function
- Register cleanup() with atexit(3)
- Functions called by cleanup() are marked with CLEANUP and are not allowed to
call exit(3)
The function "free" performs input parameter validation.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
It is therefore not needed to check a passed pointer before this function call.
A corresponding update suggestion was generated by the software "Coccinelle"
from the following semantic patch approach.
http://coccinelle.lip6.fr/
@Remove_unnecessary_pointer_checks1@
expression x;
@@
-if (x != \(0 \| NULL\))
free(x);
@Remove_unnecessary_pointer_checks2@
expression x;
@@
-if (x != \(0 \| NULL\)) {
free(x);
x = \(0 \| NULL\);
-}
@Remove_unnecessary_pointer_checks3@
expression a, b;
@@
-if (a != \(0 \| NULL\) && b != \(0 \| NULL\))
+if (a)
free(b);
@Remove_unnecessary_pointer_checks4@
expression a, b;
@@
-if (a != \(0 \| NULL\) && b != \(0 \| NULL\)) {
+if (a) {
free(b);
b = \(0 \| NULL\);
}
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>