Creating reusable functions for unity CG shader?

How do I write a reusable function for unity CG shader? For example, I want to reuse a function across the passes:

   		float4 foo(float4 input){
   			//... some computation
   			return float4(0.0); //return some outputs
   		}
   		Pass {
   			CGPROGRAM
   			
   			//inside vert func
   			foo(someInput);
   			
   			ENDCG
   		}
   		Pass {
   			CGPROGRAM
   			
   			//inside vert func
   			foo(someInput);

   			ENDCG
   		}

Is it possible to achieve this with unity shader?

There is this, which is, I think, exactly what you were looking for…

    Shader "gamevial/randomshader" {
    	Properties {
    	 	_Splat0("Texture1 (R)", 2D) = "white" {}
        	
    	}
    	CGINCLUDE
///reusable stuff here
    			
    	ENDCG
Subshader{

I managed to do this by making an extra file (in the same folder as my .shader) called include.cginc and putting my function(foo) into that. (no extra pragmas or anything) Then after CGPROGRAM I added #include "include.cginc" and could happily call the function in both subshaders.

Now, this worked fine in windows, but in OSX I get this error in the console…

Shader error in 'Custom/IncludeTest': Bad characters in source file at line 0

So this might not be enough of a solution… There are no funny characters in the file, but I could look into this a bit further if it would help