On Feb 2, 2016, at 9:30 PM, Eric Blake wrote:
> On 02/02/2016 06:15 PM, Programmingkid wrote:
>
>>> No, keep filename as a const char * pointer. It's easy to avoid use of
>>> uninitialized memory. Try this:
>>>
>>> const char *filename;
>>> char bsd_path[MAXPATHLEN] = "";
>>> ...
>>> if (strncmp("/dev/cdrom"...) {
>>> bsd_path = ...
>>> }
>>> ...
>>> if (strncmp("/dev/"...) {
>>> print_unmounting_directions(*bsd_path ? bsd_path : filename);
>>
>> At first I thought this code looked unusual, but it does work. Is this ok?
>>
>> #if defined(__APPLE__) && defined(__MACH__)
>> /* if a physical device experienced an error while being opened */
>> if (strncmp((*bsd_path ? bsd_path : filename), "/dev/", 5) == 0) {
>> print_unmounting_directions(*bsd_path ? bsd_path : filename);
>> return -1;
>> }
>
> A bit repetitive. You don't use filename after the fact, so shorter
> would be:
>
> #if defined(__APPLE__)...
> if (*bsd_path) {
> filename = filename;
> if (strncmp(filename, "/dev/"...) {
> print...(filename);
>
Is this what you mean:
#if defined(__APPLE__) && defined(__MACH__)
/* if a physical device experienced an error while being opened */
filename = (*bsd_path ? bsd_path : filename);
if (strncmp(filename, "/dev/", 5) == 0) {
print_unmounting_directions(filename);
return -1;
}
#endif /* defined(__APPLE__) && defined(__MACH__) */