Commit Graph

16 Commits

Author SHA1 Message Date
Thomas Huth 9604efb183 Fix typos in the remaining lib folders
Found with the "codespell" utility.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2023-02-28 16:12:57 +11:00
Thomas Huth 63d2f38ab6 lib/libc/README.txt: Fix "cannel" typo
It should be "channel" instead of "cannel", obviously.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2021-10-01 14:09:29 +10:00
Alexey Kardashevskiy 0549fa7d08 libc: Compile with -Wextra
-Wextra enables a bunch of rather useful checks which this fixes.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
Changes:
v2:
* replaced cast to int with cast to size_t
2021-02-09 12:39:52 +11:00
Thomas Huth 12278e72d5 libc: Add a simple implementation of an assert() function
... useful for "this should never happen" situations, where
you want to make sure that it really never happens.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
[aik: removed extra ';' and empty line]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-06-07 16:38:42 +10:00
Thomas Huth 16661f937c libc: Add the snprintf() function
Code has been taken from the sprintf() function (which is almost the same,
except that snprintf calls vsnprintf instead of vsprintf internally).

Signed-off-by: Thomas Huth <thuth@redhat.com>
[aik: fixed traling spaces]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-05-29 19:06:14 +10:00
Thomas Huth 232eb915d1 libc: Check for NULL pointers in free()
POSIX says that the free() function should simply do nothing if a NULL
pointer argument has been specified. So let's be a little bit more
compliant in our libc and add a NULL pointer check here, too.

Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-05-24 19:03:53 +10:00
Thomas Huth f5825039ff libc: Implement strrchr()
This function will be used in one of the next patches to find the last
slash in a file name string.

Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-05-24 19:03:52 +10:00
Thomas Huth bc0dc19289 libc: Declare size_t as unsigned long
If size_t is only "int", memset() and friends are limited
to 4 GB. And ssize_t is already declared as "long", so it
is somewhat inconsequent to define size_t as "int" only.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2017-07-07 16:40:47 +10:00
Thomas Huth 1f0600f25d libc: The arguments of puts() can be marked as "const"
puts() does not change the string, so the parameter can be "const".

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2017-06-08 16:09:07 +10:00
Thomas Huth e0dc16c217 paflof: Add socket(), send() and recv() functions to paflof
Code is slightly based on the implementation from net-snk, but
has been adapted to use the forth_eval() and forth_push/pop() macros
instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-09-14 17:50:40 +10:00
Thomas Huth 48ae29e4c0 libc: Add srand() call
Needed for seeding the state of the pseudo-random number generator.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:12 +11:00
Thomas Huth 1487399da6 libc: Fix the rand() function to return non-zero values
The rand() function in SLOF's libc has a bug which caused the
function to always return zero: The _rand value was shifted left
by 16, and then ANDed with 0x7fff. Obviously, the shift operation
should be ">>" instead of "<<".
And while we're at it, also increase the constant for the
multiplaction in there so that more upper bits are affected.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:04 +11:00
Alexey Kardashevskiy da3bd7a2c7 libc: Port vsnprintf back from skiboot
Since initial port from slof to skiboot, vsnprintf() has improved in
skiboot so let's port the improved version back.

Suggested-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-02 14:23:25 +11:00
Nikunj A Dadhania dca8e05458 Add standard header stdbool.h
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Acked-by: Thomas Huth <thuth@linux.vnet.ibm.com>
2013-07-24 14:46:22 +05:30
Thomas Huth 33bb95bab2 Silenced some compiler warnings that occur when compiling with prototype checks
The compiler flags -Wmissing-prototypes and -Wstrict-prototypes generally help
to write code with proper prototypes. This way one can avoid some ugly bugs
because it helps to identify functions that do not have prototypes in headers.
It also helps to improve performance since local functions then have to be
declared "static", so the compiler can do better optimizations.

Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
2011-12-20 17:56:34 +01:00
Benjamin Herrenschmidt aaad509cdc Initial import of slof-JX-1.7.0-4
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2010-12-01 09:51:44 +11:00