<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[esxDOS BBS — POSIX API Experimentation - ls.c]]></title>
		<link>https://board.esxdos.org/viewtopic.php?id=256</link>
		<atom:link href="https://board.esxdos.org/extern.php?action=feed&amp;tid=256&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in POSIX API Experimentation - ls.c.]]></description>
		<lastBuildDate>Tue, 12 Jun 2018 13:39:56 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: POSIX API Experimentation - ls.c]]></title>
			<link>https://board.esxdos.org/viewtopic.php?pid=897#p897</link>
			<description><![CDATA[<p>I think you&#039;ve probably already solved this but just by coincidence I wrote a similar test program &quot;dir.c&quot; that is now in the zx next examples directory:</p><p><a href="https://github.com/z88dk/z88dk/tree/master/libsrc/_DEVELOPMENT/EXAMPLES/zxn/esxdos">https://github.com/z88dk/z88dk/tree/mas … zxn/esxdos</a></p><p>It&#039;s not compiled as a dot command but as an sna snapshot that is a fast way to run stuff on the next.</p><div class="codebox"><pre><code>// zcc +zxn -v -clib=sdcc_iy -SO3 --max-allocs-per-node200000 dir.c -o dir -subtype=sna -Cz&quot;--clean&quot; -create-app
// zcc +zxn -v -clib=new dir.c -o dir -subtype=sna -Cz&quot;--clean&quot; -create-app

#include &lt;stdio.h&gt;
#include &lt;arch/zxn/esxdos.h&gt;
#include &lt;time.h&gt;
#include &lt;errno.h&gt;

#pragma printf = &quot;%B %s %lu %u&quot;

struct esx_dirent_lfn file;
struct tm dt;

unsigned char cwd[ESX_PATHNAME_MAX+1];

void main(void)
{
   unsigned char dirh;
   
   esx_f_getcwd(cwd);
   printf(&quot;CWD: %s\n&quot;, cwd);
   
   dirh = esx_f_opendir_ex(cwd, ESX_DIR_USE_LFN);
   
   while (esx_f_readdir(dirh, &amp;file) &amp;&amp; (errno == 0))
   {
      struct esx_dirent_slice *slice;

      slice = esx_slice_dirent(&amp;file);
      tm_from_dostm(&amp;dt, &amp;slice-&gt;time);
      
      printf(&quot;\n&quot;);
      
      printf(&quot;attr: %08B\n&quot;, file.attr);
      printf(&quot;name: %s\n&quot;, file.name);
      printf(&quot;size: %lu\n&quot;, slice-&gt;size);
      printf(&quot;date: %02u/%02u/%u\n&quot;, dt.tm_mday, dt.tm_mon, dt.tm_year + 1900);
      printf(&quot;time: %02u:%02u:%02u\n&quot;, dt.tm_hour, dt.tm_min, dt.tm_sec);
      
      printf(&quot;\n&quot;);
   }
}</code></pre></div><p>This is using the <a href="https://github.com/z88dk/z88dk/blob/master/include/_DEVELOPMENT/sdcc/arch/zxn/esxdos.h#L22">nextos-esxdos api</a> (everything is prefixed with &quot;esx_*&quot; instead of &quot;esxdos_*&quot;) but the esxdos subset should work on esxdos too.&nbsp; I will be bringing up the proper esxdos interface to the same level as soon as I can but in the meantime, as experiment, this nextos-esx interface is also available to the +zx target through arch/zx/esxdos.h.</p><p>The above is using lfn but this can be changed to 8.3 by using &quot;esx_opendir()&quot; instead of &quot;esx_opendir_ex()&quot;.</p><p>The structure for directory entries varies a little depending on whether you ask for plus3 headers and/or lfn (nextos only) in the opendir call.&nbsp; Normally you wouldn&#039;t want either option in esxdos so you would end up getting a &quot;struct esx_dirent&quot; that represents a directory entry and would be filled in by readdir().&nbsp; All these directory entries have a variable-length zero terminated filename embedded in them so there is a function &quot;esx_slice_dirent()&quot; that will skip past the variable length part can give you access to the file size and datetime that follow.</p>]]></description>
			<author><![CDATA[null@example.com (Alcoholics Anonymous)]]></author>
			<pubDate>Tue, 12 Jun 2018 13:39:56 +0000</pubDate>
			<guid>https://board.esxdos.org/viewtopic.php?pid=897#p897</guid>
		</item>
		<item>
			<title><![CDATA[POSIX API Experimentation - ls.c]]></title>
			<link>https://board.esxdos.org/viewtopic.php?pid=859#p859</link>
			<description><![CDATA[<p>This may be a question for the z88dk forum, I&#039;m not sure, but I thought I&#039;d try here first - please excuse me if I am in the wrong place...</p><p>I wanted to experiment with the POSIX API, so have been trying to reduce each use case to as simple an example as I could, to make them easier to explain to others....</p><p>In that regard some of the GNU tools seemed obvious, and thought I would *TRY* and do some tutorials, simple goals with with excessive commenting, to help other users get started with the filesystem access from z88dk.</p><p>So, far from perfect here is my first very-most-simple port of ls.c, the objective is to purely get me a list of files in the current folder... <a href="https://gist.github.com/Xalior/11f4f1299e56bfce1012c9027f850dfd">https://gist.github.com/Xalior/11f4f129 … 027f850dfd</a></p><p>Enclosed inline for ease, but github has syntax highlights, etc.<br /></p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;input.h&gt;
#include &lt;arch/zx.h&gt;
#include &lt;arch/zx/esxdos.h&gt;

void main() {
    unsigned char *cwd[128];
    char *curr_dir = NULL;
    unsigned char *dp = NULL;
    struct esxdos_dirent *dptr = NULL;
    unsigned int count = 0;

    // Get the value of environment variable PWD
    esxdos_f_getcwd(cwd);

    if(NULL == cwd)
    {
        printf(&quot;\n ERROR : Could not get the working directory\n&quot;);
        return -1;
    } else {
        printf(&quot; CWD   : %s\n&quot;, cwd);
    }

    // Open the current directory
    dp = esxdos_f_opendir(cwd);
    if(NULL == dp)
    {
        printf(&quot;\n ERROR : Could not open the working directory.\n&quot;);
        return -1;
    } else {
        printf(&quot; DONE  : Opened the working directory. (%d)\n&quot;, dp);
    }

    // Go through and display all the names (files or folders)
    // Contained in the directory.
    for(count = 0; NULL != (esxdos_f_readdir(dp, dptr)); count++)
    {
        printf(&quot;Entry #%u: %u\n&quot;,count, *dptr-&gt;dir);
        printf(&quot;Str@1 #%u: %s\n&quot;,count, *dptr+sizeof(unsigned char));
        printf(&quot;-----\n&quot;);
    }
    esxdos_f_close(dp);
    return 0;
}</code></pre></div><p>Compiled with:<br /></p><div class="codebox"><pre><code>zcc +zx -vn -startup=30 -clib=new LS.c -o LS -subtype=dot -create-app</code></pre></div><p>When I run the code I seem to end in an almost infinite loop with no filenames output.</p><p>The &quot;logic&quot; of &#039;*dptr+sizeof(unsigned char)&#039; is derived from reading the structure itself in the ESXDOS header code, to try and figure out the shape...</p><p>Can someone please give me a shove in the right direction? Hopefully that will be enough to unstick me...</p><p>-Dx</p><p>Edited:&nbsp; to fix a typo, and clarify source of sizeof logics.</p>]]></description>
			<author><![CDATA[null@example.com (Xalior)]]></author>
			<pubDate>Mon, 28 May 2018 19:10:01 +0000</pubDate>
			<guid>https://board.esxdos.org/viewtopic.php?pid=859#p859</guid>
		</item>
	</channel>
</rss>
