=provides

SvPV_nolen
sv_2pv_nolen
SvPVbyte
sv_2pvbyte
sv_pvn
sv_pvn_force

=implementation

#ifndef SvPV_nolen

#if { NEED sv_2pv_nolen }

char *
sv_2pv_nolen(pTHX_ register SV *sv)
{   
  STRLEN n_a;
  return sv_2pv(sv, &n_a);
}

#endif

/* Hint: sv_2pv_nolen
 * Use the SvPV_nolen() macro instead of sv_2pv_nolen().
 */

/* SvPV_nolen depends on sv_2pv_nolen */
#define SvPV_nolen(sv) \
          ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
           ? SvPVX(sv) : sv_2pv_nolen(sv))

#endif

#ifdef SvPVbyte

/* SvPVbyte does not work in perl-5.6.1, borrowed version for 5.7.3 */
#if { VERSION < 5.7.0 }

#if { NEED sv_2pvbyte }

char *
sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
{   
  sv_utf8_downgrade(sv,0);
  return SvPV(sv,*lp);
}

#endif

/* Hint: sv_2pvbyte
 * Use the SvPVbyte() macro instead of sv_2pvbyte().
 */

#undef SvPVbyte

/* SvPVbyte depends on sv_2pvbyte */
#define SvPVbyte(sv, lp)                                                \
        ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)                \
         ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))

#endif

#else

#  define SvPVbyte          SvPV
#  define sv_2pvbyte        sv_2pv

#endif

/* sv_2pvbyte_nolen depends on sv_2pv_nolen */
__UNDEFINED__  sv_2pvbyte_nolen  sv_2pv_nolen

/* Hint: sv_pvn
 * Always use the SvPV() macro instead of sv_pvn().
 */
__UNDEFINED__  sv_pvn(sv, len)         SvPV(sv, len)

/* Hint: sv_pvn
 * Always use the SvPV_force() macro instead of sv_pvn_force().
 */
__UNDEFINED__  sv_pvn_force(sv, len)   SvPV_force(sv, len)

=xsinit

#define NEED_sv_2pv_nolen
#define NEED_sv_2pvbyte

=xsubs

IV
SvPVbyte(sv)
	SV *sv
	PREINIT:
		STRLEN len;
		const char *str;
	CODE:
		str = SvPVbyte(sv, len);
		RETVAL = strEQ(str, "mhx") ? len : -1;
	OUTPUT:
		RETVAL

IV
SvPV_nolen(sv)
	SV *sv
	PREINIT:
		const char *str;
	CODE:
		str = SvPV_nolen(sv);
		RETVAL = strEQ(str, "mhx") ? 3 : 0;
	OUTPUT:
		RETVAL

=tests plan => 2

ok(&Devel::PPPort::SvPVbyte("mhx"), 3);
ok(&Devel::PPPort::SvPVbyte("mhx"), 3);

