Bug 6477 - strnlen is not portable
Summary: strnlen is not portable
Status: RESOLVED WONTFIX
Alias: None
Product: hal
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: x86 (IA32) NetBSD
: high normal
Assignee: Kay Sievers
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-03 07:35 UTC by Julio Merino
Modified: 2006-04-07 19:23 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Proposed patch. (1.26 KB, patch)
2006-04-03 07:36 UTC, Julio Merino
Details | Splinter Review

Description Julio Merino 2006-04-03 07:35:55 UTC
The volume_id/util.c file uses the strnlen function to check for the length of a
string.  As the strnlen(3) manual page says in a Linux system, this is a GNU
extension, which means that the function is not available in operating systems
that do not use the GNU libc.  For example, NetBSD, but this surely affects many
other.

The build process emits a warning when building that file, saying that the
prototype for strnlen is not available.  This will result in a later failure
during the link process because that call will not resolve to anything.

The attached patch fixes this issue by getting rid of the strnlen call and
replaces it with a very simple loop that does the same.  I've preferred not to
use a configure check nor other magic because it'd add unnecessary bloat with no
real gain.

The patch also fixes another warning that affects the isspace() call.  As this
is defined as a macro, the value passed to it is directly used by the code as an
array subscript.  This can be solved by using an explicit cast to int.

See below for the output of the compiler:

if /bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I..
-DDEBUG  -I/usr/pkg/include -I/usr/X11R6/include  -g -O2 -Wall -Wchar-subscripts
-Wmissing-declarations -Wnested-externs -Wpointer-arith -Wcast-align
-Wsign-compare -MT util.lo -MD -MP -MF ".deps/util.Tpo" -c -o util.lo util.c; \
then mv -f ".deps/util.Tpo" ".deps/util.Plo"; else rm -f ".deps/util.Tpo"; exit
1; fi
 gcc -DHAVE_CONFIG_H -I. -I. -I.. -DDEBUG -I/usr/pkg/include
-I/usr/X11R6/include -g -O2 -Wall -Wchar-subscripts -Wmissing-declarations
-Wnested-externs -Wpointer-arith -Wcast-align -Wsign-compare -MT util.lo -MD -MP
-MF .deps/util.Tpo -c util.c  -fPIC -DPIC -o .libs/util.o
util.c: In function `volume_id_set_label_string':
util.c:114: warning: implicit declaration of function `strnlen'
util.c:116: warning: subscript has type `char'
Comment 1 Julio Merino 2006-04-03 07:36:47 UTC
Created attachment 5172 [details] [review]
Proposed patch.
Comment 2 Kay Sievers 2006-04-08 12:23:46 UTC
volume_id will be removed from the hal sources sometimes soon and on Linux udev
will provide the already queried data and also a shared lib to link against.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.