1 /* { dg-do compile } */
2 
3 typedef __SIZE_TYPE__ size_t;
4 typedef unsigned long UV;
5 typedef size_t STRLEN;
6 typedef struct sv SV;
7 typedef struct magic MAGIC;
8 typedef struct xpv XPV;
9 typedef unsigned char U8;
10 typedef int I32;
11 typedef unsigned int U32;
12 struct sv {
13     void* sv_any;
14     U32 sv_flags;
15 };
16 struct xpv {
17     char * xpv_pv;
18     STRLEN xpv_cur;
19 };
20 struct magic {
21     char* mg_ptr;
22 };
23 extern const unsigned char PL_utf8skip[];
24 char *Perl_sv_2pv_flags (STRLEN *);
25 void Perl_utf8n_to_uvuni (U8 *);
26 void Perl_sv_magic (SV *);
Perl_sv_pos_b2u(register SV * sv,I32 * offsetp,MAGIC * mg)27 void Perl_sv_pos_b2u( register SV* sv, I32* offsetp, MAGIC *mg)
28 {
29   U8* s;
30   STRLEN len;
31   s = (U8*)(((sv)->sv_flags & (0x00040000)) == 0x00040000
32 	    ? ((len = ((XPV*) (sv)->sv_any)->xpv_cur), ((XPV*) (sv)->sv_any)->xpv_pv)
33 	    : Perl_sv_2pv_flags(&len));
34   if ((I32)len < *offsetp)
35     ;
36   else
37     {
38       STRLEN *cache = ((void *)0);
39       if (((sv)->sv_flags & (0x00002000|0x00004000|0x00008000))
40 	  && !((sv)->sv_flags & 0x00800000))
41 	{
42 	  if (mg && mg->mg_ptr)
43 	    {
44 	      cache = (STRLEN *) mg->mg_ptr;
45 	      STRLEN forw = *offsetp;
46 	      STRLEN backw = cache[1] - *offsetp;
47 	      if (!(forw < 2 * backw))
48 		{
49 		  U8 *p = s + cache[1];
50 		  STRLEN ubackw = 0;
51 		  cache[1] -= backw;
52 		  while (backw--)
53 		    {
54 		      p--;
55 		      while ((((U8)*p) >= 0x80 && (((U8)*p) <= 0xbf)))
56 			{
57 			  p--;
58 			  backw--;
59 			}
60 		      ubackw++;
61 		    }
62 		  cache[0] -= ubackw;
63 		  *offsetp = cache[0];
64 		  cache[2] = 0;
65 		  cache[3] = 0;
66 		  return;
67 		}
68 	    }
69 	  if (!(((UV)(*s)) < 0x80))
70 	    Perl_utf8n_to_uvuni(s);
71 	}
72       if (!((sv)->sv_flags & 0x00800000))
73 	{
74 	  if (!mg)
75 	    Perl_sv_magic(sv);
76 	  cache[0] = len;
77 	  cache[1] = *offsetp;
78 	}
79       *offsetp = len;
80     }
81 }
82