Re: [PATCH 5/8] Test for number of mkdir() arguments

Pawel Kot <[email protected]> Tue, 4 Dec 2018 00:24:14 +0300
Newsgroups gmane.linux.drivers.gnokii
Message-ID <CAHytCw7C1Zz8E7NAC4W155bP+NoDyrMv3BZGpX4gV3A=uPiwqw@mail.gmail.com>
--===============1115802752536070136==
Content-Type: multipart/alternative; boundary="000000000000fc86ea057c24c563"

--000000000000fc86ea057c24c563
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Ladis,

On Mon, Dec 3, 2018 at 11:28 PM Ladislav Michl <[email protected]> wrote=
:
> there's an issue with changes like that one bellow.
> Currently each file including compat.h have to include
> config.h before on its own. That does not sound too
> convenient and is quite error prone as I just found
> testing mkdir patch on more configurations.

I remeber it being discussed. Still not quite sure why we did it that way.
I believe #include "config.h" from compat.h should be safe. Even without
removing all others. I believe that whenever you need something from
"config.h" you should explicitly include it.

Cheers,
Pawe=C5=82

> So what about this change:
>
> diff --git a/include/compat.h b/include/compat.h
> index 8711c425..60974344 100644
> --- a/include/compat.h
> +++ b/include/compat.h
> @@ -18,6 +18,17 @@
>  #ifndef        _gnokii_compat_h
>  #define        _gnokii_compat_h
>
> +#if defined(HAVE_CONFIG_H)
> +#  include "config.h"
> +
> +#elif defined(WIN32) && defined(_MSC_VER)
> +#  include "windows-config.h"
> +
> +#else
> +#  error "compat.h requires config.h"
> +
> +#endif
> +
>  #include <stdlib.h>
>  #include <stdio.h>
>
> Perhaps ommiting windows-config.h part in the first round.
> Then we could delete config.h include from each file which
> also include compat.h. That is... almost each file.
>
> Objections?
>
>
> On Mon, Dec 03, 2018 at 10:42:06AM +0100, Ladislav Michl wrote:
> > Windows' mkdir() takes only 1 argument, so add a test for that.
> > ---
> >  configure.ac     |  1 +
> >  include/compat.h | 15 ++++++++++++++-
> >  2 files changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/configure.ac b/configure.ac
> > index 379c7412..cd2064dd 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -902,6 +902,7 @@ AC_PROG_GCC_TRADITIONAL
> >  AC_FUNC_MEMCMP
> >  AC_TYPE_SIGNAL
> >  AC_FUNC_STRFTIME
> > +AC_FUNC_MKDIR
> >  AC_CHECK_FUNCS(mktime timegm gettimeofday select poll wcrtomb)
> >  AC_CHECK_FUNCS(strchr strdup strndup strstr strtol strtok strsep)
> >  AC_CHECK_FUNCS(asprintf vasprintf snprintf vsnprintf getpass setenv)
> > diff --git a/include/compat.h b/include/compat.h
> > index 009f5f0e..8711c425 100644
> > --- a/include/compat.h
> > +++ b/include/compat.h
> > @@ -199,6 +199,20 @@ int vasprintf(char **ptr, const char *format,
va_list ap);
> >  time_t timegm(struct tm *tm);
> >  #endif
> >
> > +#if HAVE_MKDIR
> > +# if MKDIR_TAKES_ONE_ARG
> > +   /* Mingw32 */
> > +#  define mkdir(a,b) mkdir(a)
> > +# endif
> > +#else
> > +# if HAVE__MKDIR
> > +   /* plain Win32 */
> > +#  define mkdir(a,b) _mkdir(a)
> > +# else
> > +#  error "Don't know how to create a directory on this system."
> > +# endif
> > +#endif
> > +
> >  /*
> >   * The following code was taken from W. Richard Stevens'
> >   * "UNIX Network Programming", Volume 1, Second Edition.
> > @@ -219,7 +233,6 @@ time_t timegm(struct tm *tm);
> >  #ifdef WIN32
> >  #  ifdef _MSC_VER
> >  #    define inline __inline
> > -#    define mkdir(dirname, accessrights) _mkdir(dirname)
> >  #    define strcasecmp _stricmp
> >  #    define strncasecmp _strnicmp
> >  #    define __const const
> > --
> > 2.20.0.rc1
> >
> >
> > _______________________________________________
> > gnokii-users mailing list
> > [email protected]
> > https://lists.nongnu.org/mailman/listinfo/gnokii-users
>
> _______________________________________________
> gnokii-users mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/gnokii-users



--
Pawel Kot

--000000000000fc86ea057c24c563
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi Ladis,<br><br>On Mon, Dec 3, 2018 at 11:28 PM Ladislav =
Michl &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&=
gt; wrote:<br>&gt; there&#39;s an issue with changes like that one bellow.<=
br>&gt; Currently each file including compat.h have to include<br>&gt; conf=
ig.h before on its own. That does not sound too<br>&gt; convenient and is q=
uite error prone as I just found<br>&gt; testing mkdir patch on more config=
urations.<br><br>I remeber it being discussed. Still not quite sure why we =
did it that way.<div>I believe #include &quot;config.h&quot; from compat.h =
should be safe. Even without removing all others. I believe that whenever y=
ou need something from &quot;config.h&quot; you should explicitly include i=
t.</div><div><br></div><div>Cheers,</div><div>Pawe=C5=82</div><div><br>&gt;=
 So what about this change:<br>&gt;<br>&gt; diff --git a/include/compat.h b=
/include/compat.h<br>&gt; index 8711c425..60974344 100644<br>&gt; --- a/inc=
lude/compat.h<br>&gt; +++ b/include/compat.h<br>&gt; @@ -18,6 +18,17 @@<br>=
&gt; =C2=A0#ifndef =C2=A0 =C2=A0 =C2=A0 =C2=A0_gnokii_compat_h<br>&gt; =C2=
=A0#define =C2=A0 =C2=A0 =C2=A0 =C2=A0_gnokii_compat_h<br>&gt;<br>&gt; +#if=
 defined(HAVE_CONFIG_H)<br>&gt; +# =C2=A0include &quot;config.h&quot;<br>&g=
t; +<br>&gt; +#elif defined(WIN32) &amp;&amp; defined(_MSC_VER)<br>&gt; +# =
=C2=A0include &quot;windows-config.h&quot;<br>&gt; +<br>&gt; +#else<br>&gt;=
 +# =C2=A0error &quot;compat.h requires config.h&quot;<br>&gt; +<br>&gt; +#=
endif<br>&gt; +<br>&gt; =C2=A0#include &lt;stdlib.h&gt;<br>&gt; =C2=A0#incl=
ude &lt;stdio.h&gt;<br>&gt;<br>&gt; Perhaps ommiting windows-config.h part =
in the first round.<br>&gt; Then we could delete config.h include from each=
 file which<br>&gt; also include compat.h. That is... almost each file.<br>=
&gt;<br>&gt; Objections?<br>&gt;<br>&gt;<br>&gt; On Mon, Dec 03, 2018 at 10=
:42:06AM +0100, Ladislav Michl wrote:<br>&gt; &gt; Windows&#39; mkdir() tak=
es only 1 argument, so add a test for that.<br>&gt; &gt; ---<br>&gt; &gt; =
=C2=A0<a href=3D"http://configure.ac">configure.ac</a> =C2=A0 =C2=A0 | =C2=
=A01 +<br>&gt; &gt; =C2=A0include/compat.h | 15 ++++++++++++++-<br>&gt; &gt=
; =C2=A02 files changed, 15 insertions(+), 1 deletion(-)<br>&gt; &gt;<br>&g=
t; &gt; diff --git a/<a href=3D"http://configure.ac">configure.ac</a> b/<a =
href=3D"http://configure.ac">configure.ac</a><br>&gt; &gt; index 379c7412..=
cd2064dd 100644<br>&gt; &gt; --- a/<a href=3D"http://configure.ac">configur=
e.ac</a><br>&gt; &gt; +++ b/<a href=3D"http://configure.ac">configure.ac</a=
><br>&gt; &gt; @@ -902,6 +902,7 @@ AC_PROG_GCC_TRADITIONAL<br>&gt; &gt; =C2=
=A0AC_FUNC_MEMCMP<br>&gt; &gt; =C2=A0AC_TYPE_SIGNAL<br>&gt; &gt; =C2=A0AC_F=
UNC_STRFTIME<br>&gt; &gt; +AC_FUNC_MKDIR<br>&gt; &gt; =C2=A0AC_CHECK_FUNCS(=
mktime timegm gettimeofday select poll wcrtomb)<br>&gt; &gt; =C2=A0AC_CHECK=
_FUNCS(strchr strdup strndup strstr strtol strtok strsep)<br>&gt; &gt; =C2=
=A0AC_CHECK_FUNCS(asprintf vasprintf snprintf vsnprintf getpass setenv)<br>=
&gt; &gt; diff --git a/include/compat.h b/include/compat.h<br>&gt; &gt; ind=
ex 009f5f0e..8711c425 100644<br>&gt; &gt; --- a/include/compat.h<br>&gt; &g=
t; +++ b/include/compat.h<br>&gt; &gt; @@ -199,6 +199,20 @@ int vasprintf(c=
har **ptr, const char *format, va_list ap);<br>&gt; &gt; =C2=A0time_t timeg=
m(struct tm *tm);<br>&gt; &gt; =C2=A0#endif<br>&gt; &gt; <br>&gt; &gt; +#if=
 HAVE_MKDIR<br>&gt; &gt; +# if MKDIR_TAKES_ONE_ARG<br>&gt; &gt; + =C2=A0 /*=
 Mingw32 */<br>&gt; &gt; +# =C2=A0define mkdir(a,b) mkdir(a)<br>&gt; &gt; +=
