<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>ALLEGRO_NATIVE_PATH_SEP+PHYSFS bug on Windows?</title>
		<link>http://www.allegro.cc/forums/view/617884</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 14 Jul 2019 01:26:50 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve just spent hours hunting for a bug and was finally able to isolate the code causing it. It seems that using ALLEGRO_NATIVE_PATH_SEP with PHYFS won&#39;t work on Windows. Consider the following code:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#include &lt;stdint.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;string.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  4</span><span class="p">#include &lt;allegro5/allegro_image.h&gt;</span>
<span class="number">  5</span><span class="p">#include &lt;allegro5/allegro_physfs.h&gt;</span>
<span class="number">  6</span>
<span class="number">  7</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 10</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    <a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span>ALLEGRO_WINDOWED<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">800</span>, <span class="n">600</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>    
<div class="highlight"><span class="number"> 17</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>PHYSFS_init<span class="k2">(</span>argv<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>   </div><div class="highlight"><span class="number"> 18</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>PHYSFS_mount<span class="k2">(</span><span class="s">"my-file.zip"</span>, NULL, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>   </div><div class="highlight"><span class="number"> 19</span>    <a href="http://www.allegro.cc/manual/al_set_physfs_file_interface"><span class="a">al_set_physfs_file_interface</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>   </div><span class="number"> 20</span>
<span class="number"> 21</span>    ALLEGRO_PATH <span class="k3">*</span>path <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a><span class="k2">(</span><span class="s">"data/"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>    <a href="http://www.allegro.cc/manual/al_set_path_filename"><span class="a">al_set_path_filename</span></a><span class="k2">(</span>path, <span class="s">"image.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>path, ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>path, ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>    <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>bmp, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>    <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>    <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">5</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span><span class="k2">}</span>
</div></div><p>

I&#39;m working on Linux and the code works whether you use PHYSFS (load the file <i>data/image.png</i> from the <i>my-file.zip</i> archive) or if you comment the marked lines and don&#39;t use PHYSFS (load <i>image.png</i> from the <i>data/</i> folder). Both work on Linux.</p><p>However, when building for Windows, the PHYSFS version won&#39;t work. The code will work fine if you don&#39;t use PHYSFS, though.</p><p>I tested this with <i>wine</i> and with a Windows XP VM, both with the same results.</p><p>Of course, you can use &#39;/&#39; instead of ALLEGRO_NATIVE_PATH_SEP and the problem disappears but it&#39;s still annoying trying to use ALLEGRO_NATIVE_PATH_SEP and figure out that it&#39;s the cause of your problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Fri, 12 Jul 2019 11:15:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Personally I would be for deprecating ALLEGRO_NATIVE_PATH_SEP. There is no reason to ever use it (Windows filesystem functions all understand / in place of \). And when displaying a path to a user I doubt they really care if you show them C:\\GAMES or <a>C://GAMES</a>.</p><p>Having said that, I have not used a Windows in a very long time, so maybe there is cases where \ needs to be used?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 12 Jul 2019 19:00:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are cases such as FOR loop variables being wrongly set in the windows command prompt when using &quot;/&quot; instead of &quot;\&quot;. Some old command prompt commands also use &quot;/&quot; for named arguments and might potentially cause unexpected results.</p><p>In my experience it will generally not cause any issues and I use &quot;/&quot; all the time, except for batch scripts.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (l j)</author>
		<pubDate>Fri, 12 Jul 2019 20:05:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617884/1042827#target">Elias</a> said:</div><div class="quote"><p>so maybe there is cases where \ needs to be used?</p></div></div><p>
Off the top of my head, I can see two kinds of cases:<br />- As output : In order to show a path to a user, for example in order to display &quot;You are editing C:\Data\Users\(...)\Image4.png&quot;<br />- As input : If you need to parse a path produced as a string by a system command or third-party library. Or if you want to parse argv[0]</p><p>In the second case, it&#39;s actually better to expect both separators when you&#39;re on Windows OS. I remember  slashes when running a program through sh or gdb, and antislashes otherwise.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 12 Jul 2019 20:32:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Using &#39;/&#39; seems like the way to go as solving the issue might be more complicated than it seems. Any solution in Windows might fix the issue in some places but break things somewhere else.</p><p>That said, could this be a PHYSFS issue and not Allegro&#39;s? I mean, if you use <i>data\image.png</i> (as per the output of the <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="k2">)</span></span> in line 23) with <span class="source-code"><a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="k2">)</span></span>, it will work fine if you&#39;re not using PHYSFS but fail with PHYSFS. A quick look at the <a href="http://icculus.org/physfs/docs/html/physfs_8h.html#a5e38a425bb0b44c09ec25b105f770c63">PHYSFS documentation</a> seems to indicate that PHYSFS usually expects its filenames to be written in platform-independent notation. So, that might likely be the cause of the problem.</p><p>[EDIT:] Indeed, the following minimal PHYSFS code fails when using &#39;\\&#39; as path separator:</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;stdio.h&gt;</span>
<span class="p">#include &lt;assert.h&gt;</span>
<span class="p">#include &lt;physfs.h&gt;</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span> <span class="k2">{</span>
    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>PHYSFS_init<span class="k2">(</span>argv<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>PHYSFS_mount<span class="k2">(</span><span class="s">"my-file.zip"</span>, NULL, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
    PHYSFS_File <span class="k3">*</span>file <span class="k3">=</span> PHYSFS_openRead<span class="k2">(</span><span class="s">"data\\image.png"</span><span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Fri, 12 Jul 2019 20:39:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Uhm, I might be hallucinating, but PHYSFS expects /, just like CMake, and lots of other things.</p><p>To expand, physfs is a virtual file system. Its conventions are to use forward / slash. It&#39;s totally arbitrary, but you have to convert windows filenames to use forward slashes yourself if they are in the DOS format.</p><p>EDIT<br />And actually, I use ALLEGRO_NATIVE_PATH_SEP myself, but it&#39;s easily replaced by a couple ifdefs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 12 Jul 2019 23:57:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I was trying to say that indeed, the error in my code was caused by using the Windows ALLEGRO_NATIVE_PATH_SEP (&#39;\\&#39;) with PHYSFS. Knowing the PHYSFS convention makes it obvious that if you&#39;re going to use PHYSFS you have to use forward slashes but it&#39;s not something that&#39;s immediately obvious if you&#39;re not aware of the PHYSFS convention.</p><p>I guess it&#39;s not really an Allegro bug, nor a PHYSFS bug. Just something that you must be aware of when using both together.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Sat, 13 Jul 2019 02:36:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, just something to be aware of. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>And CMake-GUI, doesn&#39;t tell you anything is wrong with your paths until you hit configure. :/</p><p>Also, I have a <span class="source-code">SanitizePath<span class="k2">(</span><span class="k2">)</span></span> function for just this purpose. Turns everything into a forward slash path.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 13 Jul 2019 03:05:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So: PhysFS uses forward slashes only? The way to deal with that seems to be to make a macro or function that returns the correct path separator, based on ALLEGRO_NATIVE_PATH_SEP and whether you are using PhysFS or not.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 13 Jul 2019 03:33:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s no OS that doesn&#39;t understand forward slashes, at least when it comes to system calls, everything should just automatically be converted to / &lt;//&gt;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 14 Jul 2019 01:26:50 +0000</pubDate>
	</item>
</rss>
