summaryrefslogtreecommitdiffstats
path: root/include/c.h
Commit message (Collapse)AuthorAgeFilesLines
* include/c: use __has_attributeKarel Zak2019-05-211-12/+19
| | | | | | | | | | | | | | The __has macros are more portable (supported by gcc as well as clang). The old __GNUC_PREREQ is deprecated and it should be removed in future. (Well, the __has macros are supported since gcc 5, so we should be patient as some old stable distros (e.g. RHEL 7) use gcc 4.x). This patch helps clang to correctly analyze our xalloc.h stuff. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-0/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch '2018wk48' of https://github.com/kerolasa/util-linuxKarel Zak2018-12-101-1/+1
|\ | | | | | | | | * '2018wk48' of https://github.com/kerolasa/util-linux: include/c: check returns_nonnull function attribute with __GNUC_PREREQ
| * include/c: check returns_nonnull function attribute with __GNUC_PREREQSami Kerola2018-12-021-1/+1
| | | | | | | | | | | | | | | | | | Karel pointed out previous commit could have been better in github feedback, so lets use the version check macro instead of compare versions directly. Previous-commit: f1b327f8d5c8de7bf7fae99e85765d0954a25bac Reference: https://github.com/karelzak/util-linux/pull/704#issuecomment-432605211 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | include/c: re-add type checking in container_of()Ruediger Meier2018-12-031-2/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts parts of commit eb06d5d4, which seems to be based on Linux kernel commit c7acec71. Unlike the original kernel patch we did not add that even stronger type checking by using macro BUILD_BUG_ON_MSG. So basically we removed a useful warning when compiling such broken code: struct st { int a; char b; }; struct st t = { .a = 1, .b = 2 }; struct st *x = container_of(&t.a, struct st, b); printf("%p %p\n", (void *)&t, (void *)x); Moreover we also introduced a new compiler warning for intel/icc: "arithmetic on pointer to void or function type" Let's just revert the update of container_of() because adding a kernel-like BUILD_BUG_ON_MSG would be too much noise and also problematic (see kernel commit c03567a8). Also note that the original problem addressed by the kernel commit seems to be only reproducible with gcc 4.9, not with any later gcc nor clang,icc. Moreover, currently we have no such use-case in the UL sources anyways. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* include/c: use returns_nonnull function attribute in xalloc.hSami Kerola2018-11-211-0/+6
| | | | | | | | Let the compiler optimize based on the knowledge that the return value will never be null. Reference: https://patchwork.ozlabs.org/patch/281112/#631159 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/c: add NAME_MAX compatSevan Janiyan2018-10-031-0/+4
| | | | | | | Upstreamed from pkgsrc. Addresses: https://github.com/karelzak/util-linux/pull/695 Signed-off-by: Karel Zak <kzak@redhat.com>
* include/list, include/c: update and container_of()Karel Zak2018-07-201-3/+9
| | | | | | | | * update container_of() to version without "const" qualifier * use container_of() in list_entry() Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: add errexec()Karel Zak2018-02-011-0/+6
| | | | | | | | | | | | | | | | The new errexec() macro consolidate and unify the way how util-linux tools react to failed exec()-like functions: * exit code 126 when program located, but not usable * exit code 127 when could not find program to exec The exit codes are compatible with coreutils. Note that all the change is located in c.h; the file exitcodes.h contains API specific (mkfs, fsck, ...) codes only. Addresses: https://github.com/karelzak/util-linux/pull/311 Signed-off-by: Karel Zak <kzak@redhat.com>
* hwclock: update usage()J William Piggott2017-09-051-1/+1
| | | | | | Improve usage strings for debug and version. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-4/+2Star
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: update --help content againRuediger Meier2017-06-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We change -h, --help display this help and exit -V, --version output version information and exit to -h, --help display this help -V, --version print version Some thoughts about this: * use "display" for --help because it matches better if we would add pager support (like git --help) * "print" for --version to be different * "this" for --help is important to make clear that running --help would not give you any better information than the one you see already * remove "information and exit" because it's bloat for the short-help, everybody knows what it does if it exists In the manpages we should use the old, longer but more correct descriptions, inclusive a reminder if --help/--version are only working when used as the only option. Note the term "version information" indicates that we don't only print a single version number. CC: J William Piggott <elseifthen@gmx.com> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+12
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: revert to the old USAGE_HELP stringsRuediger Meier2017-06-261-2/+2
| | | | | | | | | | | | | | This reverts the include/c.h part of cc7cb070. As discussed on ml. Our current strings are imported from coreutils and not too bad. Also the old strings are still hardcoded at many places. So let's revert the change, then consolidate these strings really everywhere and then think again whether and how we should change them. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: consolidate usage() "Available columns"Karel Zak2017-06-261-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch '170622' of github.com:jwpi/util-linuxKarel Zak2017-06-261-1/+3
|\ | | | | | | | | | | | | | | * '170622' of github.com:jwpi/util-linux: Docs: move option naming to howto-contribute.txt Docs: update howto-usage-function.txt Docs: add a comment for constants to boilerplate.c include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
| * include/c.h: add USAGE_COMMANDS and USAGE_COLUMNSJ William Piggott2017-06-241-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | * login-utils/lslogins.c: all uses changed * misc-utils/findmnt.c: likewise * sys-utils/blkzone.c: likewise * disk-utils/sfdisk.c: likewise * sys-utils/lscpu.c: likewise * sys-utils/lsmem.c: likewise * sys-utils/wdctl.c: likewise Signed-off-by: J William Piggott <elseifthen@gmx.com>
* | misc: no more errtryh()Ruediger Meier2017-06-251-6/+0Star
|/ | | | | | | Nowadays all our regular commands have --help options. test_uuidd does not use translations anyways. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* hwclock: update --help content and grammarJ William Piggott2017-06-211-2/+2
| | | | | Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: J William Piggott <elseifthen@gmx.com>
* hwclock: add usage() functions headingJ William Piggott2017-06-211-0/+1
| | | | | | | | | | | Make a functions heading, similar to the existing options heading. * include/c.h: define USAGE_FUNCTIONS * Documentation/boilerplate.c: add USAGE_FUNCTIONS * sys-utils/hwclock.c add functions header to usage() Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: J William Piggott <elseifthen@gmx.com>
* agetty: fix characters reorder in login promptKarel Zak2017-03-271-0/+4
| | | | | | | | | | | | | | The current agetty uses TIOCSTI ioctl to return already read chars from login name back to the terminal (without read() before tcsetattr() we will lost data already written by user). The ioctl based solution is fragile due to race -- we can return chars when terminal already contains another new chars. The result is reordered chars in login name. The solution is to use extra buffer for already read data. Reported-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-0/+6
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c.h: add errtryhelp()Karel Zak2016-12-191-0/+9
| | | | | | | | | | Add code to print: Try '<progname> --help' for more information. and exit. Signed-off-by: Karel Zak <kzak@redhat.com>
* include: move sys/sysmacros.h to c.hKarel Zak2016-03-081-0/+4
| | | | | | | The file is no portable (#ifdef HAVE_SYS_SYSMACROS_H is necessary), but needed on many places. It seems better to keep it in c.h. Signed-off-by: Karel Zak <kzak@redhat.com>
* include: provide MAP_ANONYMOUS on OSXRuediger Meier2016-02-181-0/+8
| | | | | | | Hope there are no side effect when defining _DARWIN_C_SOURCE globally. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* login, mount: fix __SC_GETPW_R_SIZE_MAX usageKarel Zak2015-12-151-0/+9
| | | | | | | | | | sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd buffer (see getpwnam_r man page or POSIX). This is not large enough in some cases. Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN). Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: add --disable-assertKarel Zak2015-08-041-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: Define F_DUPFD_CLOEXEC on kFreeBSD systems if missingGuillem Jover2015-06-081-0/+6
| | | | | | | The kernel of FreeBSD version 10 and higher supports this fcntl command, but the system libc, in this case glibc, might not yet know about it. Signed-off-by: Guillem Jover <guillem@hadrons.org>
* include/c: define UL_ASAN_BLACKLIST address_sanitizer function attributeSami Kerola2014-12-191-0/+17
| | | | | | | | The UL_ASAN_BLACKLIST allows AddressSanitizer to be switched off for functions that cannot be checked. Reference: http://dxr.mozilla.org/mozilla-central/source/mfbt/Attributes.h Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libfdisk: fix bug in cmp_numbers() and partitions sortingKarel Zak2014-12-041-1/+1
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191 Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix cfdisk freespace analyzeKarel Zak2014-12-041-0/+8
| | | | | | | | | The problem is how fdisk_partition_cmp_start() compare numbers, the function returns result from "a->start - b->start", unfortunately the numbers are uint64, but function returns "int". Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191 Signed-off-by: Karel Zak <kzak@redhat.com>
* include: fix compiler warningsSami Kerola2014-10-011-5/+5
| | | | | | | | | | | | | | | | | This change has motivation to make -Wall -pedantic compiler options to spit a little bit less noise, which with luck will increase change to notice real issues. Multiple of these: warning: ISO C forbids braced-groups within expressions [-Wpedantic] And nearly 300 times reported: include/c.h:75:41: warning: struct has no named members [-Wpedantic] #define UL_BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/c: do not gettextize a wordless stringBenno Schulenberg2014-05-061-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* include/c: remove a duplicate includeBenno Schulenberg2014-05-061-10/+7Star
| | | | | | Also tweak some comments. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* include/c.h: add macro to print definitions as stringSami Kerola2014-05-041-0/+9
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/c.h: prefer nanosleep() over usleep()Karel Zak2014-01-241-5/+12
| | | | | | | | | | | | | | Let's use nanosleep() although if usleep() exists. The nanosleep function does no interact with signals and other timers. The patch introduces xusleep() as replacement to libc (or our fallback) usleep(). Yes, we don't want to use struct timespec + nanosleep() everywhere in code as nano-time resolution is useless for us. The patch also enlarges delays in some busy wait loops. It seems enough to try read/write 4x per second. Signed-off-by: Karel Zak <kzak@redhat.com>
* include/xalloc: add warn_unused_result to allocation functionsKarel Zak2013-07-091-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: add macro UL_CLOEXECSTRKarel Zak2013-04-031-0/+8
| | | | | | ... to make "e" for fopen() portable to systems without O_CLOEXEC. Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: arch is gone, use delpart as usage() function exampleSami Kerola2013-03-261-1/+1
| | | | | | The arch.c was removed in commit 27abd809. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* sulogin: make usleep() workaround workWerner Fink2012-12-181-3/+7
| | | | | | Simply fix a compile problem found during debugging console.c Signed-off-by: Werner Fink <werner@suse.de>
* include/c: move usleep() fallback to c.hKarel Zak2012-10-221-0/+15
| | | | | | To make it available everywhere in code. Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: remove MAXHOSTNAMELEN macroKarel Zak2012-10-191-11/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: add get_hostname_max() inline functionSami Kerola2012-10-191-0/+18
| | | | | | | | | | | | Using sysconf(_SC_HOST_NAME_MAX) does not work everywhere. At such even header values for hostname length should be preferred, and if nothing else works guess the maxium being 64 bytes. Based-on-code-by: Karel Zak <kzak@redhat.com> CC: Mike Frysinger <vapier@gentoo.org> References: http://www.spinics.net/lists/util-linux-ng/msg07050.html Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* dmesg: add fileback for SEEK_DATAKarel Zak2012-07-241-0/+11
| | | | | Reported-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: move fallback for MAXHOSTNAMELEN to c.hKarel Zak2012-05-291-0/+11
| | | | | Reported-by: Thomas Schwinge <thomas@codesourcery.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* include: [c.h] protect container_ofmaximilian attems2012-05-231-0/+2
| | | | | | | | | | fixes lots of warning noise: ../../../include/c.h:112:0: warning: "container_of" redefined [enabled by default] /usr/lib/klibc/include/stddef.h:52:0: note: this is the location of the previous definition Signed-off-by: maximilian attems <max@stro.at>
* losetup: make xgetpass more robustKarel Zak2012-01-171-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lists: add list sorting routineDavidlohr Bueso2011-12-161-0/+8
| | | | | | | | | | | | | | | | | We need a list sorting function, just to mention one example user that could benefit is the lib/tt code to sort columns. This patch adds list_sort() which uses the Merge Sort algorithm, behaving nicely in O(nlog(n)), heavily based on the kernel's implementation[1]. The private data (void *priv) passed to the comparison function as been removed to adopt a qsort(3)-like syntax, and IMHO we don't really need it anyways. [1]: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=lib/list_sort.c;h=d7325c6b103f0be078ff3672c35c468ed35738f1;hb=HEAD [kzak@redhat.com: - use size_t in list_sort()] Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: check scanf %ms modifierKarel Zak2011-10-101-0/+9
| | | | | | | | | | | | Without the check libmount builds on systems that has older than 2.7 glibc are silently unsuccessful. The missing %ms modifier will, at least, result on such system missing output of findmnt and lsblk commands. If either %ms or %as modifiers are present the libmount build is disabled. Based on patch from: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: rename BUILD_BUG_ON_ZERO definitionSami Kerola2011-10-101-2/+2
| | | | | | | | | | | | Definition name is changed to UL_BUILD_BUG_ON_ZERO to avoid collision with a system header. ../include/c.h:72:1: warning: "BUILD_BUG_ON_ZERO" redefined In file included from /usr/include/sys/sysinfo.h:25, from dmesg.c:16: /usr/include/linux/kernel.h:34:1: warning: this is the location of the previous definition Signed-off-by: Sami Kerola <kerolasa@iki.fi>