[systemd-devel] [PATCH] Add sd_is_special for special file descriptors

William Douglas william.r.douglas at gmail.com
Wed Jun 15 12:45:51 PDT 2011


Jim Meyering <jim at meyering.net> writes:

> William Douglas wrote:
>
> Hello,
> I notice that other code in this file does the same thing,
> so maybe you're just following that example, but why bother
> to clear the bits of a struct stat before calling fstat or stat
> to fill it in?
>
> Aren't the two memset calls here unnecessary?
You are completely correct, I'll change those thanks!

>
>> +        if (!S_ISREG(st_fd.st_mode))
>> +                return 0;
>> +
>> +        if (path) {
>> +                struct stat st_path;
>> +
>> +                memset(&st_path, 0, sizeof(st_path));
>> +                if (stat(path, &st_path) < 0) {
>> +
>> +                        if (errno == ENOENT || errno == ENOTDIR)
>> +                                return 0;
>> +
>> +                        return -errno;
>> +                }
>> +
>> +                return
>> +                        st_path.st_dev == st_fd.st_dev &&
>> +                        st_path.st_ino == st_fd.st_ino;
>> +        }
>> +
>> +        return 1;
>> +}

-- 
William Douglas, Intel Open Source Technology Center


More information about the systemd-devel mailing list