int fcntl(int fd, int cmd, ...) { FAR struct file *filep; va_list ap; int ret; /* fcntl() is a cancellation point */ (void)enter_cancellation_point(); /* Setup to access the variable argument list */ va_start(ap, cmd); /* Did we get a valid file descriptor? */ #if CONFIG_NFILE_DESCRIPTORS > 0 if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS) { /* Get the file structure corresponding to the file descriptor. */ filep = fs_getfilep(fd); if (!filep) { /* The errno value has already been set */ va_end(ap); leave_cancellation_point(); return ERROR; } /* Let file_vfcntl() do the real work */ ret = file_vfcntl(filep, cmd, ap); } else #endif { /* No... check for operations on a socket descriptor */ #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) { /* Yes.. defer socket descriptor operations to net_vfcntl() */ ret = net_vfcntl(fd, cmd, ap); } else #endif { /* No.. this descriptor number is out of range */ set_errno(EBADF); ret = ERROR; } } va_end(ap); leave_cancellation_point(); return ret; }
int fcntl(int fildes, int cmd, ...) { va_list ap; int ret; /* Setup to access the variable argument list */ va_start(ap, cmd); /* Did we get a valid file descriptor? */ #if CONFIG_NFILE_DESCRIPTORS > 0 if ((unsigned int)fildes < CONFIG_NFILE_DESCRIPTORS) { /* Yes.. defer file operations to file_vfcntl() */ ret = file_vfcntl(fildes, cmd, ap); } else #endif { /* No... check for operations on a socket descriptor */ #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 if ((unsigned int)fildes < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) { /* Yes.. defer socket descriptor operations to net_vfcntl() */ ret = net_vfcntl(fildes, cmd, ap); } else #endif { /* No.. this descriptor number is out of range */ ret = EBADF; } } va_end(ap); return ret; }
int fcntl(int fd, int cmd, ...) { FAR struct file *filep; va_list ap; int ret; /* fcntl() is a cancellation point */ (void)enter_cancellation_point(); /* Setup to access the variable argument list */ va_start(ap, cmd); /* Did we get a valid file descriptor? */ #if CONFIG_NFILE_DESCRIPTORS > 0 if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS) { /* Get the file structure corresponding to the file descriptor. */ ret = fs_getfilep(fd, &filep); if (ret >= 0) { DEBUGASSERT(filep != NULL); /* Let file_vfcntl() do the real work. The errno is not set on * failures. */ ret = file_vfcntl(filep, cmd, ap); } } else #endif { /* No... check for operations on a socket descriptor */ #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) { /* Yes.. defer socket descriptor operations to net_vfcntl(). The * errno is not set on failures. */ ret = net_vfcntl(fd, cmd, ap); } else #endif { /* No.. this descriptor number is out of range */ ret = -EBADF; } } va_end(ap); if (ret < 0) { set_errno(-ret); ret = ERROR; } leave_cancellation_point(); return ret; }