On 03/06/13 00:37, Eric Blake wrote:

> I guess I had in my mind %c instead of %u; still, I can't help but
> wonder if fprintf() and buffering is overkill, compared to just doing
> something like this:
>  write(fd, &"01"[vcpu->online], 1);
> 
> (okay, I hope you would favor readability over my compact
> representation, but you get the point).

I'd be crucified on qemu-devel if I tried to pull off something like the
above :)

> Oh, and I guess I didn't check
> whether a trailing newline is essential to the kernel interpreting the
> input, so maybe it would have to be more like:
> 
>  char buf[2] = { "01"[vcpu->online], '\n' };
>  write(fd, buf, 2);

The newline is probably not important.

Anyway I'd prefer to avoid direct write()s with nbyte > 1 as I'd have to
handle partial transfers, if for nothing else than principle. (IIRC
avoiding that loop was my main motivation for stdio.)

I guess I'll use open(O_DIRECTORY) + openat("online") + read(..., 1) +
pwrite(..., 1, 0). RHEL-5 seems to support all of these (I can't find
O_SEARCH in the manual there, which is why I'll probably omit it from
open()). If people still complain then I can switch from open(directory)
+ openat("online") to lstat(directory) + open("/.../online").

Thanks
Laszlo


Reply via email to