Proposal: libsmbclient API

Derrell Lipman derrell.lipman at unwireduniverse.com
Thu Mar 26 17:47:29 GMT 2009


On Thu, Mar 26, 2009 at 1:29 PM, Andreas Schneider <mail at cynapses.org>wrote:

> On Thursday 26 March 2009 18:09:56 you wrote:
> > If it's going to return a string, then how about just passing a string as
> > the parameter? It's easy enough to parse, and that way the interface is
> > consistent.
> >
>
> I would prefer an interger. It's easier to compare. I've implemented it in
> csync and libssh this way.
>
> https://dev.csync.org/browser/src/csync.h
>
> Take a look at line 40 - 52 for the macros.
>

That's fine, and it's exactly what I figured you were doing.

One warning, though:
#define CSYNC_VERSION_INT(a, b, c) (a << 16 | b << 8 | c)

As unlikely as it may be, if someone passes parameters like this:
  CSYNC_VERSION_INT(0x1 | 0x2, 2, 4)
your version calculation will be incorrect because the left-shift operator
has higher precedence than the bitwise-OR operator. For reliability, macros
should always reference their parameters as a parenthesized expression:

#define CSYNC_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))

Cheers,

Derrell


More information about the samba-technical mailing list