1Index: perlio.h
2===================================================================
3--- perlio.h	(.../vendor/perl/current)	(revision 21)
4+++ perlio.h	(.../trunk)	(revision 21)
5@@ -64,7 +64,7 @@
6  */
7 #include <stdio.h>
8 
9-#ifdef __BEOS__
10+#if defined(__BEOS__) && !defined(__HAIKU__)
11 int fseeko(FILE *stream, off_t offset, int whence);
12 off_t ftello(FILE *stream);
13 #endif
14Index: haiku/haikuish.h
15===================================================================
16--- haiku/haikuish.h	(.../vendor/perl/current)	(revision 0)
17+++ haiku/haikuish.h	(.../trunk)	(revision 21)
18@@ -0,0 +1,11 @@
19+#ifndef PERL_HAIKU_HAIKUISH_H
20+#define PERL_HAIKU_HAIKUISH_H
21+
22+#include "../unixish.h"
23+
24+/* We need <sys/wait.h> or else the W* macros aren't defined in perl.h. */
25+
26+#include <sys/wait.h>
27+
28+#endif
29+
30Index: perl.c
31===================================================================
32--- perl.c	(.../vendor/perl/current)	(revision 21)
33+++ perl.c	(.../trunk)	(revision 21)
34@@ -107,7 +107,7 @@
35 
36 #endif
37 
38-#ifdef __BEOS__
39+#if defined(__BEOS__) && !defined(__HAIKU__)
40 #  define HZ 1000000
41 #endif
42 
43@@ -381,7 +381,7 @@
44      * BeOS has those, but returns the wrong value.
45      * The HZ if not originally defined has been by now
46      * been defined as CLK_TCK, if available. */
47-#if defined(HAS_SYSCONF) && defined(_SC_CLK_TCK) && !defined(__BEOS__)
48+#if defined(HAS_SYSCONF) && defined(_SC_CLK_TCK) && (!defined(__BEOS__) || defined(__HAIKU__))
49     PL_clocktick = sysconf(_SC_CLK_TCK);
50     if (PL_clocktick <= 0)
51 #endif
52Index: perl.h
53===================================================================
54--- perl.h	(.../vendor/perl/current)	(revision 21)
55+++ perl.h	(.../trunk)	(revision 21)
56@@ -2551,7 +2551,10 @@
57 #   define ISHISH "macos classic"
58 #endif
59 
60-#if defined(__BEOS__)
61+#if defined(__HAIKU__)
62+#   include "haiku/haikuish.h"
63+#   define ISHISH "haiku"
64+#elif defined(__BEOS__)
65 #   include "beos/beosish.h"
66 #   define ISHISH "beos"
67 #endif
68@@ -5609,9 +5612,10 @@
69 #if O_TEXT != O_BINARY
70     /* If you have different O_TEXT and O_BINARY and you are a CLRF shop,
71      * that is, you are somehow DOSish. */
72-#   if defined(__BEOS__) || defined(__VOS__) || defined(__CYGWIN__)
73-    /* BeOS has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect;
74-     * BeOS is always UNIXoid (LF), not DOSish (CRLF). */
75+#   if defined(__BEOS__) || defined(__HAIKU__) || defined(__VOS__) || \
76+	defined(__CYGWIN__)
77+    /* BeOS/Haiku has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect;
78+     * BeOS/Haiku is always UNIXoid (LF), not DOSish (CRLF). */
79     /* VOS has O_TEXT != O_BINARY, and they have effect,
80      * but VOS always uses LF, never CRLF. */
81     /* If you have O_TEXT different from your O_BINARY but you still are
82Index: lib/CPANPLUS/Internals/Constants/Report.pm
83===================================================================
84--- lib/CPANPLUS/Internals/Constants/Report.pm	(.../vendor/perl/current)	(revision 21)
85+++ lib/CPANPLUS/Internals/Constants/Report.pm	(.../trunk)	(revision 21)
86@@ -29,6 +29,7 @@
87     Cygwin      => 'cygwin',
88     Darwin      => 'darwin',
89     EBCDIC      => 'os390|os400|posix-bc|vmesa',
90+    Haiku       => 'haiku',
91     HPUX        => 'hpux',
92     Linux       => 'linux',
93     MSDOS       => 'dos|os2|MSWin32|cygwin',
94Index: lib/CPANPLUS/t/20_CPANPLUS-Dist-MM.t
95===================================================================
96--- lib/CPANPLUS/t/20_CPANPLUS-Dist-MM.t	(.../vendor/perl/current)	(revision 21)
97+++ lib/CPANPLUS/t/20_CPANPLUS-Dist-MM.t	(.../trunk)	(revision 21)
98@@ -45,7 +45,13 @@
99 $conf->set_conf( cpantest => 0 );
100 
101 ### Redirect errors to file ###
102-*STDERR                          = output_handle() unless $Verbose;
103+### The code in IPC::Cmd::_open3_run() uses a pipe to get the child's stderr
104+### output and IPC::Open3::_open3() will not dup the child's error end to the
105+### original STDERR FD. Instead it will assign the pipe's write end FD, which
106+### will be CLOEXEC. On exec() this FD will be closed and the select()+read()
107+### loop in IPC::Cmd::_open3_run() will become very busy, since select()
108+### will always return immediately due to the half-closed pipe.
109+#*STDERR                          = output_handle() unless $Verbose;
110 
111 ### dont uncomment this, it screws up where STDOUT goes and makes
112 ### test::harness create test counter mismatches
113Index: lib/Module/Build.pm
114===================================================================
115--- lib/Module/Build.pm	(.../vendor/perl/current)	(revision 21)
116+++ lib/Module/Build.pm	(.../trunk)	(revision 21)
117@@ -30,6 +30,7 @@
118 		 dynixptx  Unix
119 		 freebsd   Unix
120 		 linux     Unix
121+		 haiku     Unix
122 		 hpux      Unix
123 		 irix      Unix
124 		 darwin    Unix
125Index: lib/Term/ReadLine.pm
126===================================================================
127--- lib/Term/ReadLine.pm	(.../vendor/perl/current)	(revision 21)
128+++ lib/Term/ReadLine.pm	(.../trunk)	(revision 21)
129@@ -222,7 +222,8 @@
130 	$console = "sys\$command";
131     }
132 
133-    if (($^O eq 'amigaos') || ($^O eq 'beos') || ($^O eq 'epoc')) {
134+    if (($^O eq 'amigaos') || ($^O eq 'beos') || ($^O eq 'epoc') ||
135+	($^O eq 'haiku')) {
136 	$console = undef;
137     }
138     elsif ($^O eq 'os2') {
139Index: lib/ExtUtils/MM.pm
140===================================================================
141--- lib/ExtUtils/MM.pm	(.../vendor/perl/current)	(revision 21)
142+++ lib/ExtUtils/MM.pm	(.../trunk)	(revision 21)
143@@ -69,6 +69,7 @@
144 $Is{VOS}    = $^O eq 'vos';
145 $Is{QNX}    = $^O eq 'qnx';
146 $Is{AIX}    = $^O eq 'aix';
147+$Is{Haiku}  = $^O eq 'haiku';
148 
149 $Is{Unix}   = !grep { $_ } values %Is;
150 
151Index: lib/ExtUtils/MM_Haiku.pm
152===================================================================
153--- lib/ExtUtils/MM_Haiku.pm	(.../vendor/perl/current)	(revision 0)
154+++ lib/ExtUtils/MM_Haiku.pm	(.../trunk)	(revision 21)
155@@ -0,0 +1,62 @@
156+package ExtUtils::MM_Haiku;
157+
158+use strict;
159+
160+=head1 NAME
161+
162+ExtUtils::MM_Haiku - methods to override UN*X behaviour in ExtUtils::MakeMaker
163+
164+=head1 SYNOPSIS
165+
166+ use ExtUtils::MM_Haiku;	# Done internally by ExtUtils::MakeMaker if needed
167+
168+=head1 DESCRIPTION
169+
170+See ExtUtils::MM_Unix for a documentation of the methods provided
171+there. This package overrides the implementation of these methods, not
172+the semantics.
173+
174+=over 4
175+
176+=cut
177+
178+use ExtUtils::MakeMaker::Config;
179+use File::Spec;
180+require ExtUtils::MM_Any;
181+require ExtUtils::MM_Unix;
182+
183+use vars qw(@ISA $VERSION);
184+@ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
185+$VERSION = '6.42';
186+
187+
188+=item os_flavor
189+
190+Haiku is Haiku.
191+
192+=cut
193+
194+sub os_flavor {
195+    return('Haiku');
196+}
197+
198+=item init_linker
199+
200+libperl.a equivalent to be linked to dynamic extensions.
201+
202+=cut
203+
204+sub init_linker {
205+    my($self) = shift;
206+
207+    $self->{PERL_ARCHIVE} ||= 
208+      File::Spec->catdir('$(PERL_INC)',$Config{libperl});
209+    $self->{PERL_ARCHIVE_AFTER} ||= '';
210+    $self->{EXPORT_LIST}  ||= '';
211+}
212+
213+=back
214+
215+1;
216+__END__
217+
218Index: t/io/fs.t
219===================================================================
220--- t/io/fs.t	(.../vendor/perl/current)	(revision 21)
221+++ t/io/fs.t	(.../trunk)	(revision 21)
222@@ -275,7 +275,7 @@
223 		is( $atime, 500000001,          'atime' );
224 		is( $mtime, 500000000 + $delta, 'mtime' );
225 	    }
226-	    elsif ($^O eq 'beos') {
227+	    elsif ($^O eq 'beos' || $^O eq 'haiku') {
228             SKIP: {
229 		    skip "atime not updated", 1;
230 		}
231Index: hints/haiku.sh
232===================================================================
233--- hints/haiku.sh	(.../vendor/perl/current)	(revision 0)
234+++ hints/haiku.sh	(.../trunk)	(revision 21)
235@@ -0,0 +1,56 @@
236+# Haiku hints file
237+# $Id$
238+
239+prefix="/boot/home/config"
240+
241+libpth='/boot/home/config/lib /boot/common/lib /boot/system/lib'
242+usrinc='/boot/develop/headers/posix'
243+locinc='/boot/home/config/include /boot/common/include /boot/develop/headers'
244+
245+libc='/boot/system/lib/libroot.so'
246+libs=' '
247+
248+#d_bcmp='define'
249+#d_bcopy='define'
250+#d_bzero='define'
251+#d_index='define'
252+#d_htonl='define' # It exists, but much hackery would be required to support.
253+# a bunch of extra includes would have to be added, and it's only used at
254+# one place in the non-socket perl code.
255+
256+#these are all in libdll.a, which my version of nm doesn't know how to parse.
257+#if I can get it to both do that, and scan multiple library files, perhaps
258+#these can be gotten rid of.
259+
260+case "$usemymalloc" in
261+'') usemymalloc='n' ;;
262+esac
263+# Hopefully, Be's malloc knows better than perl's.
264+
265+d_link='undef'
266+dont_use_nlink='define'
267+# no posix (aka hard) links for us!
268+
269+d_syserrlst='undef'
270+# the array syserrlst[] is useless for the most part.
271+# large negative numbers really kind of suck in arrays.
272+
273+# Sockets didn't use to be real sockets but BONE changes this.
274+#if [ ! -f /boot/develop/headers/be/bone/sys/socket.h ]; then
275+#    d_socket='undef'
276+#    d_gethbyaddr='undef'
277+#    d_gethbyname='undef'
278+#    d_getsbyname='undef'
279+#
280+#	libs='-lnet'
281+#fi
282+
283+
284+cc="gcc"
285+ld='gcc'
286+
287+export PATH="$PATH:$PWD/haiku"
288+
289+case "$ldlibpthname" in
290+'') ldlibpthname=LIBRARY_PATH ;;
291+esac
292Index: ext/Errno/Errno_pm.PL
293===================================================================
294--- ext/Errno/Errno_pm.PL	(.../vendor/perl/current)	(revision 21)
295+++ ext/Errno/Errno_pm.PL	(.../trunk)	(revision 21)
296@@ -155,7 +155,7 @@
297 	# we might miss out on compiler-specific ones
298 	$file{"$ENV{GUSI}include:sys:errno.h"} = 1;
299 
300-    } elsif ($^O eq 'beos') {
301+    } elsif ($^O eq 'beos' || $^O eq 'haiku') {
302 	# hidden in a special place
303 	$file{'/boot/develop/headers/posix/errno.h'} = 1;
304 
305@@ -250,7 +250,8 @@
306 
307     close(CPPI);
308 
309-    unless ($^O eq 'MacOS' || $^O eq 'beos') {	# trust what we have / get later
310+    unless ($^O eq 'MacOS' || $^O eq 'beos' || $^O eq 'haiku') {
311+	# trust what we have / get later
312     # invoke CPP and read the output
313 
314 	if ($^O eq 'VMS') {
315@@ -293,12 +294,12 @@
316 
317     # Many of the E constants (including ENOENT, which is being
318     # used in the Perl test suite a lot), are available only as
319-    # enums in BeOS, so compiling and executing some code is about
320+    # enums in BeOS/Haiku, so compiling and executing some code is about
321     # only way to find out what the numeric Evalues are. In fact above, we
322     # didn't even bother to get the values of the ones that have numeric
323     # values, since we can get all of them here, anyway.
324 
325-    if ($^O eq 'beos') {
326+    if ($^O eq 'beos' || $^O eq 'haiku') {
327 	if (open(C, ">errno.c")) {
328 	    my @allerrs = keys %err;
329 	    print C <<EOF;
330Index: ext/Compress/Raw/Zlib/zlib-src/zutil.h
331===================================================================
332--- ext/Compress/Raw/Zlib/zlib-src/zutil.h	(.../vendor/perl/current)	(revision 21)
333+++ ext/Compress/Raw/Zlib/zlib-src/zutil.h	(.../trunk)	(revision 21)
334@@ -147,7 +147,7 @@
335 #  define OS_CODE  0x0f
336 #endif
337 
338-#if defined(_BEOS_) || defined(RISCOS)
339+#if (defined(_BEOS_) && !defined(__HAIKU__)) || defined(RISCOS)
340 #  define fdopen(fd,mode) NULL /* No fdopen() */
341 #endif
342 
343Index: ext/Time/HiRes/t/HiRes.t
344===================================================================
345--- ext/Time/HiRes/t/HiRes.t	(.../vendor/perl/current)	(revision 21)
346+++ ext/Time/HiRes/t/HiRes.t	(.../trunk)	(revision 21)
347@@ -337,7 +337,8 @@
348 	&& defined &Time::HiRes::getitimer
349 	&& has_symbol('ITIMER_VIRTUAL')
350 	&& $Config{sig_name} =~ m/\bVTALRM\b/
351-        && $^O !~ /^(nto)$/) { # nto: QNX 6 has the API but no implementation
352+	&& $^O !~ /^(nto)$/ # nto: QNX 6 has the API but no implementation
353+	&& $^O ne 'haiku') { # same for Haiku
354     for (18..19) {
355 	print "ok $_ # Skip: no virtual interval timers\n";
356     }
357Index: ext/Haiku/Makefile.PL
358===================================================================
359--- ext/Haiku/Makefile.PL	(.../vendor/perl/current)	(revision 0)
360+++ ext/Haiku/Makefile.PL	(.../trunk)	(revision 21)
361@@ -0,0 +1,20 @@
362+use 5.006;
363+use ExtUtils::MakeMaker;
364+
365+unless ($^O eq "haiku") {
366+    die "OS unsupported\n";
367+}
368+
369+#my @libs;
370+#push @libs, '-L/lib/w32api -lole32 -lversion' if $^O eq "cygwin";
371+
372+WriteMakefile(
373+    NAME          => 'Haiku',
374+    VERSION_FROM  => 'Haiku.pm',
375+#    LIBS          => \@libs,
376+    INSTALLDIRS   => ($] >= 5.008004 ? 'perl' : 'site'),
377+    NO_META       => 1,
378+
379+    AUTHOR        => 'Ingo Weinhold <ingo_weinhold@gmx.de>',
380+    ABSTRACT_FROM => 'Haiku.pm',
381+);
382Index: ext/Haiku/Haiku.xs
383===================================================================
384--- ext/Haiku/Haiku.xs	(.../vendor/perl/current)	(revision 0)
385+++ ext/Haiku/Haiku.xs	(.../trunk)	(revision 21)
386@@ -0,0 +1,141 @@
387+#define PERL_NO_GET_CONTEXT
388+#include "EXTERN.h"
389+#include "perl.h"
390+#include "XSUB.h"
391+
392+#include <stdarg.h>
393+
394+#include <OS.h>
395+
396+static void
397+haiku_do_debugger(const char* format,...)
398+{
399+    char buffer[1024];
400+    va_list args;
401+    va_start(args, format);
402+    my_vsnprintf(buffer, sizeof(buffer), format, args);
403+    va_end(args);
404+
405+    debugger(buffer);
406+}
407+
408+static void
409+haiku_do_debug_printf(pTHX_ register SV *sv,
410+    void (*printfFunc)(const char*,...))
411+{
412+    dVAR;
413+
414+    if (!sv)
415+	return;
416+    if (SvTYPE(sv) == SVt_IV && SvIOK(sv)) {
417+	assert(!SvGMAGICAL(sv));
418+	if (SvIsUV(sv))
419+	    (*printfFunc)("%"UVuf, (UV)SvUVX(sv));
420+	else
421+	    (*printfFunc)("%"IVdf, (IV)SvIVX(sv));
422+	return;
423+    }
424+    else {
425+	STRLEN len;
426+	/* Do this first to trigger any overloading.  */
427+	const char *tmps = SvPV_const(sv, len);
428+	U8 *tmpbuf = NULL;
429+#undef strnlen
430+if (strnlen(tmps, len) != len)
431+haiku_do_debugger("haiku_do_debug_printf(): len: %lu, acually: %lu",
432+len, strnlen(tmps, len));
433+
434+	if (!SvUTF8(sv)) {
435+	    /* We don't modify the original scalar.  */
436+	    tmpbuf = bytes_to_utf8((const U8*) tmps, &len);
437+	    tmps = (char *) tmpbuf;
438+	}
439+
440+	if (len)
441+	    (*printfFunc)("%.*s", (int)len, tmps);
442+	Safefree(tmpbuf);
443+    }
444+}
445+
446+XS(haiku_debug_printf)
447+{
448+    dVAR;
449+    dXSARGS;
450+    dORIGMARK;
451+    SV *sv;
452+
453+    if (items < 1)
454+	Perl_croak(aTHX_ "usage: Haiku::debug_printf($format,...)");
455+
456+    sv = newSV(0);
457+
458+    if (SvTAINTED(MARK[1]))
459+	TAINT_PROPER("debug_printf");
460+    do_sprintf(sv, SP - MARK, MARK + 1);
461+
462+    haiku_do_debug_printf(sv, &debug_printf);
463+
464+    SvREFCNT_dec(sv);
465+    SP = ORIGMARK;
466+    PUSHs(&PL_sv_yes);
467+}
468+
469+XS(haiku_ktrace_printf)
470+{
471+    dVAR;
472+    dXSARGS;
473+    dORIGMARK;
474+    SV *sv;
475+
476+    if (items < 1)
477+	Perl_croak(aTHX_ "usage: Haiku::debug_printf($format,...)");
478+
479+    sv = newSV(0);
480+
481+    if (SvTAINTED(MARK[1]))
482+	TAINT_PROPER("ktrace_printf");
483+    do_sprintf(sv, SP - MARK, MARK + 1);
484+
485+    haiku_do_debug_printf(sv, &ktrace_printf);
486+
487+    SvREFCNT_dec(sv);
488+    SP = ORIGMARK;
489+    PUSHs(&PL_sv_yes);
490+}
491+
492+XS(haiku_debugger)
493+{
494+    dVAR;
495+    dXSARGS;
496+    dORIGMARK;
497+    SV *sv;
498+
499+    if (items < 1)
500+	Perl_croak(aTHX_ "usage: Haiku::debugger($format,...)");
501+
502+    sv = newSV(0);
503+
504+    if (SvTAINTED(MARK[1]))
505+	TAINT_PROPER("debugger");
506+    do_sprintf(sv, SP - MARK, MARK + 1);
507+
508+    haiku_do_debug_printf(sv, &haiku_do_debugger);
509+
510+    SvREFCNT_dec(sv);
511+    SP = ORIGMARK;
512+    PUSHs(&PL_sv_yes);
513+}
514+
515+MODULE = Haiku            PACKAGE = Haiku
516+
517+PROTOTYPES: DISABLE
518+
519+BOOT:
520+{
521+    char *file = __FILE__;
522+
523+    newXS("Haiku::debug_printf", haiku_debug_printf, file);
524+    newXS("Haiku::ktrace_printf", haiku_ktrace_printf, file);
525+    newXS("Haiku::debugger", haiku_debugger, file);
526+    XSRETURN_YES;
527+}
528Index: ext/Haiku/Haiku.pm
529===================================================================
530--- ext/Haiku/Haiku.pm	(.../vendor/perl/current)	(revision 0)
531+++ ext/Haiku/Haiku.pm	(.../trunk)	(revision 21)
532@@ -0,0 +1,54 @@
533+package Haiku;
534+
535+BEGIN {
536+    use strict;
537+    use vars qw|$VERSION $XS_VERSION @ISA @EXPORT @EXPORT_OK|;
538+
539+    require Exporter;
540+    require DynaLoader;
541+
542+    @ISA = qw|Exporter DynaLoader|;
543+    $VERSION = '0.34';
544+    $XS_VERSION = $VERSION;
545+    $VERSION = eval $VERSION;
546+
547+    @EXPORT = qw(
548+    );
549+    @EXPORT_OK = qw(
550+    );
551+}
552+
553+bootstrap Haiku;
554+
555+1;
556+
557+__END__
558+
559+=head1 NAME
560+
561+Haiku - Interfaces to some Haiku API Functions
562+
563+=head1 DESCRIPTION
564+
565+The Haiku module contains functions to access Haiku APIs.
566+
567+=head2 Alphabetical Listing of Haiku Functions
568+
569+=over
570+
571+=item Haiku::debug_printf(FORMAT,...)
572+
573+Similar to printf, but prints to system debug output.
574+
575+=item Haiku::debugger(FORMAT,...)
576+
577+Drops the program into the debugger. The printf like arguments define the
578+debugger message.
579+
580+=item Haiku::ktrace_printf(FORMAT,...)
581+
582+Similar to printf, but prints to a kernel tracing entry.
583+
584+=back
585+
586+=cut
587Index: Configure
588===================================================================
589--- Configure	(.../vendor/perl/current)	(revision 21)
590+++ Configure	(.../trunk)	(revision 21)
591@@ -7864,6 +7864,7 @@
592     case "$lddlflags" in
593     '') case "$osname" in
594   			beos) dflt='-nostart' ;;
595+  			haiku) dflt='-nostart' ;;
596 			hpux) dflt='-b';
597 			      case "$gccversion" in
598 			      '') dflt="$dflt +vnocompatwarnings" ;;
599@@ -7946,7 +7947,7 @@
600 	;;
601 *)	case "$useshrplib" in
602 	'')	case "$osname" in
603-		svr4*|nonstopux|dgux|dynixptx|esix|powerux|beos|cygwin*)
604+		svr4*|nonstopux|dgux|dynixptx|esix|powerux|beos|cygwin*|haiku)
605 			dflt=y
606 			also='Building a shared libperl is required for dynamic loading to work on your system.'
607 			;;
608@@ -8109,6 +8110,9 @@
609 	beos)
610 		# beos doesn't like the default, either.
611 		;;
612+	haiku)
613+		# Haiku doesn't like the default, either.
614+		;;
615 	hpux*)
616 		# hpux doesn't like the default, either.
617 		tmp_shrpenv="env LDOPTS=\"+s +b${shrpdir}\""
618