<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sun, Aug 19, 2018 at 2:39 PM Richard W.M. Jones <<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Aug 19, 2018 at 01:13:07AM +0300, Nir Soffer wrote:<br>
> is_aligned (size, align) returns true if size is aligned to align,<br>
> assuming that align is power of 2.<br>
> <br>
> Suggested by Eric Blake in<br>
> <a href="https://www.redhat.com/archives/libguestfs/2018-August/msg00036.html" rel="noreferrer" target="_blank">https://www.redhat.com/archives/libguestfs/2018-August/msg00036.html</a><br>
> ---<br>
>  common/include/isaligned.h | 51 ++++++++++++++++++++++++++++++++++++++<br>
>  1 file changed, 51 insertions(+)<br>
>  create mode 100644 common/include/isaligned.h<br>
> <br>
> diff --git a/common/include/isaligned.h b/common/include/isaligned.h<br>
<br>
You have to add this file to common/include/Makefile.am otherwise<br>
it will never be distributed.<br></blockquote><div><br></div><div>Right, missed this, will be in v4.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Rich.<br>
<br>
> new file mode 100644<br>
> index 0000000..e693820<br>
> --- /dev/null<br>
> +++ b/common/include/isaligned.h<br>
> @@ -0,0 +1,51 @@<br>
> +/* nbdkit<br>
> + * Copyright (C) 2018 Red Hat Inc.<br>
> + * All rights reserved.<br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions are<br>
> + * met:<br>
> + *<br>
> + * * Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + *<br>
> + * * Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * * Neither the name of Red Hat nor the names of its contributors may be<br>
> + * used to endorse or promote products derived from this software without<br>
> + * specific prior written permission.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND<br>
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,<br>
> + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A<br>
> + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR<br>
> + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,<br>
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT<br>
> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF<br>
> + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND<br>
> + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,<br>
> + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT<br>
> + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
> + * SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#ifndef NBDKIT_ISALIGNED_H<br>
> +#define NBDKIT_ISALIGNED_H<br>
> +<br>
> +#include <assert.h><br>
> +#include <stdbool.h><br>
> +<br>
> +#include "ispowerof2.h"<br>
> +<br>
> +/* Return true if size is a multiple of align. align must be power of 2.<br>
> + */<br>
> +static inline bool<br>
> +is_aligned (unsigned int size, unsigned int align)<br>
> +{<br>
> +  assert (is_power_of_2 (align));<br>
> +  return !(size & (align - 1));<br>
> +}<br>
> +<br>
> +#endif /* NBDKIT_ISALIGNED_H */<br>
> -- <br>
> 2.17.1<br>
<br>
-- <br>
Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones</a><br>
Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
libguestfs lets you edit virtual machines.  Supports shell scripting,<br>
bindings from many languages.  <a href="http://libguestfs.org" rel="noreferrer" target="_blank">http://libguestfs.org</a><br>
</blockquote></div></div>