Date: Thu, 22 Jan 1998 00:25:11 +0100 (GMT) From: "X DOT PONS AT UAB DOT ES" Subject: access() in DJGPP and TC/BC To: djgpp AT delorie DOT com Message-id: <01ISNOZW1WPE008ULX@cc.uab.es> Organization: Universitat Autonoma de Barcelona MIME-version: 1.0 Content-type: TEXT/PLAIN; CHARSET=ISO-8859-1 Precedence: bulk I have found a problem when porting TC/BC code to DJGPP because of the different meanings of the accesibility mode ("amode", the second parameter) of the access() function. * DJGPP defines these accessibility modes: R_OK (=0x02) Request if the file is readable. Since all files are readable under MS-DOS, this access mode always exists. W_OK (=0x04) Request if the file is writable. X_OK (=0x08) Request if the file is executable. F_OK (=0x01) Request if the file exists. D_OK (=0x10) Request if the file is really a directory. * TC/BC define these accessibility modes: 06 ¦ Check for read and write permission 04 ¦ Check for read permission 02 ¦ Check for write permission 01 ¦ Execute (ignored) 00 ¦ Check for existence of file This is problematic because the meanings are very different although the code compiles and runs perfectly. Note, for example, that a 4 (read permission) in TC/BC implies a W_OK (write permission) in DJGPP. access() is not an ANSI-C function, so probably it is not an "error" of the compilers, but it is easy to do a mistake, specially when porting from TC/BC (where numbers are used, not #defines) to DJGPP (where the compiler simply interpret those numbers in a different way). I would like: - Warn those of you that use access() in both compilers (probably most or all of you know about it, but it could be useful for some people). Recommend to use words, not numbers. - Ask if anybody knows a reason for that difference. - Post to the group my proposal to avoid this. It is a small #include that can be included both in DJGPP and TC/BC codes and that allows using DJGPP notation under TC/BC. Nevertheless, be aware that it does not solve the confusion when access() is (was) already written using TC/BC numerical codes instead of the proposed words. #ifdef __DJGPP__ #include #else #include #endif #if defined (__BORLANDC__) || defined (__TURBOC__) #define F_OK 0 #define R_OK 4 /* Gives the same result as F_OK */ #define W_OK 2 #define X_OK 1 /* TC/BC returns 0 if the file exists; -1 if it does not. DJGPP returns 0 if the file exists and it is executable (EXE, COM); -1 if it does not exist or if it does not recognize it as executable (BAT and PIF files also return -1). */ #define D_OK 0 /* TC/BC only determines whether the directory exists. If you submit c:\dos\xcopy.xxx returns 0 although xcopy.xxx does not exist (but c:\dos does). DJGPP returns 0 only if it is a directory (c:\dos). */ #endif Hope this helps, Xavier Pons