× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.






Thanks Scott and Matt!  The code snip and website really helps bring the
point.  I didn't know about the *NULL use.  It will help me in other IFS
API's.

*** Scott wrote:
Hi Craig,

> How do you check for getcwd() errors (get current working directory IFS
> procedure)?  In the below code, variable errno is not always the same
even
> though it is a valid current working directory.  For example, if working
> directory from user profile does not exist, the root directory is used
and
> a different errno is returned Both are valid working directories but
> errno is nonzero and is different based on root or not.  For my working
> directory, errno = 1636341396 and for root = 1627406400.  Is it always
> these two error numbers for valid current working directories?

The getcwd() function does not return a pointer to errno, it returns a
pointer to a string representing the current directory (or *NULL upon
error)

What YOUR CODE is doing, however, is populating errno with the first 4
bytes of the returned directory :)

So, if the getcwd() function is returning /home/klemscot then the first
4 bytes are:

      / = x'61'
      h = x'88'
      o = x'96'
      m = x'94'

If you take x'61889694' and convert it to decimal you get 1636341396

> How would I check for any error if the errno is always nonzero?

The way that these functions work (all of the Unix-type APIs, not just
this one) is that they return some sort of value that indicates that an
error has occurred.   It doesn't tell you which error has occurred, just
that some error has occurred.

Usually, for functions that return an integer, they'll return -1 to
indicate an error. And for functions like getcwd() that return a pointer,
they'll return *NULL to indicate an error.

The purpose of errno is to find out WHICH error has occurred once you
already know that the function returned an error.

> Any ideas?

Here, I'll whip up a quick sample of this API:

     H DFTACTGRP(*NO) BNDDIR('QC2LE')

     D getcwd          pr              *   extproc('getcwd')
     D                                 *   value
     D   size                        10U 0 value

     D geterrno        pr              *   extproc('__errno')
     D p_errno         s               *
     D errno           s             10I 0 based(p_errno)

     D buf             s            257A
     D CurDir          s            256A   varying
     D msg             s             51A

      /free

           if (getcwd(%addr(buf): %size(buf)) = *NULL);
               p_errno = geterrno();
               msg = 'getcwd() failed with errno ' + %editc(errno:'Z');
           else;
               CurDir = %str(%addr(buf));
               msg = CurDir;
           endif;

           dsply ' '  ' '  msg;
           *inlr = *on;

      /end-free


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.