From: <no...@so...> - 2001-07-19 12:15:07
|
Patches item #425763, was opened at 2001-05-20 16:51 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=302435&aid=425763&group_id=2435 Category: runtime Group: None Status: Open Resolution: None Priority: 5 Submitted By: Danny Smith (dannysmith) Assigned to: Earnie Boyd (earnie) Summary: Fix sys/stat.h S_IS* macros Initial Comment: The S_IS* macros in sys/stat.h are not safe when assigned to char. The following code illustrates: /* stat.c */ #include <sys/stat.h> #include <stdio.h> #define SAFE_S_ISREG(m) (((m)& S_IFMT) == S_IFREG) int main( void ) { struct _stat buf; char isregfile; if ( _stat( "stat.c", &buf )== 0 ) { isregfile= S_ISREG (buf.st_mode); printf("S_ISREG: %d\n", isregfile); /* 0 */ isregfile= SAFE_S_ISREG (buf.st_mode); printf("SAFE_S_ISREG: %d\n", isregfile); /* 1 */ } return 0; } Patch makes safe, so that macros return 0 or 1. Danny ---------------------------------------------------------------------- >Comment By: Earnie Boyd (earnie) Date: 2001-07-19 05:15 Message: Logged In: YES user_id=15438 _S_IFBLK isn't described at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt__stat_structure_st_m ode_field_constants.asp so it's bogus and IMO should be removed. Based on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt__access.2c_._wacces s.asp _S_IREAD should have a value of 2 and _S_IWRITE should have a value of 4 We'll have to further research or experiment to come up with the correct values for the others. ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2001-07-18 18:05 Message: Logged In: YES user_id=11494 While configuring make-3.79.1, the configure test for S_IS macros in current sys/stat results in: #define STAT_MACROS_BROKEN. With my patch, they pass configure test. This is the part of the test that fails: #include <sys/stat.h> #if defined(S_ISBLK) && defined(S_IFCHR) # if S_ISBLK (S_IFCHR) You lose. # endif #endif S_ISBLK (S_FIF0) would fail as well. Danny ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2001-06-25 16:21 Message: Logged In: YES user_id=11494 Your right Earnie, the example I gave is not good enough reason. My expectation of an is-type function or macro is to return a 0/1 value, but that is not a reasonable expectation. What really bothers me about the current S_IS* macros is the fact that the current macros seem to imply that each mode has its own bit. Which is not true. #define _S_IFIFO 0x1000 // 1000000000000 #define _S_IFCHR 0x2000 // 10000000000000 #define _S_IFBLK 0x3000 // 11000000000000 #define _S_IFDIR 0x4000 // 100000000000000 #define _S_IFREG 0x8000 // 1000000000000000 #define _S_IFMT 0xF000 // 1111000000000000 Are all block devices also FIFOs and Character devices? ARe all Character devices also Block The current macros imply that they are. Also the extra overhead is not that great: ((m) & _S_IFDIR) == 0 vs ((m) & _S_IFMT ) == _S_IFDIR ---------------------------------------------------------------------- Comment By: Earnie Boyd (earnie) Date: 2001-06-11 11:03 Message: Logged In: YES user_id=15438 I really don't like this patch. It adds unnecessary overhead for the incorrect behavior of defining the result as a char instead of _mode_t. The typical use for this is directly with a conditional and not as a value set into a variable. Earnie. ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=302435&aid=425763&group_id=2435 |