A tail-recursive version written in OCaml that should not reach stack limits easily. (Not an expert in OCaml, so this might be stupid. But I tried it with 10000 iterations, and it worked without any issues.)
<span style="font-weight:bold;color:#a71d5d;">let </span><span style="color:#0086b3;">gnu </span><span style="font-weight:bold;color:#a71d5d;">=
</span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">let rec </span><span style="font-weight:bold;color:#795da3;">aux </span><span style="color:#323232;">s </span><span style="font-weight:bold;color:#a71d5d;">= function
</span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#0086b3;">0 </span><span style="color:#323232;">-> s
</span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#323232;">n -> aux (s</span><span style="font-weight:bold;color:#a71d5d;">^</span><span style="color:#183691;">" is Not Unix"</span><span style="color:#323232;">) (n</span><span style="color:#0086b3;">-1</span><span style="color:#323232;">)
</span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;"> aux </span><span style="color:#183691;">"GNU"</span><span style="color:#323232;">;;
</span>