summaryrefslogtreecommitdiff
path: root/string.h (follow)
Commit message (Collapse)AuthorAge
* 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.
* 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.
* Doxify version functions.Andre Noll2025-03-25
| | | | | | | The two auto-generated public functions come undoxified, so document their declarations in string.h. Fixes: 69bace22205b4bb01673f7c9873f57a43bd6a0f7
* 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.
* 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
* | 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.
* string: Remove malloc attribute from para_realloc().Andre Noll2021-10-27
| | | | | | | | | | | | | | | | | | | | Quoting from the corresponding section of the gcc-10 manual: This tells the compiler that a function is 'malloc'-like, i.e., that the pointer P returned by the function cannot alias any other pointer valid when the function returns, and moreover no pointers to valid objects occur in any storage addressed by P. Using this attribute can improve optimization. Compiler predicts that a function with the attribute returns non-null in most cases. Functions like 'malloc' and 'calloc' have this property because they return a pointer to uninitialized or zeroed-out storage. However, functions like 'realloc' do not have this property, as they can return a pointer to storage containing pointers. Found by code inspection, the unpached code never caused problems. Also, the function definition in string.c does not contain the attribute.
* 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 }'
* string.h: Fix indentation, add doxygen reference.Andre Noll2017-08-08
| | | | | The comment was improperly formatted, and the reference to para_printf() lacked a \ref statement.
* 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.
* Fix signedness issues in format strings.Andre Noll2016-12-04
| | | | | | | | | | | | | | Compiling with -Wformat-signedness (not enabled so far) causes many warnings because of format strings which specify an unsigned type but correspond to an argument of signed type, or vice versa. This commit fixes all these mismatches. For "%u", "%d", "%lu", "%ld" we let the format string match the type of the argument, but for "%x" we need to cast the argument to a suitable unsigned type. After this patch the tree compiles cleanly with -Wformat-signedness given. The warning will be enabled in a subsequent commit.
* 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.
* Do not check return value of WRITE_STATUS_ITEM().Andre Noll2015-08-12
| | | | | | | The previous commit removed error checking from para_printf(), but one instance remains: the WRITE_STATUS_ITEM() macro which also calls para_printf(). This patch removes the error checking code of this macro and adjusts all callers.
* 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.
* Assorted typo fixes in comments.Andre Noll2015-01-11
| | | | Quite a few..
* 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
* 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: 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.
| * string: Clean up for_each_line() and related functions.Andre Noll2013-05-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While for_each_complete_line() is a static function, there are two public functions, for_each_line() and for_each_line_ro(), which are implemented as simple wrappers for the static one. The only difference between the two is that for_each_line_ro() sets the FELF_READ_ONLY bit while for_each_line() does not. Since we are about to add another bit of information soon, let's make the bitmap and the static function public, and remove the two wrappers. All callers are changed to pass an additional "unsigned flags" to indicate whether they want the read-only behavior. Documentation is updated accordingly.
* | Merge branch 't/utf8'Andre Noll2013-05-14
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | Was cooking since 2013-03-10. a946af string.c: Fix typo in documentation of skip_cells(). 251394 Switch to HTF-8 for web pages. 09c6bc gui: Try to link against libncursesw. 36f38a UTF-8 support for para_gui. a99804 mp3_afh: Switch to UTF-8 encoding. f78b53 gui: Don't compute string length unnecessarily. 6224f7 Get rid of unused HAVE_NCURSES define. 6cd788 Fix --with-curses configure option.
| * UTF-8 support for para_gui.Andre Noll2012-12-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds two public helper functions to string.c which operate on multibyte strings if the character encoding used in the selected locale is UTF-8. The first new helper, strwidth(), computes the width of the UTF-8 string while skip_cells() determines the number of bytes the given multibyte string must be advanced in order to skip the given number of cells. para_gui is changed to use the new functions to properly display UTF-8 encoded data in its top and bottom windows.
* | Change copyright year to 2013.Andre Noll2013-03-25
|/ | | | Better late than never.
* Introduce create_shifted_argv().Andre Noll2012-08-27
| | | | | | | | | | In order to create argument vectors for the gengetopt parsers, filter_common.c and recv_common.c call create_argv() on the given --filter or --receiver option, then shift the returned array by one to the right because gengetopt expects the program name in argv[0]. This commit creates a new helper function for this purpose and changes the two callers to use the new function.
* Implement client-server feature negotiation.Andre Noll2012-05-05
| | | | | | | | | | The server announces a list of supported features and the client may request any subset of features. The only supported feature is "sideband". It has no effect at the moment but this will change in subsequent patches. TODO: Documentation, remove "foo" feature.
* Replace PARA_VSNPRINTF by xvasprintf().Andre Noll2012-01-20
| | | | | | | | | | | | | | | | | | | | | | The PARA_VSNPRINTF macro is rather clumsy, and too large to be inlined. Moreover, it does not return the length of the formated string, so users have to call strlen() after the call to PARA_VSNPRINTF(). This is extra work which can easily be avoided since the number of bytes written is returned by the underlying call to vsnprintf(). This patch replaces the macro by the public function xvasprintf(), which is similar to the non-standard vasprintf() on GNU systems. It also adds xasprintf(), a similar variant which takes a variable number of arguments. Unlike PARA_VSNPRINTF, xasprintf() and xvasprintf() return the number of bytes written. This relies on vsnprintf() conforming to the C99 standard and breaks in particular on glibc 2.0 systems. Since glibc 2.0 is about 15 years old, this is unlikely to cause problems on real systems. All users which called strlen() right after xvasprintf() are changed to use the return value of xvasprintf() instead.
* Change year in copyright message to 2012.Andre Noll2012-01-07
|
* Merge branch 't/interactive'Andre Noll2011-12-05
|\ | | | | | | | | Conflicts: string.h
| * string: Introduce compute_word_num().Andre Noll2011-11-20
| | | | | | | | | | | | | | | | | | The completion code needs to determine the word the curser is currently on. Libreadline only provides the start and end position of the current word in the line buffer, but not the word number. This patch adds compute_word_num() to string.c which uses the same algorithm as create_argv() to determine the word boundaries.
* | Make vorbis comment helper functions generic.Andre Noll2011-11-13
|/ | | | | | | | | copy_comment() and copy_if_tag_type() are useful also to the new flac audio format handler, so move these functions to string.c and make them public. Rename them to safe_strdup() and key_value_copy() respectively, as this is more to the point.
* Replace 2010 in copyright message by 2011.Andre Noll2011-01-17
|
* Change year in COPYRIGHT to 2010.Andre Noll2010-04-05
| | | | Hey, this is earlier than last year :)
* First draft of the wma decoder.Andre Noll2009-11-18
| | | | Understands only v1, but is easy to crash.
* Introduce para_regcomp.Andre Noll2009-07-08
| | | | | | | | | | | | | A wrapper for regcomp() that logs an error message if the regcomp() failed and uses a return value according to the paraslash rules. Currently there is only one user of regular expressions, is_v4_dot_quad(), which is converted to para_regex(), but new callers will be added soon. Unfortunately, this change made it necessary to include regex.h in all .c files that use string.h. Clean up the order in which headers are included a bit while we're at it. Maybe I should rethink the rule "Only .c files shall include header files"...
* Replace split_args() by create_argv().Andre Noll2009-07-05
| | | | | | | | | The latter function is superior as it honors quotes and special characters like '\n'. This allows for example to use whitespace characters in mood methods. Fixup and simplify all callers accordingly. The patch broke the grab command of para_audiod which is deactivated ATM and will be fixed in a subsequent patch.
* Merge branch 'afh_cleanup' into next.Andre Noll2009-07-04
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Quite a few conflicts, but no real problem. git rerere rulez! Conflicts: afs.c afs.cmd aft.c attribute.c audiod_command.c blob.c command.c para.h server.c server.cmd stat.c
| * Revamp status item handling.Andre Noll2009-07-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes the way the status items are printed and parsed. The new parser-friendly format is used internally and, as a side effect, is also available as an new listing mode for the ls command and for the stat commands of both para_server and para_audiod. With the new format, each status item is prefixed by its size, and the status item identifier is printed as a numerical value. This simplifies the parsing code in para_audiod/para_gui a bit and should make it perform better as the status items do not have to be looked up by name. More importantly, the new format gets rid of the restriction that status items should not contain newline characters because the parser knows in advance how much it has to read to get the complete item. This restriction became a real problem as more and more audio files contain (version 2 id3) tags that contain much more than a single line. For example the linux podcast mp3 files contain the full content of the podcast as text in the command tag.
* | Move para_tmpname() to file_write.c and make it static.Andre Noll2009-06-14
|/ | | | Also use para_random() instead of rand().