Can I use the access API to verify that an IFS Path exists as opposed to verifying a path and file exists? If not should I use the CHDIR command instead or maybe use the open source CHKLNK command? Thanks.
Thank you! I will do that. I'm assuming that if the path is found that I would need to execute a closedir then. My program uses the open, write, close and unlink API's to write a file to the IFS if the path is valid.
The other option would be stat() - which would avoid the close but may have a higher overhead.
From googling around, there appear to be some versions of access() that will work with directories but it is unclear to me which is what! Scott probably knows - he is far more knowledgeable about all things C than I am.
access() should work fine. Not sure that I understand what is being asked... what is the difference between a "path exists" vs "path and file exists"?
If its important to determine if the object is a directory (vs. a file) then I would use stat() and check the IS_DIR bit of the mode. (Which will cover all of the "directory-like" objects, such as *DIR, *DDIR, *FLR and *FILE)
I wouldn't use anything that creates an object like mkdir or open, or anything that changes your current state like chdir unless you actually want to create an object or change your current state, respectively. These add overhead, its just a waste if you don't need it. Plus... why? Checking existence with access() is actually easier to code -- and stat() is also relatively easy and much more powerful. Why use something not designed for the purpose?
Also, your RPG code that calls stat could be much simpler, unless you need to run it on V3R2/V3R7? Why aren't you taking advantage of options(*string)?
The code I put in my post isn't my code. It was code I googled before I wrote my code. I'm developing a program that will be passed an IFS Path, document type (JSON, XML, TXT or PDF), file name prefix and a data string. I want to validate the path first, the file name will be unique as a sequence number is generated for each file from a data area. I coded jonboy's first suggestion because I have to code to V7.2 even thought the development box is on V7.4 as I have to wait until over 60 production LPAR's are upgraded or I would have used a SQL Table for this. A will replace opendir() and closedir() with access() then. Thank you! But I have another issue now. When I go to write an XML string to the IFS, two characters are added to the front of the string causing 2 characters what appears to be a tab and a ' '. So something must be wrong with either my open() or write() statement. Could you take a look please? Thanks!