summaryrefslogtreecommitdiff
path: root/string.c (follow)
Commit message (Collapse)AuthorAge
* gui: Require a UTF-8 terminal.Andre Noll2026-05-25
| | | | In 2026 this should be no constraint. Affects only para_gui.
* Move read_size_header() from string.c to stat.c.Andre Noll2026-05-24
| | | | | This way it can be static, and executables which don't need it don't contain a copy of this function.
* Fix documentation of alloc().Andre Noll2026-04-08
| | | | | Apparently, the documentation of the size parameter was copied from realloc() or similar.
* Mark zalloc() with __malloc.Andre Noll2026-04-08
| | | | | This helps gcc to generate better code thanks to the no alias guarantees the attribute provides.
* Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* Remove para_strcat().Andre Noll2026-01-04
| | | | | There is only a single user in audioc.c, and this user can easily avoid the function by allocating only a single buffer.
* Modify para_hostname() to return a static buffer.Andre Noll2025-08-07
| | | | | | | | All but one caller immediately free the result after using it. The exception is daemon.c, which maintains a copy in struct daemon, and leaks it on exit. All users can trivially be converted to use the new version, which does not require to free the result.
* Improve documentation of para_printf().Andre Noll2025-07-09
| | | | | This was quite hard to read due to the many \a directives. Remove those and improve the wording.
* Merge topic branch t/build into masterAndre Noll2025-05-20
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A medium sized series for the build system which improves the way the git version string is stored in the executables and man pages. Subsequent patches of the series remove some warts from the makefile: we no longer use order-only dependencies and the .PRECIOUS target. The merge results in a conflict against the "remove regex include" commit 67388cd4fae0. This is trivial to resolve, though. * refs/heads/t/build: Doxify version functions. Doxify OV_EXCLUDE_STATIC_CALLBACKS #define. Makefile: Fix braino in tarball target. build: Remove superfluous dependency in Makefile.real. build: Remove the .PRECIOUS target. build: Improve clean targets. build: Get rid of directory order-only dependencies. build: Compile with -Wunused -Wall also on BSD. build: Revamp git versioning. build: Merge version.{c,h} into string.{c,h}.
| * build: Revamp git versioning.Andre Noll2025-03-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This rewrites GIT-VERSION-GEN and renames it to version-gen.sh. The main difference is that the script now generates version.c rather than version.h, speeding up the build because switching branches or transitioning from a clean to a dirty work-tree (or vice versa) changes the version string. Before the patch, all files which included version.h were recompiled. With the patch applied, only the short version.c needs to be recompiled. The generated version,c defines one function which returns the single-line version string and a second function which returns the multi-line version information (author, copyright, git URL etc). This information is now passed to version-gen.sh via environment variables. The CPP macros we had before are removed.
| * build: Merge version.{c,h} into string.{c,h}.Andre Noll2025-03-25
| | | | | | | | | | | | | | | | | | This is a preparatory patch for the upcoming revamp of the git version script. The revamped script generates version.c, a file which is currently tracked by git. We can easily get rid of it (and of version.h) since all paraslash executables link in both string.o and version.o. So let's move the three small functions of version.c to string.c and their declarations from version.h to string.h.
* | Include regex.h from para.h.Andre Noll2025-05-19
|/ | | | Every .c file includes it anyway.
* string.c: Remove an unused local variable in for_each_line().Andre Noll2025-03-19
| | | | | | | This set but not used variable existed for a long time, but only now the first compiler, clang-19 on FreeBSD, started to complain. Streamline the documentation a bit while at it.
* string.c: Don't fall back to /tmp in para_homedir().Andre Noll2023-12-24
| | | | | This can only lead to trouble. If we can't get the path to the home directory, something is deeply wrong and we really should abort.
* create_argv_offset(): Use arr_zalloc().Andre Noll2023-12-24
| | | | | There is no point in initializing the allocated array manually, and it does not hurt to initialize also the last element.
* Open-code find_arg().Andre Noll2022-10-03
| | | | | There is only one caller in client_common.c, so open-code the logic there and get rid of the public function and the unused error code.
* Merge topic branch t/overflow into masterAndre Noll2022-10-03
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This series implements a new memory allocation API which checks for overflows. The first part of the series just renames the main allocation functions. Later patches in the series implement allocators which take two size_t arguments (like calloc(3)) and check whether the multiplication overflows by employing the __builtin_mul_overflow() primitive supported by gcc and clang. This requires us to bump the lowest supported gcc and clang version. * refs/heads/t/overflow: build: Compile with -ftrapv. string: Introduce arr_zalloc(). string: Introduce arr_alloc(). string: Introduce arr_realloc() and check for integer overflow. string: Rename para_calloc() -> zalloc(). string: Rename para_malloc() -> alloc(). string: Overhaul para_strdup().
| * string: Introduce arr_zalloc().Andre Noll2022-07-29
| | | | | | | | | | | | Adjust all callers which pass a product of two integers to zalloc() to call the new function instead and reduce zalloc() to a one-line wrapper.
| * string: Introduce arr_alloc().Andre Noll2022-07-29
| | | | | | | | | | | | | | | | Change all callers of alloc() which pass a product of two integers as the allocation size to call the new function instead. This function aborts if the multiplication overflows. With arr_alloc() in place, alloc() reduces to a trivial wrapper which calls new arr_alloc() with the first argument equal to one.
| * string: Introduce arr_realloc() and check for integer overflow.Andre Noll2022-07-29
| | | | | | | | | | | | | | | | Use __builtin_mul_overflow() for the check. This builtin was introduced in gcc-5, so we need to bump the lowest supported version. Re-implement para_realloc() as a trivial wrapper for arr_realloc() to simplify and to avoid duplicating the size check.
| * string: Rename para_calloc() -> zalloc().Andre Noll2022-07-29
| | | | | | | | | | Reword the documentation a bit since the function has never been a wrapper for calloc(3). No code changes.
| * string: Rename para_malloc() -> alloc().Andre Noll2022-07-29
| | | | | | | | | | | | | | Just because it's shorter and matches the naming of the new allocators we are about to introduce. The bulk of this patch was created with sed -i 's/para_malloc/alloc/g' *.c *.h yy/mp.y
| * string: Overhaul para_strdup().Andre Noll2022-07-29
| | | | | | | | | | | | | | | | We don't need to print an error message because it will be clear what has happened when the assertion triggers. Reword the documentation and mention that the memory allocated by this function must be freed by the caller.
* | Merge branch 'refs/heads/t/ll'Andre Noll2022-09-18
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two little cleanups related to the logging facility and two commits which add the ll command to para_server and para_audiod. The merge resulted in a conflict in afs.c due to the earlier merge of the poll topic branch which replaced all calls to select() by calls to poll(). The implementation of the ll server command introduced a new caller of select(), afs_select(), which needs to be replaced by afs_poll() to resolve the conflict. * refs/heads/t/ll: New server command: ll to change the log level at runtime. New audiod command: ll to change the log level at runtime. daemon: Kill get_loglevel_by_name(). server/audiod: Don't parse loglevel argument unnecessarily.
| * daemon: Kill get_loglevel_by_name().Andre Noll2022-07-02
| | | | | | | | | | | | | | | | | | Open-code the logic in daemon_set_log_color_or_die() and get the values from the new SEVERTIES macro rather than duplicating the severity list in get_loglevel_by_name(). The SEVERTIES macro will turn out to be handy for the ll subcommands of para_server and para_audiod which are introduced in subsequent commits.
* | Remove para_dirname() and para_basename().Andre Noll2022-05-30
|/ | | | | | The former has only a single caller, the second only two, open-coding these is actually simpler and more performant because we no longer scan each path twice and avoid the temporary copy of the path.
* Simplify and improve freep().Andre Noll2019-10-12
| | | | | Make it a no-op if NULL is passed. Also the comment to \param was slightly incorrect and the code contained an unnecessary cast.
* string.c: Fix typos in comment.Andre Noll2018-12-25
|
* Shorten copyright notice.Andre Noll2017-09-22
| | | | | | | | | | | | | | | | | | | | | The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
* Merge branch 'refs/heads/t/doxygen'Andre Noll2017-07-21
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This series contains an update of Doxyfile to a newer doxygen version and an overhaul of the source code documentation. Several stale references have been fixed. Other parts of the documentation have been improved. Cooking for almost a month. * refs/heads/t/doxygen: aft.c: Trivial spelling/whitespace fixes. afh: Expand documentation of init function declarations. filter: Remove duplicate documentation of filter_get(). doxygen: Improve documentation of struct receiver. doxygen: Add \ref to references. Improve documentation of mm.c and mm.h. doxygen: Don't refer to Black Hats Manual. doxygen: Don't refer to libosl functions. doxygen: Trivial cleanups. doxygen: Remove some stale doxygen references. recv: Explain user data mechanism. Update to doxygen-1.8.11. The merge resulted in a few conflicts which were easy to resolve.
| * doxygen: Add \ref to references.Andre Noll2017-06-25
| | | | | | | | | | This way doxygen issues a warning if the file/function/structure no longer exists and a stale reference remains.
| * doxygen: Trivial cleanups.Andre Noll2017-06-25
| | | | | | | | A couple of capitalization and punctuation fixes.
* | Remove some unnecessary includes.Andre Noll2017-07-16
|/ | | | These headers are already included with para.h.
* string.c: Improve documentation of create_argv().Andre Noll2016-08-07
| | | | | Mention that it is OK to pass NULL, and that the returned array is NULL terminated.
* Remove explicit uses of _GNU_SOURCE.Andre Noll2016-06-12
| | | | | | | | | | | | The best way to add these flags is to use the autoconf helper AC_USE_SYSTEM_EXTENSIONS. This macro adds defines to config.h, so we must include config.h (via para.h) before anything else. The two files for which this matters are fixed by moving the include directive for para.h to the top. The AC_USE_SYSTEM_EXTENSIONS macro was introduced in Autoconf 2.60, which was released ten years ago. The existing AC_PREREQ([2.61]) check in configure.ac makes sure the macro is defined.
* Introduce sanitize_str().Andre Noll2016-03-13
| | | | | | | | | | | | Currently we sanitize the status item strings for para_gui in align_str() of gui.c. This implementation is flawed because it does not work for wide character strings. This patch provides an abstraction in string.c which works in both the UFT-8 and non-UTF-8 case. The flawed implementation of this function in gui.c is removed and the surrounding code is changed to call the new function instead.
* string.c: Simplify and rename wide character helpers.Andre Noll2016-03-13
| | | | | | | | | Just assume non-printable characters are one character wide. This gives a more reasonable approximation than the hack we have now. This patch also renames mutt_wcwidth() to xwcwidth() and mutt_wcswidth() to xwcswidth() since these functions have nothing in common with mutt any more.
* string.c: Alloc space for terminating null wide character.Andre Noll2016-03-13
| | | | | | Should not matter since we already know the number of wide characters and never look past the allocated buffer. But let's be conservative here and allocate space for the terminating null wide character.
* string.c: Handle invalid loglevels gracefully.Andre Noll2016-01-10
| | | | | Public functions should always return a proper error code on failure. Returning -1 is asking for trouble.
* string.c: Kill E_STRTOLL.Andre Noll2015-09-20
| | | | | | | | This error code is unnecessary because para_atoi64() returns it only if strtoll(3) did not perform any conversion and we have already a more descriptive error code for this case: E_ATOI_NO_DIGITS. Two new comments to para_atoi64() explain this in detail.
* string.c: Fix typo in comment.Andre Noll2015-01-20
|
* string.c: Simplify and improve for_each_line().Andre Noll2015-01-18
| | | | | Much faster for large buffers. Idea: Search for zero byte only until next cr.
* Update year in copyright headers.Andre Noll2015-01-12
| | | | | | | | | | | | | | | | Done with files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2014\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2014 Andre Noll/Copyright (C) \1 Andre Noll/1' $files In previous years we ran a similar script to set the second year in the range to the current year. This is kind of silly, so let's get rid of this useless information. This commit replaces "Copyright (C) A-B" by "Copyright (C) A" in all file headers, i.e. only the first year (A) is left in. Accurate information including time stamps for each change can be obtained from the git history.
* doc: Change email address to maan@tuebingen.mpg.deAndre Noll2014-08-18
| | | | | | | | | | | | | | The mail server on systemlinux.org was down for more than a week lately, so let's use an alternative official address. This commit changes all maan@systemlinux.org addresses to maan@tuebingen.mpg.de. Most .c and .h files contain the email address in the copyright header, so they must all be patched. Three other files contain the address for a different reason: * README lists email and git, gitweb and home page URLs * configure.ac needs it for configure -h * version.c contains it for the -V option of all commands
* Remove chop().Andre Noll2014-05-04
| | | | | | | | | | In curses_log() we currently we call chop(), which calls strlen() to find the last character of the given string. This is unnecessary since xvasprintf() returns this information anyway, we just have to remember it. With this change the last user of chop() is gone, so this patch removes chop() from string.c.
* Change copyright year to 2014.Andre Noll2014-02-22
| | | | | | | | | This year, we're really on time. The changes in this patch were created by the following silly script: files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2013\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2013 Andre Noll/Copyright (C) \1-2014 Andre Noll/1' $files sed --in-place= -e 's/Copyright (C) 2013 Andre Noll/Copyright (C) 2013-2014 Andre Noll/1' $files
* Remove __malloc attribute from para_realloc().Andre Noll2014-02-22
| | | | | This attribute tells the compiler that the returned pointer cannot alias any other pointer. This is not the case for para_realloc().
* Merge branch 't/gui_improvements'Andre Noll2013-06-07
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Was cooking for more than one month. bf1831 string: Speed up xvasprintf(). bcc083 string: Add discard feature for for_each_line(). e3868d string: Simplify return value of for_each_line(). d1f0f0 string: Simplify for_each_line(). 23b121 string: Clean up for_each_line() and related functions. 6256ed string: Replace the for_each_line_modes enum by a bitmap. 14e689 gui: Don't sleep before executing the status command. e90c6c gui: Speed up add_spaces(). 20e2c6 gui: Rename do_exit(). ef0508 gui: Remove superfluous cmd_died. d7562b gui: Check stdin for readability. a44fa6 gui: Discard overlong input lines. Conflicts: gui.c
| * string: Speed up xvasprintf().Andre Noll2013-05-02
| | | | | | | | | | | | | | | | This avoids to call vsnprintf() twice in the common case where the result is small. The running time of a simple test case that called this function in a loop improved from 13s to 8s due to this change.
| * string: Add discard feature for for_each_line().Andre Noll2013-05-02
| | | | | | | | | | | | | | | | | | | | This adds the new FELF_DISCARD_FIRST flag which instructs for_each_line() to discard everything up to the next newline. The new feature is only used by para_gui. When para_gui detects a partial overlong input line, it ignores this data and passes the FELF_DISCARD_FIRST flag in subsequent calls to for_each_line(). Hence output continues at the next line.