Re: [PATCH] Add getmntent_r
Yaakov (Cygwin/X <yselkowitz <at> users.sourceforge.net>
2012-06-06 02:29:13 GMT
On 2012-06-05 07:42, Corinna Vinschen wrote:
>> +extern "C" struct mntent *
>> +getmntent_r (FILE *, struct mntent *mntbuf, char *buf, int buflen)
>> +{
>> + struct mntent *mnt = mount_table->getmntent (_my_tls.locals.iteration++);
>> + char *tmpbuf;
>> + int len = 0, maxlen;
>> +
>> + if (!mnt)
>> + {
>> + mntbuf = NULL;
>
> This doesn't make sense since mntbuf is a local varibale. Changing
> its value won't be propagated by the calling function anyway.
Further testing of glibc shows that buf and mntbuf are indeed left
untouched when returning NULL.
>> + maxlen = strlen (mnt->mnt_fsname) + strlen (mnt->mnt_dir)
>> + + strlen (mnt->mnt_type) + strlen (mnt->mnt_opts) + 30;
>> + tmpbuf = (char *) alloca (maxlen);
>> + memset (tmpbuf, '\0', maxlen);
>> +
>> + len += __small_sprintf (tmpbuf, "%s", mnt->mnt_fsname) + 1;
>> + len += __small_sprintf (tmpbuf + len, "%s", mnt->mnt_dir) + 1;
>> + len += __small_sprintf (tmpbuf + len, "%s", mnt->mnt_type) + 1;
>> + len += __small_sprintf (tmpbuf + len, "%s", mnt->mnt_opts) + 1;
>
> This you can have simpler.
>
(Continue reading)