# endif<br>&gt; &gt; +#else<br>&gt; &gt; +# if HAVE__MKDIR<br>&gt; &gt; + =
=C2=A0 /* plain Win32 */<br>&gt; &gt; +# =C2=A0define mkdir(a,b) _mkdir(a)<=
br>&gt; &gt; +# else<br>&gt; &gt; +# =C2=A0error &quot;Don&#39;t know how t=
o create a directory on this system.&quot;<br>&gt; &gt; +# endif<br>&gt; &g=
t; +#endif<br>&gt; &gt; +<br>&gt; &gt; =C2=A0/*<br>&gt; &gt; =C2=A0 * The f=
ollowing code was taken from W. Richard Stevens&#39;<br>&gt; &gt; =C2=A0 * =
&quot;UNIX Network Programming&quot;, Volume 1, Second Edition.<br>&gt; &gt=
; @@ -219,7 +233,6 @@ time_t timegm(struct tm *tm);<br>&gt; &gt; =C2=A0#ifd=
ef WIN32<br>&gt; &gt; =C2=A0# =C2=A0ifdef _MSC_VER<br>&gt; &gt; =C2=A0# =C2=
=A0 =C2=A0define inline __inline<br>&gt; &gt; -# =C2=A0 =C2=A0define mkdir(=
dirname, accessrights) _mkdir(dirname)<br>&gt; &gt; =C2=A0# =C2=A0 =C2=A0de=
fine strcasecmp _stricmp<br>&gt; &gt; =C2=A0# =C2=A0 =C2=A0define strncasec=
mp _strnicmp<br>&gt; &gt; =C2=A0# =C2=A0 =C2=A0define __const const<br>&gt;=
 &gt; --<br>&gt; &gt; 2.20.0.rc1<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; ___=
____________________________________________<br>&gt; &gt; gnokii-users mail=
ing list<br>&gt; &gt; <a href=3D"mailto:[email protected]">gnokii-use=
[email protected]</a><br>&gt; &gt; <a href=3D"https://lists.nongnu.org/mailman/=
listinfo/gnokii-users">https://lists.nongnu.org/mailman/listinfo/gnokii-use=
rs</a><br>&gt;<br>&gt; _______________________________________________<br>&=
gt; gnokii-users mailing list<br>&gt; <a href=3D"mailto:gnokii-users@nongnu=
.org">[email protected]</a><br>&gt; <a href=3D"https://lists.nongnu.o=
rg/mailman/listinfo/gnokii-users">https://lists.nongnu.org/mailman/listinfo=
/gnokii-users</a><br><br><br><br>--<br>Pawel Kot<br></div></div>

--000000000000fc86ea057c24c563--


--===============1115802752536070136==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gnokii-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/gnokii-users

--===============1115802752536070136==--