Skip to content

Commit

Permalink
revert spurious whitespace changes
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Dec 12, 2023
1 parent fc38c7a commit 14757da
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
//
// SPDX-License-Identifier: BSD-2-Clause

#include <errno.h>
#include <stdarg.h>
#include <sys/ioctl.h>

#include <wasi/api.h>
#include <errno.h>
#include <stdarg.h>

#ifdef __wasilibc_use_preview2
#include <descriptor_table.h>
#endif

int ioctl(int fildes, int request, ...)
{
int ioctl(int fildes, int request, ...) {
#ifdef __wasilibc_use_preview2
descriptor_table_entry_t* entry;
if (descriptor_table_get_ref(fildes, &entry)) {
Expand Down Expand Up @@ -44,80 +44,80 @@ int ioctl(int fildes, int request, ...)
}
#endif // __wasilibc_use_preview2

switch (request) {
switch (request) {
case FIONREAD: {
// Poll the file descriptor to determine how many bytes can be read.
__wasi_subscription_t subscriptions[2] = {
{
.u.tag = __WASI_EVENTTYPE_FD_READ,
.u.u.fd_read.file_descriptor = fildes,
},
{
.u.tag = __WASI_EVENTTYPE_CLOCK,
.u.u.clock.id = __WASI_CLOCKID_MONOTONIC,
},
};
__wasi_event_t events[__arraycount(subscriptions)];
size_t nevents;
__wasi_errno_t error = __wasi_poll_oneoff(
subscriptions, events, __arraycount(subscriptions), &nevents);
if (error != 0) {
errno = error;
return -1;
}
// Poll the file descriptor to determine how many bytes can be read.
__wasi_subscription_t subscriptions[2] = {
{
.u.tag = __WASI_EVENTTYPE_FD_READ,
.u.u.fd_read.file_descriptor = fildes,
},
{
.u.tag = __WASI_EVENTTYPE_CLOCK,
.u.u.clock.id = __WASI_CLOCKID_MONOTONIC,
},
};
__wasi_event_t events[__arraycount(subscriptions)];
size_t nevents;
__wasi_errno_t error = __wasi_poll_oneoff(
subscriptions, events, __arraycount(subscriptions), &nevents);
if (error != 0) {
errno = error;
return -1;
}

// Location where result should be written.
va_list ap;
va_start(ap, request);
int* result = va_arg(ap, int*);
va_end(ap);
// Location where result should be written.
va_list ap;
va_start(ap, request);
int *result = va_arg(ap, int *);
va_end(ap);

// Extract number of bytes for reading from poll results.
for (size_t i = 0; i < nevents; ++i) {
__wasi_event_t* event = &events[i];
if (event->error != 0) {
errno = event->error;
return -1;
}
if (event->type == __WASI_EVENTTYPE_FD_READ) {
*result = event->fd_readwrite.nbytes;
return 0;
}
// Extract number of bytes for reading from poll results.
for (size_t i = 0; i < nevents; ++i) {
__wasi_event_t *event = &events[i];
if (event->error != 0) {
errno = event->error;
return -1;
}
if (event->type == __WASI_EVENTTYPE_FD_READ) {
*result = event->fd_readwrite.nbytes;
return 0;
}
}

// No data available for reading.
*result = 0;
return 0;
// No data available for reading.
*result = 0;
return 0;
}
case FIONBIO: {
// Obtain the current file descriptor flags.
__wasi_fdstat_t fds;
__wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds);
if (error != 0) {
errno = error;
return -1;
}
// Obtain the current file descriptor flags.
__wasi_fdstat_t fds;
__wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds);
if (error != 0) {
errno = error;
return -1;
}

// Toggle the non-blocking flag based on the argument.
va_list ap;
va_start(ap, request);
if (*va_arg(ap, const int*) != 0)
fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK;
else
fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK;
va_end(ap);
// Toggle the non-blocking flag based on the argument.
va_list ap;
va_start(ap, request);
if (*va_arg(ap, const int *) != 0)
fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK;
else
fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK;
va_end(ap);

// Update the file descriptor flags.
error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags);
if (error != 0) {
errno = error;
return -1;
}
return 0;
}
default:
// Invalid request.
errno = EINVAL;
// Update the file descriptor flags.
error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags);
if (error != 0) {
errno = error;
return -1;
}
return 0;
}
default:
// Invalid request.
errno = EINVAL;
return -1;
}
}

0 comments on commit 14757da

Please sign in to comment.