<div dir="ltr"><br><br>On 21 March 2018 at 22:28, monty <<a href="mailto:monty2@programmer.net">monty2@programmer.net</a>> wrote:<br>><br>><br>> The SQ_FILE_*_ERROR codes can be mapped directly to an expanded file exception hierarchy, so an appropriate exception class can be thrown (and caught) on failure. #primitiveFailForOSError: can be used for this. Or it can be used with the raw errno/GetLastError() codes, and a sqFileErrorCodeFromSystemErrorCode()-based primitive can be used after to map it.<br>><br>> The exact values of the errno.h E* defines are technically unspecified,<br><br>By "unspecified" do you just mean that they are different between platforms.<br>What about embedding  errno.h  in the compiled VM and let the Image side browse and parse it, so the error mapping/condensing can be done Image-side?<br>I'm not sure of the difficulty to do this since I haven't done it before,<br>but maybe something like...  <a href="https://stackoverflow.com/questions/410980/include-a-text-file-in-a-c-program-as-a-char">https://stackoverflow.com/questions/410980/include-a-text-file-in-a-c-program-as-a-char</a><br><br><br>> We need some way in-image to portably, correctly distinguish certain failure modes (like a file not existing) from others. (Code in the current Squeak image just guesses.)<br><br>This should(?) portably provide the exact C label for a numeric error.  <div>The Image-side might need per-platform <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">mapping/condensing, but still may be nicer to do it there.</span><div><br></div><div>cheers -ben<br><br> <br>><br>> and the perror()/strerror_r() messages are locale-specific: <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_03">http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_03</a><br>><br>> I would like to hear more ideas.<br>><br>> > Sent: Wednesday, March 21, 2018 at 7:08 AM<br>> > From: "Alistair Grant" <<a href="mailto:akgrant0710@gmail.com">akgrant0710@gmail.com</a>><br>> > To: "Squeak Virtual Machine Development Discussion" <<a href="mailto:vm-dev@lists.squeakfoundation.org">vm-dev@lists.squeakfoundation.org</a>><br>> > Subject: Re: [Vm-dev] [PATCH] added FilePlugin error code lookup function<br>> ><br>> ><br>> > Hi Monty,<br>> ><br>> > The VM has a primitive failure that allows the OS error to be<br>> > returned: #primitiveFailForOSError:<br>> ><br>> > Why not simply return the OS error and allow the image to deal with it?<br>> ><br>> > Cheers,<br>> > Alistair<br>> ><br>> ><br>> ><br>> > On 21 March 2018 at 07:52, monty <<a href="mailto:monty2@programmer.net">monty2@programmer.net</a>> wrote:<br>> > ><br>> > ><br>> > > +enum {<br>> > > +       SQ_FILE_ERROR,<br>> > > +       SQ_FILE_PERMISSION_ERROR,<br>> > > +       SQ_FILE_ALREADY_EXISTS_ERROR,<br>> > > +       SQ_FILE_DOES_NOT_EXIST_ERROR,<br>> > > +       SQ_FILE_RESOURCE_LIMIT_ERROR,<br>> > > +       SQ_FILE_INVALID_OPERATION_ERROR,<br>> > > +       SQ_FILE_IO_ERROR,<br>> > > +       SQ_FILE_BAD_HANDLE_ERROR,<br>> > > +       SQ_FILE_IS_DIRECTORY_ERROR,<br>> > > +       SQ_FILE_IS_NOT_DIRECTORY_ERROR,<br>> > > +       SQ_FILE_INVALID_NAME_ERROR,<br>> > > +       SQ_FILE_IN_PROGRESS_ERROR<br>> > > +};<br>> > > <br>> > > +<br>> > > +sqInt<br>> > > +sqFileErrorCodeFromSystemErrorCode(sqInt errorCode)<br>> > > +{<br>> > > +       /* A switch statement is avoided, since some error codes, like EAGAIN/EWOULDBLOCK, can<br>> > > +          overlap, and EINTR is not propagated as SQ_FILE_IN_PROGRESS_ERROR, since it should be<br>> > > +          handled internally where possible and because only certain operations can be safely<br>> > > +          reattempted after failing with EINTR<br>> > > +       */<br>> > > +       if (errorCode == EACCES<br>> > > +               || errorCode == EPERM<br>> > > +               || errorCode == EROFS)<br>> > > +               return SQ_FILE_PERMISSION_ERROR;<br>> > > +       else if (errorCode == EEXIST)<br>> > > +               return SQ_FILE_ALREADY_EXISTS_ERROR;<br>> > > +       else if (errorCode == ENOENT<br>> > > +               || errorCode == ENODEV<br>> > > +               || errorCode == ENXIO)<br>> > > +               return SQ_FILE_DOES_NOT_EXIST_ERROR;<br>> > > +       else if (errorCode == EDQUOT<br>> > > +               || errorCode == EFBIG<br>> > > +               || errorCode == EMFILE<br>> > > +               || errorCode == EMLINK<br>> > > +               || errorCode == ENFILE<br>> > > +               || errorCode == ENOLCK<br><br></div></div></div>