This macro expands to the name of the current input file, in the form of a C string constant. Their names all start with double underscores. Older compilers may not provide all of them. The permissions might have said "it is OK" but the file could have been removed, or changed to read-only since then. The standard predefined macros are specified by the relevant language standards, so they are available with all compilers that implement those standards. The permissions on the file, or one of the directories leading to it, might change between the time when you check the file permissions and the time when you actually try to open the file. So update the Workbooks.Open FileName:'R:DevelopmentCopy of Product Information. However, any LBYL strategy also suffers from TOCTOU - Time of Check, Time of Use - issues. What I would like to do is only open the file in Read Only mode. You could use access(filename, W_OK), and it will usually give you the correct answer - unless your program is running with effective UID different from real UID. Useful macro 2: The macro that shortens a redundant expression. Also, there could be ACLs that mean you can access the file for writing even if the permissions reported by stat() indicate that you can't (or vice versa). You can use stat(), but it is modestly tricky to determine the permissions correctly. This is a case where it is easiest and most reliable to try opening the file for writing, and react appropriately if the open fails ('Easier to Ask for Forgiveness than for Permission') than to try and determine whether it will fail first ('Look Before You Leap') - see LBYL vs EAFP. 141 In the sake of debugging purposes, can I get the line number in C /C++ compilers (standard way or specific ways for certain compilers) e.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |