aboutsummaryrefslogtreecommitdiff
path: root/lib/portability.h
AgeCommit message (Collapse)Author
2020-11-06portability.h: ensure _FILE_OFFSET_BITS=64 takes effect.Elliott Hughes
I added a #include above this, which caused subtle breakages on 32-bit systems. Move it to the top of the file to fix it and avoid making a similar mistake in future.
2020-10-29Make it easier to switch regex implementations.Elliott Hughes
One reason to use toybox on the host is to get the same behavior across Android/Linux/macOS. Unfortunately (as we've seen from a few bugs) one area where that doesn't quite work is that toybox uses the libc regular expression implementation. That's fine, and mostly what users want, but those folks trying to get the exact same behavior everywhere might want to switch in a known regex implementation (bionic's NetBSD regex implementation, say) for increased consistency. That actually works pretty well, but portability.h has an #ifndef test for REG_STARTEND before including <regex.h> that gets in the way. To make up for that, this patch removes the unnecessary #include <regex.h> from grep.c itself.
2020-04-02Move #include <linux/*.h> into individual commands, initialize structRob Landley
with memset() instead of = {}, and move TT.alarm to local variable.
2020-04-01Add rtcwake.Elliott Hughes
Some of the bringup folks are debugging RTC issues and asked for this. Rather than duplicate the weird xtzset dance with mktime, I've factored that out into a new xmktime that takes a boolean for whether to use UTC or local time. Otherwise, the slight cleanup of hwclock.c is entirely optional. The only functional change there is that util-linux 2.34's hwclock uses ISO time format, which is the usual toybox preference anyway, so I've switched it over to that rather than ctime(3). Bug: http://b/152042947
2020-03-11Fix Mac build.Elliott Hughes
The recent re-enablement of the BLKGETSIZE64 code broke the Mac build. Use the equivalent <sys/disk.h> ioctl() pair instead.
2020-03-10modinfo: various fixes.Elliott Hughes
I came here because the new -Wno-unreachable-code-loop-increment warning didn't like the for loop on line 86. That loop is indeed not necessary. Use strend() to do a string suffix match. Use memmem() to search. It's available on macOS and Android by default, but it's behind _GNU_SOURCE for glibc, so add that to portability.h. Output the tags in the same order as the Debian modinfo. I've left "parmtype" in even though the Debian modinfo doesn't output it at all. Also fix the tests so that they work on a device that has modules for multiple kernels installed (like my laptop) --- make sure that the two modules we pick come from the same kernel.
2019-12-06stat: fix filesystem type on macOS.Elliott Hughes
(Also show unknown values on Linux in hex rather than just "unknown".)
2019-11-23Fix dev_minor()/dev_major()/dev_makedev() for Mac.Elliott Hughes
Major/minor device encoding is not portable. No two BSDs agree with each other, and Darwin is different again. Everyone does agree on having major()/minor()/makedev() macros, but they disagree whether they should be in <sys/types.h> (the BSDs including Darwin, and old versions of glibc) or <sys/sysmacros.h> (glibc >= 2.26 and bionic). This fixes `ls -l /dev/zero` and `stat /dev/zero` on Mac.
2019-11-22Add getopt(1).Elliott Hughes
Includes new tests.
2019-11-13Old gcc versions are confused by __has_include(), so nest the #ifdefsRob Landley
and #define/#undef a second symbol for the else case.
2019-10-27macOS: implement posix_fallocate().Elliott Hughes
2019-10-23Use adjtimex instead of adjtime (bionic hasn't got adjtime).Rob Landley
And check in more multicast support that's been sitting in the tree, I don't have a test enviornment for it anymore but somebody wanted this...
2019-10-10The __ANDROID_NDK__ symbol is missing from ndk-r20 but Dan Albert pointedRob Landley
out clang's __has_include(), and && shorts out the eval for gcc.
2019-06-11Move sig_to_num and num_to_sig into portability.c.Elliott Hughes
macOS doesn't have real-time signals, and it has a slightly different set of non-portable signals from Linux. With this, the toybox `kill -l` output matches the default macOS kill(1).
2019-06-08macOS: numerous fixes.Elliott Hughes
This patch adds a BSD version of xgetmountlist (for the path == NULL case only), tested on macOS. It also papers over the differences between macOS' and Linux's xattr APIs. For once I think the macOS one is better. The imitation of mknodat I've had to write swings things back in Linux's favor though. BSD calls f_frsize by the name f_iosize instead. (FWIW, it looks like this is meaningless on Linux and actually meaningful on macOS.) I've added one #if to toys/ --- I'm calling pathconf in stat.c to work around the absence of f_namelen, and have left a TODO with an explanation. I'm not sure what the best fix is here, so punting. No-one can agree what f_fsid is, even if they're all basically the same, so work around the `val` versus `__val` issue between macOS and Linux. With this patch, it's now possible to build cp/mv/install and stat for macOS too. (Which completes the set of "toybox commands currently used on Linux as part of the AOSP build" if you ignore stuff that deals with processes, which I doubt we'll ever be able to support for lack of any API.)
2019-06-07Remove getprop, setprop, start, and stop from toyboxTom Cherry
These are Android specific, so not really helping the outside community, and are getting more and more Android dependencies to work correctly, so let's drop these from toybox and build them within Android. Change-Id: Ic6022f1f506e10868c61f55d64fa4e7c1b14eba2
2019-05-25Move notify.c into portability.c (collate the #ifdefs), move global variablesRob Landley
into a structure passed as arguments, add x prefix to functions that can fail, add overflow test.
2019-05-25tail: support -f on BSD too.Elliott Hughes
Factor out the inotify code and add a kqueue equivalent. Specifically tested on macOS 10.14, but I assume this works for other BSDs too, given that I worked from the FreeBSD man page...
2019-05-06Greatly simplify and speed up regexec0() using REG_STARTEND.Rob Landley
This is a 15 year old freebsd extension (presumably thus also available on MacOS) that glibc adopted in 2004, uClibc adopted in 2005, and bionic supports. The only thing that DOESN'T support it is musl, once again because its maintainer explicitly decided not to (https://www.openwall.com/lists/musl/2013/01/15/26), so add an #ifdef to let musl stay uniquely broken. (It'll stop at first NUL, everything else can match NULs). Finally fixes "s/x/y/g on a megabyte line of x's takes forever" issue.
2019-05-02Android moved the scheduler policy functions in Q.Elliott Hughes
They're forwarded to libprocessgroup, but we may as well go straight to the source since neither library is in the NDK anyway. This code is unfortunate because it means that even `toybox true` ends up pulling in a JSON parser at runtime, because ps might call get_sched_policy/get_sched_policy_name. I'll experiment with dlopen-on-demand in portability.c and see whether the savings are worthwhile, but for now at least use the current library directly so we can save *one* dlopen!
2019-04-21Shouldn't need clearenv() for macosx now we've got xclearenv.Rob Landley
2019-02-05The android NDK does not appear to have adjtime(). (It has the syscall, andRob Landley
it has clock_settime(), but not the libc adjtime() function...) *shrug* Stub it out in portability.h.
2019-01-08FreeBSD doesn't #define IUTF8 in termios.h, add workaround to portability.h.Rob Landley
2019-01-08Ed Maste says freebsd hasn't got sys/xattr.h, so move it to portability.h.Rob Landley
2019-01-08Add FreeBSD endianness supportEd Maste
2018-12-07macOS: fix code using POSIX 2008 `st_[acm]tim` fields.Elliott Hughes
Hopefully they'll fix this properly at some point, but until then...
2018-12-07Forgot to check the portability.? changes. (Oops.)Rob Landley
2018-11-30macOS: work around header idiosyncracies.Elliott Hughes
2018-11-30macOS: fix endian macros for macOS.Elliott Hughes
I've also flipped the `#if` because `#ifdef` feels more naturally readable than #ifndef when there's also a `#else`. (I've preserved the oddness of the clearenv declaration being here, because there isn't currently a more suitable `#ifdef __APPLE__` to move it too. Later...)
2018-11-29Remove an extra #include <string.h>Rob Landley
2018-11-29macOS: remove glibc 2.10 workarounds.Elliott Hughes
The only part of this I actually need for macOS is to remove __APPLE__ from the getdelim/getline workaround, but if we're following the usual "seven year rule", glibc 2.10 is dead to us anyway, and we should just remove all of this.
2018-11-28macOS: there's no <features.h> on the Mac.Elliott Hughes
2018-11-28macOS: replace local strnstr with strcasestr.Elliott Hughes
bionic, glibc, macOS, and musl all have strcasestr (see http://man7.org/linux/man-pages/man3/strstr.3.html). macOS (via BSD) has a strnstr that does what strnstr sounds like it should do by analogy with strnlen and strncpy. So we at least need to rename strnstr, but it probably makes more sense just to switch to strcasestr instead.
2018-11-28macOS: noreturn.Elliott Hughes
The macOS libc headers use `__attribute__((noreturn))` rather than `__attribute__((__noreturn__))`, so toybox's `noreturn` macro trips them up. Since we already have a variety of uses of `__attribute__` that aren't guarded in this way, let's do the same here.
2018-10-20The static NDK fix broke the dynamic NDK build.Rob Landley
2018-10-10Fix static Android NDK build.Rob Landley
2018-10-07Fix non-android ps build.Rob Landley
2018-10-07libcutils isn't in the NDK.Elliott Hughes
Bug: https://github.com/landley/toybox/issues/43
2018-10-04Make it possible to build the AOSP .config against glibc.Elliott Hughes
It's possible that we should just pull setprop back out of toybox to live with getprop in system/core/, but this lets us build the same toybox configuration for device and host in AOSP. (Longer term we'd like to use host bionic, but if we enable this we can start experimenting on the tobyox side before the bionic side is finished.)
2018-09-15Fix glibc build after 013876f067a11ebfcf47789921b376e7bf3bf5b8.Elliott Hughes
/usr/include/unistd.h:626:15: error: conflicting types for 'confstr'
2018-09-08Tweaks to make building with Android NDK's llvm happier.Rob Landley
2018-07-04Add xgetrandom() with probe for new system call (else open/read /dev/{,u}random)Rob Landley
2018-01-01Cleanup logger.c, and move the facilitynames/prioritynames SYSLOG_NAMESRob Landley
stuff syslog.h does into lib.c and portability.h
2017-05-21Cleaup chrtRob Landley
2017-05-08Remove old uClibc compatibility glue. It's been 5 years since the last release.Rob Landley
See http://lists.busybox.net/pipermail/buildroot/2016-December/180102.html for a full post-mortem on the project.
2017-04-30Android NDK doesn't have cutils/sched_policy.h so add a probed config symbol.Rob Landley
2017-02-20Fix dmesg -c and -C.Elliott Hughes
I never use these, so I didn't notice I'd broken them until someone who does bringup complained. The "one weird trick" with SEEK_DATA is documented at the URL we already point to. SEEK_DATA was added in Linux 3.1 (2011) and isn't available in glibc 2.19 (2014), so I've added that to "portability.h" for the benefit of Ubuntu 14.04. Also make -c and -C mutually exclusive. Also fix some of the formatting I introduced earlier. (A clang-format file would help prevent these mistakes...)
2016-05-04Simplify ps android scheduling policy fetch slightly.Rob Landley
2016-04-30Add a ps "PCY" field for Android scheduling policy.Elliott Hughes
2016-04-08Redefining basename_r to mean something random seems popular (bionic and freebsdRob Landley
both did it) so use getbasename instead.