ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Where does one find API definitions?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where does one find API definitions?

    Hi,

    Where can I find the field definitions for C APIs?

    For example - stat();
    The IBM knowledge centre tells you about the API and the fields but not how to specifically define them; https://www.ibm.com/support/knowledg.../apis/stat.htm.

    I am confused about st_objtype (when using the ifsio_h copybook) as it's defined differently across 3 examples;
    http://www.scottklement.com/rpg/copy...io_h.rpgle.txt has it defined as 11a
    https://www.scottklement.com/rpg/ifs_ebook/stat.html has it defined as 12a
    https://www.fieldexit.com/forum/display?threadid=446 has it defined as 10a

    There must be something somewhere I can check to see exactly how the fields are defined?

    I often wonder this cause I end up having to google examples to get definitions for APIs rather than being able to find them on the IBM knowledge centre.

    Basically this question spawned over the fact st_objtype has a null on the end when defined as 11a;
    Code:
    EVAL stats.st_objtype : x 11
    5CC4C9D9 40404040 40400000 04E404E4   - *DIR      .
    I am guessing if it was defined as 10 it wouldn't but, as it's a data structure, I guess defining it short would shift the data across or something causing issues elsewhere...

    Cheers,
    Ryan

  • #2
    Ugh just saw the hex isn't right, correction below as I can't edit it.

    Code:
     
     EVAL stats.st_objtype : x 11 5CC4C9D9 40404040 40400   - *DIR      .

    Comment


    • #3
      If you want to check any of these then using the IBM versions are probably the safest. Maybe not the preferred coding style as they are riddled with compiler directives to deal with different OS releases but ...

      IBM provide RPG translations of most C API prototypes in the QRPGLESRC file in QSYSINC. The actual definition given in this case is 11A.

      But to answer your question directly. In the first example of Scott's that you list it is correctly defined and if you look you will see it is followed by a single character reserved field. In the second of his examples it is defined as 12A but the reserved field is omitted. So the result is the same particularly when comparing the field as none of the comparison values will exceed 10 characters. The example from feieldexit is technically incorrect but obviously relies on the 10 character system names convention. However, he has enlarged the reserved area to two characters so the alignment is maintained.

      In other words it doesn't matter as long as you provide the necessary padding to ensure that the structure is aligned correctly.

      Hope this helps.

      P.S. If in doubt trust Scott.

      Comment


      • #4
        In the C definitions, st_objtype is defined as qp0l_objtype, which in turn is defined as char 11. There is a 1 character reserved field that comes after it.

        Its possible that the C environment uses that 11th byte as the null terminator? I don't really know, but that's what it sounds like you've discovered. In that case, coding it as char(10) in RPG would make sense, provided that you had a reserved field after it.

        If you don't know for sure that the last byte should always have a x'00' in it, then the "safest" thing would be to match what IBM has, and keep using char(11).

        Not sure why I'd have char(12) though... that's a bug. It probably didn't matter because the field that came after it happens to be a reserved field that's unused, but... it shouldn't be 12.

        Comment


        • #5
          Thanks both for the insight here, reserved fields make sense now - I wondered what they were reserved for but I guess it's just a way of ensuring you get the results you want without messing up the alignment of the DS.

          QSYSINC is very helpful, that's what I was looking for.

          Ok so if it's null terminated I can code around it, taking into account it might not be sometimes or just use your (Scott) resolution of;
          Code:
          if %bitand( myStat.st_mode : x'4000') = x'4000';
          From here;
          Having an issue with the STAT api and it reporting back "No such path or directory." I am reading a directory and running STAT against each link that is found. I am using stat to determine if the link is a Folder or Stream file. If it is a folder I proceed to read through that. However when i


          To determine if it's a DIR or not.

          Cheers again for the help,
          Ryan

          Comment


          • #6
            Checking the mode is the way its done on Unix systems (there is no 'st_objtype' there). It also will work for anything that works like a directory, such as *DIR, *DDIR, *FILE, *FLR, etc... all different object types, but all work llike directories, can have their files read with opendir/readdir/etc, so the mode is often a better choice. But, it depends on what you're doing.... for example, if the goal is to print the object type for the user's benefit, st_objtype would be better.

            Comment


            • #7
              Right-o, the program is creating an archive directory name (that should exist) then doing a stat() to make sure it exists, if it's not a directory it errors - the error I found is due to the null in the field.

              So using the mode would work fine, thanks again.

              Comment

              Working...
              X