Re: [PATCH 3/4] mingw: move common functionality to win32.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Sep 27, 2008 at 08:34:04PM +0200, Johannes Sixt wrote:
> On Samstag, 27. September 2008, Dmitry Potapov wrote:
> > +static inline int get_file_attr(const char *fname,
> > WIN32_FILE_ATTRIBUTE_DATA *fdata) +{
> > +	if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata))
> > +		return 0;
> > +
> > +	switch (GetLastError()) {
> > +	case ERROR_ACCESS_DENIED:
> > +	case ERROR_SHARING_VIOLATION:
> > +	case ERROR_LOCK_VIOLATION:
> > +	case ERROR_SHARING_BUFFER_EXCEEDED:
> > +		return EACCES;
> > +	case ERROR_BUFFER_OVERFLOW:
> > +		return ENAMETOOLONG;
> > +	case ERROR_NOT_ENOUGH_MEMORY:
> > +		return ENOMEM;
> > +	default:
> > +		return ENOENT;
> > +	}
> > +}
> 
> I've long wished for a function that translates Win32 error codes to errno 
> codes. It would be useful in a number of other places, too.
> 
> Here you introduce a new function get_file_attr() that is nothing but 
> GetFileAttributesExA() followed by such an error code translation.
> 
> I suggest that we leave the original call to GetFileAttributesExA() alone and 
> have a function win32_to_errno(void) that is just the switch statement above.

win32_to_errno was the first thing that implemented but then released
that translation of Win32 errors to errno cannot be in general case.
For instance, ERROR_BUFFER_OVERFLOW means ENAMETOOLONG here, but it
can be translated to ETOOSMALL in other cases. How do you propose to
deal with that?

So I have not found a better solution than to add get_file_attr(), which
calls GetFileAttributesExA() and translates Win32 error.


Dmitry
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux