* [PATCH 1/4] last: use min() from c.h
@ 2012-05-17 7:41 Petr Uzel
2012-05-17 7:41 ` [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition Petr Uzel
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Petr Uzel @ 2012-05-17 7:41 UTC (permalink / raw)
To: util-linux
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
login-utils/last.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 34558bb..62fc55c 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -72,15 +72,11 @@ static struct utmp utmpbuf;
#define LMAX (int)sizeof(utmpbuf.ut_line) /* size of utmp tty field */
#define NMAX (int)sizeof(utmpbuf.ut_name) /* size of utmp name field */
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
/* maximum sizes used for printing */
/* probably we want a two-pass version that computes the right length */
-int hmax = MIN(HMAX, 16);
-int lmax = MIN(LMAX, 8);
-int nmax = MIN(NMAX, 16);
+int hmax = min(HMAX, 16);
+int lmax = min(LMAX, 8);
+int nmax = min(NMAX, 16);
typedef struct arg {
char *name; /* argument */
--
1.7.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition
2012-05-17 7:41 [PATCH 1/4] last: use min() from c.h Petr Uzel
@ 2012-05-17 7:41 ` Petr Uzel
2012-05-23 8:23 ` Karel Zak
2012-05-17 7:41 ` [PATCH 3/4] text-utils: use min() from c.h Petr Uzel
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Petr Uzel @ 2012-05-17 7:41 UTC (permalink / raw)
To: util-linux
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
disk-utils/mkfs.cramfs.c | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index 919f1ef..9e8f77f 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -80,10 +80,6 @@ static int warn_skip = 0;
static int warn_size = 0;
static int warn_uid = 0;
-#ifndef MIN
-# define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
-#endif
-
/* entry.flags */
#define CRAMFS_EFLAG_MD5 1
#define CRAMFS_EFLAG_INVALID 2
--
1.7.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] text-utils: use min() from c.h
2012-05-17 7:41 [PATCH 1/4] last: use min() from c.h Petr Uzel
2012-05-17 7:41 ` [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition Petr Uzel
@ 2012-05-17 7:41 ` Petr Uzel
2012-05-23 8:22 ` Karel Zak
2012-05-17 7:41 ` [PATCH 4/4] libuuid: use max() " Petr Uzel
2012-05-23 8:13 ` [PATCH 1/4] last: use min() " Karel Zak
3 siblings, 1 reply; 9+ messages in thread
From: Petr Uzel @ 2012-05-17 7:41 UTC (permalink / raw)
To: util-linux
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
text-utils/display.c | 7 ++-----
1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/text-utils/display.c b/text-utils/display.c
index ad638e7..84ec5d8 100644
--- a/text-utils/display.c
+++ b/text-utils/display.c
@@ -41,14 +41,11 @@
#include <string.h>
#include "hexdump.h"
#include "xalloc.h"
+#include "c.h"
static void doskip(const char *, int);
static u_char *get(void);
-#ifndef MIN
-#define MIN(a,b) ((a)<(b)?(a):(b))
-#endif
-
enum _vflag vflag = FIRST;
static off_t address; /* address/offset in stream */
@@ -262,7 +259,7 @@ get(void)
return(curp);
}
n = fread((char *)curp + nread, sizeof(unsigned char),
- length == -1 ? need : MIN(length, need), stdin);
+ length == -1 ? need : min(length, need), stdin);
if (!n) {
if (ferror(stdin))
warn("%s", _argv[-1]);
--
1.7.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] libuuid: use max() from c.h
2012-05-17 7:41 [PATCH 1/4] last: use min() from c.h Petr Uzel
2012-05-17 7:41 ` [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition Petr Uzel
2012-05-17 7:41 ` [PATCH 3/4] text-utils: use min() from c.h Petr Uzel
@ 2012-05-17 7:41 ` Petr Uzel
2012-05-23 8:24 ` Karel Zak
2012-05-23 8:13 ` [PATCH 1/4] last: use min() " Karel Zak
3 siblings, 1 reply; 9+ messages in thread
From: Petr Uzel @ 2012-05-17 7:41 UTC (permalink / raw)
To: util-linux
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
libuuid/src/gen_uuid.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c
index 9d5575b..613da02 100644
--- a/libuuid/src/gen_uuid.c
+++ b/libuuid/src/gen_uuid.c
@@ -91,6 +91,7 @@
#include "uuidP.h"
#include "uuidd.h"
#include "randutils.h"
+#include "c.h"
#ifdef HAVE_TLS
#define THREAD_LOCAL static __thread
@@ -150,9 +151,6 @@ static int get_node_id(unsigned char *node_id)
* just sizeof(struct ifreq)
*/
#ifdef HAVE_SA_LEN
-#ifndef max
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
#define ifreq_size(i) max(sizeof(struct ifreq),\
sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
#else
--
1.7.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/4] last: use min() from c.h
2012-05-17 7:41 [PATCH 1/4] last: use min() from c.h Petr Uzel
` (2 preceding siblings ...)
2012-05-17 7:41 ` [PATCH 4/4] libuuid: use max() " Petr Uzel
@ 2012-05-23 8:13 ` Karel Zak
2012-05-23 8:23 ` Petr Uzel
3 siblings, 1 reply; 9+ messages in thread
From: Karel Zak @ 2012-05-23 8:13 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Thu, May 17, 2012 at 09:41:06AM +0200, Petr Uzel wrote:
> login-utils/last.c | 10 +++-------
> 1 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/login-utils/last.c b/login-utils/last.c
> index 34558bb..62fc55c 100644
> --- a/login-utils/last.c
> +++ b/login-utils/last.c
> @@ -72,15 +72,11 @@ static struct utmp utmpbuf;
> #define LMAX (int)sizeof(utmpbuf.ut_line) /* size of utmp tty field */
> #define NMAX (int)sizeof(utmpbuf.ut_name) /* size of utmp name field */
>
> -#ifndef MIN
> -#define MIN(a,b) (((a) < (b)) ? (a) : (b))
> -#endif
> -
> /* maximum sizes used for printing */
> /* probably we want a two-pass version that computes the right length */
> -int hmax = MIN(HMAX, 16);
> -int lmax = MIN(LMAX, 8);
> -int nmax = MIN(NMAX, 16);
> +int hmax = min(HMAX, 16);
> +int lmax = min(LMAX, 8);
> +int nmax = min(NMAX, 16);
Please, test your patches... you cannot use min() (as defined in c.h)
outside functions.
It seems that {h,l,n}max are not modified in the code so we can use
macros there. Applied the patch below.
Karel
>From 69c9e8387b90025d1f75356f5e2369d0262ee603 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Wed, 23 May 2012 10:07:57 +0200
Subject: [PATCH] last: use min() from c.h
Signed-off-by: Karel Zak <kzak@redhat.com>
---
login-utils/last.c | 20 ++++++++------------
1 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 34558bb..1b1bee1 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -72,15 +72,11 @@ static struct utmp utmpbuf;
#define LMAX (int)sizeof(utmpbuf.ut_line) /* size of utmp tty field */
#define NMAX (int)sizeof(utmpbuf.ut_name) /* size of utmp name field */
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
/* maximum sizes used for printing */
/* probably we want a two-pass version that computes the right length */
-int hmax = MIN(HMAX, 16);
-int lmax = MIN(LMAX, 8);
-int nmax = MIN(NMAX, 16);
+#define P_HMAX min(HMAX, 16)
+#define P_LMAX min(LMAX, 8)
+#define P_NMAX min(NMAX, 16)
typedef struct arg {
char *name; /* argument */
@@ -187,19 +183,19 @@ print_partial_line(struct utmp *bp) {
char *ct;
ct = utmp_ctime(bp);
- printf("%-*.*s %-*.*s ", nmax, nmax, bp->ut_name,
- lmax, lmax, bp->ut_line);
+ printf("%-*.*s %-*.*s ", P_NMAX, P_NMAX, bp->ut_name,
+ P_LMAX, P_LMAX, bp->ut_line);
if (dolong) {
if (bp->ut_addr) {
struct in_addr foo;
foo.s_addr = bp->ut_addr;
- printf("%-*.*s ", hmax, hmax, inet_ntoa(foo));
+ printf("%-*.*s ", P_HMAX, P_HMAX, inet_ntoa(foo));
} else {
- printf("%-*.*s ", hmax, hmax, "");
+ printf("%-*.*s ", P_HMAX, P_HMAX, "");
}
} else {
- printf("%-*.*s ", hmax, hmax, bp->ut_host);
+ printf("%-*.*s ", P_HMAX, P_HMAX, bp->ut_host);
}
if (doyear) {
--
1.7.7.6
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] text-utils: use min() from c.h
2012-05-17 7:41 ` [PATCH 3/4] text-utils: use min() from c.h Petr Uzel
@ 2012-05-23 8:22 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-05-23 8:22 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Thu, May 17, 2012 at 09:41:08AM +0200, Petr Uzel wrote:
> text-utils/display.c | 7 ++-----
> 1 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/text-utils/display.c b/text-utils/display.c
> index ad638e7..84ec5d8 100644
> --- a/text-utils/display.c
> +++ b/text-utils/display.c
> @@ -41,14 +41,11 @@
> #include <string.h>
> #include "hexdump.h"
> #include "xalloc.h"
> +#include "c.h"
>
> static void doskip(const char *, int);
> static u_char *get(void);
>
> -#ifndef MIN
> -#define MIN(a,b) ((a)<(b)?(a):(b))
> -#endif
> -
> enum _vflag vflag = FIRST;
>
> static off_t address; /* address/offset in stream */
> @@ -262,7 +259,7 @@ get(void)
> return(curp);
> }
> n = fread((char *)curp + nread, sizeof(unsigned char),
> - length == -1 ? need : MIN(length, need), stdin);
> + length == -1 ? need : min(length, need), stdin);
It seems that the macro works as expected and detects some
disadvantages :-)
display.c: In function ‘get’:
display.c:262:117: warning: comparison of distinct pointer types
lacks a cast [enabled by default]
Fixed and applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition
2012-05-17 7:41 ` [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition Petr Uzel
@ 2012-05-23 8:23 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-05-23 8:23 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Thu, May 17, 2012 at 09:41:07AM +0200, Petr Uzel wrote:
> disk-utils/mkfs.cramfs.c | 4 ----
> 1 files changed, 0 insertions(+), 4 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/4] last: use min() from c.h
2012-05-23 8:13 ` [PATCH 1/4] last: use min() " Karel Zak
@ 2012-05-23 8:23 ` Petr Uzel
0 siblings, 0 replies; 9+ messages in thread
From: Petr Uzel @ 2012-05-23 8:23 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
[-- Attachment #1: Type: text/plain, Size: 3423 bytes --]
On Wed, May 23, 2012 at 10:13:02AM +0200, Karel Zak wrote:
> On Thu, May 17, 2012 at 09:41:06AM +0200, Petr Uzel wrote:
> > login-utils/last.c | 10 +++-------
> > 1 files changed, 3 insertions(+), 7 deletions(-)
> >
> > diff --git a/login-utils/last.c b/login-utils/last.c
> > index 34558bb..62fc55c 100644
> > --- a/login-utils/last.c
> > +++ b/login-utils/last.c
> > @@ -72,15 +72,11 @@ static struct utmp utmpbuf;
> > #define LMAX (int)sizeof(utmpbuf.ut_line) /* size of utmp tty field */
> > #define NMAX (int)sizeof(utmpbuf.ut_name) /* size of utmp name field */
> >
> > -#ifndef MIN
> > -#define MIN(a,b) (((a) < (b)) ? (a) : (b))
> > -#endif
> > -
> > /* maximum sizes used for printing */
> > /* probably we want a two-pass version that computes the right length */
> > -int hmax = MIN(HMAX, 16);
> > -int lmax = MIN(LMAX, 8);
> > -int nmax = MIN(NMAX, 16);
> > +int hmax = min(HMAX, 16);
> > +int lmax = min(LMAX, 8);
> > +int nmax = min(NMAX, 16);
>
> Please, test your patches... you cannot use min() (as defined in c.h)
> outside functions.
Oops, I normally do, but this one seemed so trivial that I did not
test it :( Lesson learned. Sorry.
> It seems that {h,l,n}max are not modified in the code so we can use
> macros there. Applied the patch below.
Thanks,
Petr
>
> Karel
>
>
>
> From 69c9e8387b90025d1f75356f5e2369d0262ee603 Mon Sep 17 00:00:00 2001
> From: Karel Zak <kzak@redhat.com>
> Date: Wed, 23 May 2012 10:07:57 +0200
> Subject: [PATCH] last: use min() from c.h
>
> Signed-off-by: Karel Zak <kzak@redhat.com>
> ---
> login-utils/last.c | 20 ++++++++------------
> 1 files changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/login-utils/last.c b/login-utils/last.c
> index 34558bb..1b1bee1 100644
> --- a/login-utils/last.c
> +++ b/login-utils/last.c
> @@ -72,15 +72,11 @@ static struct utmp utmpbuf;
> #define LMAX (int)sizeof(utmpbuf.ut_line) /* size of utmp tty field */
> #define NMAX (int)sizeof(utmpbuf.ut_name) /* size of utmp name field */
>
> -#ifndef MIN
> -#define MIN(a,b) (((a) < (b)) ? (a) : (b))
> -#endif
> -
> /* maximum sizes used for printing */
> /* probably we want a two-pass version that computes the right length */
> -int hmax = MIN(HMAX, 16);
> -int lmax = MIN(LMAX, 8);
> -int nmax = MIN(NMAX, 16);
> +#define P_HMAX min(HMAX, 16)
> +#define P_LMAX min(LMAX, 8)
> +#define P_NMAX min(NMAX, 16)
>
> typedef struct arg {
> char *name; /* argument */
> @@ -187,19 +183,19 @@ print_partial_line(struct utmp *bp) {
> char *ct;
>
> ct = utmp_ctime(bp);
> - printf("%-*.*s %-*.*s ", nmax, nmax, bp->ut_name,
> - lmax, lmax, bp->ut_line);
> + printf("%-*.*s %-*.*s ", P_NMAX, P_NMAX, bp->ut_name,
> + P_LMAX, P_LMAX, bp->ut_line);
>
> if (dolong) {
> if (bp->ut_addr) {
> struct in_addr foo;
> foo.s_addr = bp->ut_addr;
> - printf("%-*.*s ", hmax, hmax, inet_ntoa(foo));
> + printf("%-*.*s ", P_HMAX, P_HMAX, inet_ntoa(foo));
> } else {
> - printf("%-*.*s ", hmax, hmax, "");
> + printf("%-*.*s ", P_HMAX, P_HMAX, "");
> }
> } else {
> - printf("%-*.*s ", hmax, hmax, bp->ut_host);
> + printf("%-*.*s ", P_HMAX, P_HMAX, bp->ut_host);
> }
>
> if (doyear) {
> --
> 1.7.7.6
>
Petr
--
Petr Uzel
IRC: ptr_uzl @ freenode
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] libuuid: use max() from c.h
2012-05-17 7:41 ` [PATCH 4/4] libuuid: use max() " Petr Uzel
@ 2012-05-23 8:24 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-05-23 8:24 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Thu, May 17, 2012 at 09:41:09AM +0200, Petr Uzel wrote:
> libuuid/src/gen_uuid.c | 4 +---
> 1 files changed, 1 insertions(+), 3 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-05-23 8:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-17 7:41 [PATCH 1/4] last: use min() from c.h Petr Uzel
2012-05-17 7:41 ` [PATCH 2/4] mkfs.cramfs: remove unused 'MIN' macro definition Petr Uzel
2012-05-23 8:23 ` Karel Zak
2012-05-17 7:41 ` [PATCH 3/4] text-utils: use min() from c.h Petr Uzel
2012-05-23 8:22 ` Karel Zak
2012-05-17 7:41 ` [PATCH 4/4] libuuid: use max() " Petr Uzel
2012-05-23 8:24 ` Karel Zak
2012-05-23 8:13 ` [PATCH 1/4] last: use min() " Karel Zak
2012-05-23 8:23 ` Petr Uzel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).