[icecast-dev] some portability fixes ...

Li-Kai Liu news at likai.net
Sun Sep 9 07:16:45 PDT 2001



i don't want to deal with CVS, so i'll just post some minor fixes along 
to explanations for your amusement on this list ...

I. cygwin compilability

cygwin doesn't yet handle threads that is compatible with icecast, but 
thankfully icecast supports win32 native threads. however, cygwin's 
preprocessor "#define"'s makes icecast confuse whether it should behave 
friendly to posix or win32. there is a compilation option to feed to 
cygwin's gcc: "-mno-cygwin" so the preprocessor would get rid of the 
usual posix semantics and use only mingw (msvcrt) and some windows 
headers. also there is a flag "-mno-win32" to get rid of win32 semantics 
and use posix only.

pecifically, the file "vsnprintf.c" has a portability bug (though not 
apparent) when compiled in win32. it doesn't distinguish the platform 
type and thus include <config.h> inconditionally, whereas on win32 it 
should have included <win32config.h> instead. see the patch in 
attachment: vsnprintf.c.patch.

and so it doesn't try to redefine vsnprintf() on win32 when it's already 
provided (see win32config.h).

now, to get the configure system to work under cygwin, the following 
patch to "configure.in" is needed. mainly what it does is to provide an 
interface to "-mno-cygwin" and "-mno-win32" options, and make sure it 
appears in the Makefile. (see attachment configure.in.patch).

furthermore, cygwin automatically has the newest automake and autoconf 
systems. in order to make icecast configure properly, you need to supply 
"config.sub" and "config.guess" with the icecast source distribution.

after these changes, icecast source can then generate makefiles to 
compile with cygwin's gnu tools. if "--enable-mingw" is fed to configure 
(which you can see is the default option), then the resulting binary 
will run in native win32 mode dispite being compiled with cygwin.

II. commands.c fix

commands.c has few problems, but i'll point one out here. it doesn't 
include <errno.h>, which should be included to guarentee compatibility 
with systems that define errno as a function instead of a variable.

III. file dumping problems

dumpfiles are opened with the internal function "open_for_writing" made 
available by "utility.c", which is also used to open logs and statistics 
files. on those platforms that distinguish binary and text filemodes 
(win32 and cygwin being two examples), file-dumping poses a problem 
because by default, files opened with "open_for_writing" doesn't set 
binary mode. the result is a dump file that needs to be "uncooked" or 
else won't play. patches need to be applied to commands.c and source.c 
to solve the problem. (note that the commands.c patch includes the fix 
in the previous section). mainly what they do is to setmode() after a 
valid fd is obtained.

ee attachment for commands.c.patch and source.c.patch

IV. conclusion

i'm supposed to say something nice about icecast, but there are some 
lousy programming in the source code despite the wide use of icecast 
nowadays. if i have time i'd try to point them out.

V. disclaimer

these patches work for me, but i do not guarentee they will work for 
you. make yourself a backup source branch and apply my patches to see if 
they will work for you. the purpose of these patches are primarily to 
solve portability problems, and not security fixes. these patches are 
applied directly to icecast-1.3.11.tar.gz source distribution (which 
oddly doesn't include win32config.h, just grab it from CVS).

liulk




39a40
> AC_ARG_ENABLE(mingw, [  --enable-mingw	compile icecast under cygwin using mingw libraries [default=yes]], , enable_mingw=yes)
109a111,123
> AC_CYGWIN
> 
> if test "$CYGWIN" = "no" && test "$enable_mingw" = "yes"; then
> 	echo "Dude, you're not using cygwin systems. Don't mess around with mingw."
> elif test "$CYGWIN" = "yes" && test "$enable_mingw" = "yes"; then
> 	echo "Preparing CYGWIN and mingw specific setup..."
> 	CFLAGS="$CFLAGS -mno-cygwin"
> 	LIBS="-lkernel32 -lwsock32 -lmsvcrt"
> elif test "$CYGWIN" = "yes" && test "$enable_mingw" = "no"; then
> 	echo "Preparing CYGWIN for cygnus library setup..."
> 	echo "Warning: As of cygnus 1.1.8, pthread support is crippled!!!"
> 	CFLAGS="$CFLAGS -mno-win32"
> fi
362a377,381
> if test "$enable_mingw" = "yes"; then
>     echo "don't bother to check for pthreads..."
>     THREADLIBS=""
> else
> 
373a393,394
> fi	# enable_mingw = yes
> 




86a87
> #include <errno.h>
2155a2157,2161
> 	}
> 	else
> 	{
> 		// for those lamer systems that mingles text ... LIKAI
> 		setmode( sourcecon->food.source->dumpfd, O_BINARY );




454a455,459
> 		else
> 		{
> 			// for those systems that mingles text ... LIKAI
> 			setmode( source->dumpfd, O_BINARY );
> 		}




40a41,43
> #ifdef _WIN32
> #include <win32config.h>
> #else
41a45
> #endif

--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast-dev mailing list