* Throughout, replace usage of w32api's min with MIN from sys/param.h.

This commit is contained in:
Corinna Vinschen 2012-03-08 09:36:11 +00:00
parent 106833e9b3
commit 75543537a1
12 changed files with 38 additions and 25 deletions

View File

@ -1,3 +1,7 @@
2012-03-07 Corinna Vinschen <corinna@vinschen.de>
* Throughout, replace usage of w32api's min with MIN from sys/param.h.
2012-03-07 Christopher Faylor <me.cygwin2012@cgf.cx> 2012-03-07 Christopher Faylor <me.cygwin2012@cgf.cx>
* pinfo.cc (_pinfo::dup_proc_pipe): Reorganize to provide more * pinfo.cc (_pinfo::dup_proc_pipe): Reorganize to provide more

View File

@ -14,6 +14,7 @@ details. */
#include <stdlib.h> #include <stdlib.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/acl.h> #include <sys/acl.h>
#include <sys/param.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "perprocess.h" #include "perprocess.h"
#include "security.h" #include "security.h"
@ -949,7 +950,7 @@ fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
char *p = buf; char *p = buf;
while (nbytes > 0) while (nbytes > 0)
{ {
const int frag = min (nbytes, (ssize_t) iovptr->iov_len); const int frag = MIN (nbytes, (ssize_t) iovptr->iov_len);
memcpy (iovptr->iov_base, p, frag); memcpy (iovptr->iov_base, p, frag);
p += frag; p += frag;
iovptr += 1; iovptr += 1;
@ -1001,7 +1002,7 @@ fhandler_base::writev (const struct iovec *const iov, const int iovcnt,
while (nbytes != 0) while (nbytes != 0)
{ {
const int frag = min (nbytes, (ssize_t) iovptr->iov_len); const int frag = MIN (nbytes, (ssize_t) iovptr->iov_len);
memcpy (bufptr, iovptr->iov_base, frag); memcpy (bufptr, iovptr->iov_base, frag);
bufptr += frag; bufptr += frag;
iovptr += 1; iovptr += 1;

View File

@ -18,6 +18,7 @@ details. */
#include <winuser.h> #include <winuser.h>
#include <winnls.h> #include <winnls.h>
#include <ctype.h> #include <ctype.h>
#include <sys/param.h>
#include <sys/cygwin.h> #include <sys/cygwin.h>
#include <cygwin/kd.h> #include <cygwin/kd.h>
#include "cygerrno.h" #include "cygerrno.h"
@ -1740,7 +1741,7 @@ fhandler_console::write_normal (const unsigned char *src,
if (trunc_buf.len) if (trunc_buf.len)
{ {
const unsigned char *nfound; const unsigned char *nfound;
int cp_len = min (end - src, 4 - trunc_buf.len); int cp_len = MIN (end - src, 4 - trunc_buf.len);
memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len); memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len);
memset (&ps, 0, sizeof ps); memset (&ps, 0, sizeof ps);
switch (ret = f_mbtowc (_REENT, NULL, (const char *) trunc_buf.buf, switch (ret = f_mbtowc (_REENT, NULL, (const char *) trunc_buf.buf,

View File

@ -2,7 +2,7 @@
fhandler classes. fhandler classes.
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
2009, 2011 Red Hat, Inc. 2009, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -13,6 +13,7 @@ details. */
#include "winsup.h" #include "winsup.h"
#include <alloca.h> #include <alloca.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h>
#include <winioctl.h> #include <winioctl.h>
#include <cygwin/rdevio.h> #include <cygwin/rdevio.h>
#include <cygwin/hdreg.h> #include <cygwin/hdreg.h>
@ -446,7 +447,7 @@ fhandler_dev_floppy::raw_read (void *ptr, size_t& ulen)
{ {
if (devbufstart < devbufend) if (devbufstart < devbufend)
{ {
bytes_to_read = min (len, devbufend - devbufstart); bytes_to_read = MIN (len, devbufend - devbufstart);
debug_printf ("read %d bytes from buffer (rest %d)", debug_printf ("read %d bytes from buffer (rest %d)",
bytes_to_read, bytes_to_read,
devbufend - devbufstart - bytes_to_read); devbufend - devbufstart - bytes_to_read);

View File

@ -11,6 +11,7 @@ details. */
#include "winsup.h" #include "winsup.h"
#include <unistd.h> #include <unistd.h>
#include <sys/param.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "security.h" #include "security.h"
#include "path.h" #include "path.h"
@ -44,7 +45,7 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
int tot; int tot;
DWORD n; DWORD n;
size_t minchars = vmin_ ? min (vmin_, ulen) : ulen; size_t minchars = vmin_ ? MIN (vmin_, ulen) : ulen;
debug_printf ("ulen %d, vmin_ %d, vtime_ %d, hEvent %p", ulen, vmin_, vtime_, debug_printf ("ulen %d, vmin_ %d, vtime_ %d, hEvent %p", ulen, vmin_, vtime_,
io_status.hEvent); io_status.hEvent);

View File

@ -1,7 +1,7 @@
/* fhandler_socket.cc. See fhandler.h for a description of the fhandler classes. /* fhandler_socket.cc. See fhandler.h for a description of the fhandler classes.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
2009, 2010, 2011 Red Hat, Inc. 2009, 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -34,6 +34,7 @@
#include "sigproc.h" #include "sigproc.h"
#include "wininfo.h" #include "wininfo.h"
#include <unistd.h> #include <unistd.h>
#include <sys/param.h>
#include <sys/acl.h> #include <sys/acl.h>
#include "cygtls.h" #include "cygtls.h"
#include "cygwin/in6.h" #include "cygwin/in6.h"
@ -1213,12 +1214,12 @@ fhandler_socket::accept4 (struct sockaddr *peer, int *len, int flags)
bound socket name of the peer's socket. For now bound socket name of the peer's socket. For now
we just fake an unbound socket on the other side. */ we just fake an unbound socket on the other side. */
static struct sockaddr_un un = { AF_LOCAL, "" }; static struct sockaddr_un un = { AF_LOCAL, "" };
memcpy (peer, &un, min (*len, (int) sizeof (un.sun_family))); memcpy (peer, &un, MIN (*len, (int) sizeof (un.sun_family)));
*len = (int) sizeof (un.sun_family); *len = (int) sizeof (un.sun_family);
} }
else else
{ {
memcpy (peer, &lpeer, min (*len, llen)); memcpy (peer, &lpeer, MIN (*len, llen));
*len = llen; *len = llen;
} }
} }
@ -1247,7 +1248,7 @@ fhandler_socket::getsockname (struct sockaddr *name, int *namelen)
sun.sun_path[0] = '\0'; sun.sun_path[0] = '\0';
if (get_sun_path ()) if (get_sun_path ())
strncat (sun.sun_path, get_sun_path (), UNIX_PATH_LEN - 1); strncat (sun.sun_path, get_sun_path (), UNIX_PATH_LEN - 1);
memcpy (name, &sun, min (*namelen, (int) SUN_LEN (&sun) + 1)); memcpy (name, &sun, MIN (*namelen, (int) SUN_LEN (&sun) + 1));
*namelen = (int) SUN_LEN (&sun) + (get_sun_path () ? 1 : 0); *namelen = (int) SUN_LEN (&sun) + (get_sun_path () ? 1 : 0);
res = 0; res = 0;
} }
@ -1261,7 +1262,7 @@ fhandler_socket::getsockname (struct sockaddr *name, int *namelen)
res = ::getsockname (get_socket (), (struct sockaddr *) &sock, &len); res = ::getsockname (get_socket (), (struct sockaddr *) &sock, &len);
if (!res) if (!res)
{ {
memcpy (name, &sock, min (*namelen, len)); memcpy (name, &sock, MIN (*namelen, len));
*namelen = len; *namelen = len;
} }
else else
@ -1290,7 +1291,7 @@ fhandler_socket::getsockname (struct sockaddr *name, int *namelen)
} }
if (!res) if (!res)
{ {
memcpy (name, &sock, min (*namelen, len)); memcpy (name, &sock, MIN (*namelen, len));
*namelen = len; *namelen = len;
} }
} }
@ -1321,12 +1322,12 @@ fhandler_socket::getpeername (struct sockaddr *name, int *namelen)
sun.sun_path[0] = '\0'; sun.sun_path[0] = '\0';
if (get_peer_sun_path ()) if (get_peer_sun_path ())
strncat (sun.sun_path, get_peer_sun_path (), UNIX_PATH_LEN - 1); strncat (sun.sun_path, get_peer_sun_path (), UNIX_PATH_LEN - 1);
memcpy (name, &sun, min (*namelen, (int) SUN_LEN (&sun) + 1)); memcpy (name, &sun, MIN (*namelen, (int) SUN_LEN (&sun) + 1));
*namelen = (int) SUN_LEN (&sun) + (get_peer_sun_path () ? 1 : 0); *namelen = (int) SUN_LEN (&sun) + (get_peer_sun_path () ? 1 : 0);
} }
else else
{ {
memcpy (name, &sock, min (*namelen, len)); memcpy (name, &sock, MIN (*namelen, len));
*namelen = len; *namelen = len;
} }

View File

@ -2,7 +2,7 @@
classes. classes.
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
2008, 2010, 2011 Red Hat, Inc. 2008, 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -1278,7 +1278,7 @@ fhandler_dev_tape::raw_read (void *ptr, size_t &ulen)
{ {
if (devbufend > devbufstart) if (devbufend > devbufstart)
{ {
bytes_to_read = min (len, devbufend - devbufstart); bytes_to_read = MIN (len, devbufend - devbufstart);
debug_printf ("read %d bytes from buffer (rest %d)", debug_printf ("read %d bytes from buffer (rest %d)",
bytes_to_read, devbufend - devbufstart - bytes_to_read); bytes_to_read, devbufend - devbufstart - bytes_to_read);
memcpy (buf, devbuf + devbufstart, bytes_to_read); memcpy (buf, devbuf + devbufstart, bytes_to_read);

View File

@ -11,6 +11,7 @@ details. */
#include "winsup.h" #include "winsup.h"
#include <stdlib.h> #include <stdlib.h>
#include <sys/param.h>
#include <cygwin/kd.h> #include <cygwin/kd.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "security.h" #include "security.h"
@ -623,7 +624,7 @@ fhandler_pty_slave::write (const void *ptr, size_t len)
while (len) while (len)
{ {
n = min (OUT_BUFFER_SIZE, len); n = MIN (OUT_BUFFER_SIZE, len);
char *buf = (char *)ptr; char *buf = (char *)ptr;
ptr = (char *) ptr + n; ptr = (char *) ptr + n;
len -= n; len -= n;
@ -802,7 +803,7 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
return; return;
} }
readlen = min (bytes_in_pipe, min (len, sizeof (buf))); readlen = MIN (bytes_in_pipe, MIN (len, sizeof (buf)));
if (ptr && vmin && readlen > (unsigned) vmin) if (ptr && vmin && readlen > (unsigned) vmin)
readlen = vmin; readlen = vmin;

View File

@ -57,6 +57,7 @@
#include <winnetwk.h> #include <winnetwk.h>
#include <winnls.h> #include <winnls.h>
#include <shlobj.h> #include <shlobj.h>
#include <sys/param.h>
#include <sys/cygwin.h> #include <sys/cygwin.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "security.h" #include "security.h"
@ -2782,7 +2783,7 @@ readlink (const char *path, char *buf, size_t buflen)
return -1; return -1;
} }
ssize_t len = min (buflen, strlen (pathbuf.get_win32 ())); ssize_t len = MIN (buflen, strlen (pathbuf.get_win32 ()));
memcpy (buf, pathbuf.get_win32 (), len); memcpy (buf, pathbuf.get_win32 (), len);
/* errno set by symlink.check if error */ /* errno set by symlink.check if error */

View File

@ -1293,7 +1293,7 @@ thread_socket (void *arg)
event = true; event = true;
if (!event) if (!event)
for (int i = 0; i < si->num_w4; i += MAXIMUM_WAIT_OBJECTS) for (int i = 0; i < si->num_w4; i += MAXIMUM_WAIT_OBJECTS)
switch (WaitForMultipleObjects (min (si->num_w4 - i, switch (WaitForMultipleObjects (MIN (si->num_w4 - i,
MAXIMUM_WAIT_OBJECTS), MAXIMUM_WAIT_OBJECTS),
si->w4 + i, FALSE, timeout)) si->w4 + i, FALSE, timeout))
{ {

View File

@ -1,7 +1,7 @@
/* strfuncs.cc: misc funcs that don't belong anywhere else /* strfuncs.cc: misc funcs that don't belong anywhere else
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -11,6 +11,7 @@ details. */
#include "winsup.h" #include "winsup.h"
#include <stdlib.h> #include <stdlib.h>
#include <sys/param.h>
#include <wchar.h> #include <wchar.h>
#include <winnls.h> #include <winnls.h>
#include <ntdll.h> #include <ntdll.h>
@ -238,7 +239,7 @@ __db_mbtowc (struct _reent *r, wchar_t *pwc, const char *s, size_t n, UINT cp,
*pwc = *(unsigned char *) s; *pwc = *(unsigned char *) s;
return *s ? 1 : 0; return *s ? 1 : 0;
} }
size_t cnt = min (n, 2); size_t cnt = MIN (n, 2);
ret = MultiByteToWideChar (cp, MB_ERR_INVALID_CHARS, s, cnt, pwc, 1); ret = MultiByteToWideChar (cp, MB_ERR_INVALID_CHARS, s, cnt, pwc, 1);
if (ret) if (ret)
return cnt; return cnt;
@ -312,7 +313,7 @@ __eucjp_mbtowc (struct _reent *r, wchar_t *pwc, const char *s, size_t n,
ret = 3; ret = 3;
goto jis_x_0212; goto jis_x_0212;
} }
size_t cnt = min (n, 2); size_t cnt = MIN (n, 2);
if (MultiByteToWideChar (20932, MB_ERR_INVALID_CHARS, s, cnt, pwc, 1)) if (MultiByteToWideChar (20932, MB_ERR_INVALID_CHARS, s, cnt, pwc, 1))
return cnt; return cnt;
if (n == 1) if (n == 1)

View File

@ -1,7 +1,7 @@
/* sysconf.cc /* sysconf.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2009, 2010, 2011 Red Hat, Inc. 2006, 2007, 2009, 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -11,6 +11,7 @@ details. */
#include "winsup.h" #include "winsup.h"
#include <unistd.h> #include <unistd.h>
#include <sys/param.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "security.h" #include "security.h"
@ -294,7 +295,7 @@ confstr (int in, char *buf, size_t len)
if (csa[in].l && len) if (csa[in].l && len)
{ {
buf[0] = 0; buf[0] = 0;
strncat (buf, csa[in].s, min (len, csa[in].l) - 1); strncat (buf, csa[in].s, MIN (len, csa[in].l) - 1);
} }
return csa[in].l; return csa[in].l;
} }