<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 23, 2015 at 5:36 AM, Dave Chinner <span dir="ltr"><<a href="mailto:david@fromorbit.com" target="_blank">david@fromorbit.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Sep 15, 2015 at 11:59:22AM +0200, Jan Tulak wrote:<br>
> @@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)<br>
>       }<br>
><br>
>       while ((t = getmntent(mtabp))) {<br>
> +#elif defined(HAVE_GETMNTINFO)<br>
> +     struct statfs   *stats;<br>
> +     int error, i, count;<br>
> +     // because "t" is a pointer, but we don't need to use<br>
> +     // malloc for this usage<br>
> +     struct mntent t_tmp;<br>
> +     t = &t_tmp;<br>
> +<br>
> +<br>
> +     error = 0;<br>
> +     if ((count = getmntinfo(&stats, 0)) < 0) {<br>
> +             fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),<br>
> +                             progname, strerror(errno));<br>
> +             return 0;<br>
> +     }<br>
> +<br>
> +     for (i = 0; i < count; i++) {<br>
> +             mntinfo2mntent(&stats[i], t);<br>
> +#else<br>
> +# error "How do I extract info about mounted filesystems on this platform?"<br>
> +#endif<br>
<br>
</div></div>No, please don't do that. Having a loop iterator split across two<br>
separate defines is unmaintainable. Write two separate functions<br>
with the different loop iterators, then factor the common bit out<br>
of them into a single function.<br>
<div><div class="h5"><br></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">I did a little refactoring to solve it. What I would like to ask ab​out is this:</div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">When I can put ifdef just inside of a function like fnc(void) { #ifdef... #else ... #endif }, with little to no code outside of the ifdef, is it better to put the ifdef outside, or keep it inside? </div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">I suppose the outside placement allows for easier changes for one of the branches when there would be a new function just for a specific branch. But on the other side, it makes it easier to forget the second function in another branch when making some change later.</div></div></div><div class="gmail_extra"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">​Cheers,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Jan​</div><div><br></div>--<div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​-​</div><br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Jan Tulak<br></div><a href="mailto:jtulak@redhat.com" target="_blank">jtulak@redhat.com</a> / <a href="mailto:jan@tulak.me" target="_blank">jan@tulak.me</a></div></div></div></div>
</div></div>