static GtkFileChooserConfirmation confirm_overwrite_callback (GtkFileChooser *dialog, gpointer data) { gchar *uri; GFile *file; GtkFileChooserConfirmation res; cedit_debug (DEBUG_COMMANDS); uri = gtk_file_chooser_get_uri (dialog); file = g_file_new_for_uri (uri); g_free (uri); if (is_read_only (file)) { if (replace_read_only_file (GTK_WINDOW (dialog), file)) res = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; else res = GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN; } else { /* fall back to the default confirmation dialog */ res = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; } g_object_unref (file); return res; }
static int do_remount_sb(struct super_block *sb, int flags, char *data) { int retval; struct vfsmount *vfsmnt; /* * Invalidate the inodes, as some mount options may be changed. * N.B. If we are changing media, we should check the return * from invalidate_inodes ... can't allow _any_ open files. */ invalidate_inodes(sb); if (!(flags & MS_RDONLY) && sb->s_dev && is_read_only(sb->s_dev)) return -EACCES; /*flags |= MS_RDONLY;*/ /* If we are remounting RDONLY, make sure there are no rw files open */ if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) if (!fs_may_remount_ro(sb)) return -EBUSY; if (sb->s_op && sb->s_op->remount_fs) { retval = sb->s_op->remount_fs(sb, &flags, data); if (retval) return retval; } sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); vfsmnt = lookup_vfsmnt(sb->s_dev); if (vfsmnt) vfsmnt->mnt_flags = sb->s_flags; return 0; }
int GridFTPModule::close(gfal_file_handle handle) { GridFTPFileDesc* desc = static_cast<GridFTPFileDesc*>(gfal_file_handle_get_fdesc(handle)); if (desc) { gridftp_rw_commit_put(GFAL_GRIDFTP_SCOPE_CLOSE, desc); if (is_write_only(desc->open_flags)) { desc->request->wait(GFAL_GRIDFTP_SCOPE_CLOSE); } else if (is_read_only(desc->open_flags)) { if (!desc->request->done) globus_ftp_client_abort(desc->handler->get_ftp_client_handle()); try { desc->request->wait(GFAL_GRIDFTP_SCOPE_CLOSE); } catch (const Gfal::CoreException& e) { if (e.code() != ECANCELED) throw; } } gfal_file_handle_delete(handle); delete desc; } return 0; }
int block_write(struct inode * inode, struct file * filp, const char * buf, int count) { int blocksize, blocksize_bits, i, buffercount,write_error; int block, blocks; loff_t offset; int chars; int written = 0, retval = 0; struct buffer_head * bhlist[NBUF]; unsigned int size; kdev_t dev; struct buffer_head * bh, *bufferlist[NBUF]; register char * p; write_error = buffercount = 0; dev = inode->i_rdev; if ( is_read_only( inode->i_rdev )) return -EPERM; blocksize = BLOCK_SIZE; if (blksize_size[MAJOR(dev)] && blksize_size[MAJOR(dev)][MINOR(dev)]) blocksize = blksize_size[MAJOR(dev)][MINOR(dev)]; i = blocksize; blocksize_bits = 0; while(i != 1) { blocksize_bits++; i >>= 1; } block = filp->f_pos >> blocksize_bits; offset = filp->f_pos & (blocksize-1); if (blk_size[MAJOR(dev)]) size = ((loff_t) blk_size[MAJOR(dev)][MINOR(dev)] << BLOCK_SIZE_BITS) >> blocksize_bits; else
/** * @brief Finishes moving a pattern. */ void TilesetView::end_state_moving_pattern() { QRect box = current_area_item->rect().toRect(); if (!box.isEmpty() && sceneRect().contains(box) && get_items_intersecting_current_area().isEmpty() && model->get_selection_count() == 1 && !is_read_only() && dragging_current_point != dragging_start_point) { // Context menu to move the pattern. QMenu menu; QAction* move_pattern_action = new QAction(tr("Move here"), this); connect(move_pattern_action, &QAction::triggered, [=] { emit change_selected_pattern_position_requested(box.topLeft()); }); menu.addAction(move_pattern_action); menu.addSeparator(); menu.addAction(tr("Cancel")); menu.exec(cursor().pos() + QPoint(1, 1)); } scene->removeItem(current_area_item); delete current_area_item; current_area_item = nullptr; start_state_normal(); }
void SystemProperties::ReadCallback(const prop_info* pi, void (*callback)(void* cookie, const char* name, const char* value, uint32_t serial), void* cookie) { // Read only properties don't need to copy the value to a temporary buffer, since it can never // change. if (is_read_only(pi->name)) { uint32_t serial = Serial(pi); if (pi->is_long()) { callback(cookie, pi->name, pi->long_value(), serial); } else { callback(cookie, pi->name, pi->value, serial); } return; } while (true) { uint32_t serial = Serial(pi); // acquire semantics size_t len = SERIAL_VALUE_LEN(serial); char value_buf[len + 1]; memcpy(value_buf, pi->value, len); value_buf[len] = '\0'; // TODO: see todo in Read function atomic_thread_fence(memory_order_acquire); if (serial == load_const_atomic(&(pi->serial), memory_order_relaxed)) { callback(cookie, pi->name, value_buf, serial); return; } } }
int orig_do_mount(kdev_t dev, const char * dev_name, const char * dir_name, const char * type, int flags, void * data) { #endif struct dentry * dir_d; struct super_block * sb; struct vfsmount *vfsmnt; int error; error = -EACCES; if (!(flags & MS_RDONLY) && dev && is_read_only(dev)) goto out; /* * Do the lookup first to force automounting. */ dir_d = namei(dir_name); error = PTR_ERR(dir_d); if (IS_ERR(dir_d)) goto out; down(&mount_sem); error = -ENOTDIR; if (!S_ISDIR(dir_d->d_inode->i_mode)) goto dput_and_out; error = -EBUSY; if (dir_d->d_covers != dir_d) goto dput_and_out; /* * Note: If the superblock already exists, * read_super just does a get_super(). */ error = -EINVAL; sb = read_super(dev, type, flags, data, 0); if (!sb) goto dput_and_out; /* * We may have slept while reading the super block, * so we check afterwards whether it's safe to mount. */ error = -EBUSY; if (!fs_may_mount(dev)) goto dput_and_out; error = -ENOMEM; vfsmnt = add_vfsmnt(sb, dev_name, dir_name); if (vfsmnt) { d_mount(dget(dir_d), sb->s_root); error = 0; } dput_and_out: dput(dir_d); up(&mount_sem); out: return error; }
int env_remove(const wcstring &key, int var_mode) { ASSERT_IS_MAIN_THREAD(); env_node_t *first_node; int erased = 0; if ((var_mode & ENV_USER) && is_read_only(key)) { return 2; } first_node = top; if (!(var_mode & ENV_UNIVERSAL)) { if (var_mode & ENV_GLOBAL) { first_node = global_env; } if (try_remove(first_node, key.c_str(), var_mode)) { event_t ev = event_t::variable_event(key); ev.arguments.push_back(L"VARIABLE"); ev.arguments.push_back(L"ERASE"); ev.arguments.push_back(key); event_fire(&ev); erased = 1; } } if (!erased && !(var_mode & ENV_GLOBAL) && !(var_mode & ENV_LOCAL)) { bool is_exported = uvars()->get_export(key); erased = uvars() && uvars()->remove(key); if (erased) { env_universal_barrier(); event_t ev = event_t::variable_event(key); ev.arguments.push_back(L"VARIABLE"); ev.arguments.push_back(L"ERASE"); ev.arguments.push_back(key); event_fire(&ev); } if (is_exported) mark_changed_exported(); } react_to_variable_change(key); return !erased; }
// gridFTP open is restricted by the protocol : READ or Write but not both // gfal_file_handle GridFTPModule::open(const char* url, int flag, mode_t mode) { GridFTPSessionHandler *handler = new GridFTPSessionHandler(_handle_factory, url); GridFTPStreamState* stream = new GridFTPStreamState(handler); GridFTPRequestState* request = new GridFTPRequestState(handler); std::auto_ptr<GridFTPFileDesc> desc(new GridFTPFileDesc(handler, request, stream, url, flag)); gfal_log(GFAL_VERBOSE_TRACE, " -> [GridFTPModule::open] "); globus_result_t res; // check ENOENT condition for R_ONLY if (is_read_only(desc->open_flags) && this->exists(url) == false) { char err_buff[2048]; snprintf(err_buff, 2048, " gridftp open error : %s on url %s", strerror(ENOENT), url); throw Gfal::CoreException(GFAL_GRIDFTP_SCOPE_OPEN, err_buff, ENOENT); } if (is_read_only(desc->open_flags)) { gfal_log(GFAL_VERBOSE_TRACE, " -> initialize FTP GET global operations... "); res = globus_ftp_client_get( desc->stream->handler->get_ftp_client_handle(), url, desc->stream->handler->get_ftp_client_operationattr(), NULL, globus_ftp_client_done_callback, desc->request); gfal_globus_check_result(GFAL_GRIDFTP_SCOPE_OPEN, res); } else if (is_write_only(desc->open_flags)) { gfal_log(GFAL_VERBOSE_TRACE, " -> initialize FTP PUT global operations ... "); res = globus_ftp_client_put( desc->stream->handler->get_ftp_client_handle(), url, desc->stream->handler->get_ftp_client_operationattr(), NULL, globus_ftp_client_done_callback, desc->request); gfal_globus_check_result(GFAL_GRIDFTP_SCOPE_OPEN, res); } else { gfal_log(GFAL_VERBOSE_TRACE, " -> no operation initialization, switch to partial read/write mode..."); desc->reset(); } gfal_log(GFAL_VERBOSE_TRACE, " <- [GridFTPModule::open] "); return gfal_file_handle_new2(gridftp_plugin_name(), (gpointer) desc.release(), NULL, url); }
int dogetopt(int minor, struct psdev_opt *opt) { int retval = 0; ENTRY; switch(opt->optname) { case PSDEV_TIMEOUT: opt->optval = izo_channels[minor].uc_timeout; break; case PSDEV_HARD: opt->optval = izo_channels[minor].uc_hard; break; case PSDEV_NO_FILTER: opt->optval = izo_channels[minor].uc_no_filter; break; case PSDEV_NO_JOURNAL: opt->optval = izo_channels[minor].uc_no_journal; break; case PSDEV_NO_UPCALL: opt->optval = izo_channels[minor].uc_no_upcall; break; #ifdef PSDEV_DEBUG case PSDEV_ERRORVAL: { int errorval = izo_channels[minor].uc_errorval; if (errorval < 0 && is_read_only(-errorval)) CERROR("device %s has been set read-only\n", kdevname(-errorval)); opt->optval = izo_channels[minor].uc_errorval; break; } #endif case PSDEV_TRACE: case PSDEV_DEBUG: case PSDEV_BYTES_TO_CLOSE: default: CDEBUG(D_PSDEV, "ioctl: dogetopt: minor %d, bad optval 0x%x, \n", minor, opt->optname); retval = -EINVAL; } EXIT; return retval; }
/** * @brief Finishes drawing a rectangle. */ void TilesetView::end_state_drawing_rectangle() { QRect rectangle = current_area_item->rect().toRect(); if (!rectangle.isEmpty() && sceneRect().contains(rectangle) && get_items_intersecting_current_area().isEmpty() && model->is_selection_empty() && !is_read_only()) { // Context menu to create a pattern. QMenu menu; EnumMenus<Ground>::create_actions( menu, EnumMenuCheckableOption::NON_CHECKABLE, [=](Ground ground) { QString pattern_id; do { ++last_integer_pattern_id; pattern_id = QString::number(last_integer_pattern_id); } while (model->id_to_index(pattern_id) != -1); emit create_pattern_requested(pattern_id, rectangle, ground); }); // Put most actions in a submenu to make the context menu smaller. QMenu sub_menu(tr("New pattern (more options)")); int i = 0; for (QAction* action : menu.actions()) { Ground ground = static_cast<Ground>(action->data().toInt()); if (ground == Ground::TRAVERSABLE || ground == Ground::WALL) { action->setText(tr("New pattern (%1)").arg(GroundTraits::get_friendly_name(ground))); } else { menu.removeAction(action); sub_menu.addAction(action); } ++i; } menu.addMenu(&sub_menu); menu.addSeparator(); menu.addAction(tr("Cancel")); menu.exec(cursor().pos() + QPoint(1, 1)); } scene->removeItem(current_area_item); delete current_area_item; current_area_item = nullptr; initially_selected_items.clear(); start_state_normal(); }
/** * @brief Receives a mouse press event. * @param event The event to handle. */ void TilesetView::mousePressEvent(QMouseEvent* event) { if (model == nullptr) { return; } if (state == State::NORMAL) { QList<QGraphicsItem*> items_under_mouse = items( QRect(event->pos(), QSize(1, 1)), Qt::IntersectsItemBoundingRect // Pick transparent items too. ); QGraphicsItem* item = items_under_mouse.empty() ? nullptr : items_under_mouse.first(); const bool control_or_shift = (event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier)); bool keep_selected = false; if (control_or_shift) { // If ctrl or shift is pressed, keep the existing selection. keep_selected = true; } else if (item != nullptr && item->isSelected()) { // When clicking an already selected item, keep the existing selection too. keep_selected = true; } if (!keep_selected) { scene->clearSelection(); } if (event->button() == Qt::LeftButton) { if (item != nullptr && item->isSelected() && model->get_selection_count() == 1 && !is_read_only()) { // Clicking on an already selected item: allow to move it. start_state_moving_pattern(event->pos()); } else { // Otherwise initialize a selection rectangle. initially_selected_items = scene->selectedItems(); start_state_drawing_rectangle(event->pos()); } } else { if (item != nullptr && !item->isSelected()) { // Select the right-clicked item. item->setSelected(true); } } } }
/** * @brief Shows a context menu with actions relative to the selected patterns. * * Does nothing if the view is in read-only mode. * * @param where Where to show the menu, in view coordinates. */ void TilesetView::show_context_menu(const QPoint& where) { if (model == nullptr) { return; } if (is_read_only()) { return; } QList<int> selected_indexes = model->get_selected_indexes(); if (selected_indexes.empty()) { return; } QMenu* menu = new QMenu(this); // Ground. build_context_menu_ground(*menu, selected_indexes); // Default layer. QMenu* layer_menu = new QMenu(tr("Default layer"), this); build_context_menu_layer(*layer_menu, selected_indexes); menu->addSeparator(); menu->addMenu(layer_menu); // Repeat mode. QMenu* repeat_mode_menu = new QMenu(tr("Repeatable"), this); build_context_menu_repeat_mode(*repeat_mode_menu, selected_indexes); menu->addSeparator(); menu->addMenu(repeat_mode_menu); // Animation. QMenu* animation_menu = new QMenu(tr("Animation"), this); build_context_menu_animation(*animation_menu, selected_indexes); menu->addSeparator(); menu->addMenu(animation_menu); // Change pattern id. menu->addSeparator(); change_pattern_id_action->setEnabled(model->get_selected_index() != -1); menu->addAction(change_pattern_id_action); // Delete patterns. menu->addSeparator(); menu->addAction(delete_patterns_action); // Create the menu at 1,1 to avoid the cursor being already in the first item. menu->popup(viewport()->mapToGlobal(where) + QPoint(1, 1)); }
int env_remove( const wcstring &key, int var_mode ) { ASSERT_IS_MAIN_THREAD(); env_node_t *first_node; int erased = 0; if( (var_mode & ENV_USER ) && is_read_only(key) ) { return 2; } first_node = top; if( ! (var_mode & ENV_UNIVERSAL ) ) { if( var_mode & ENV_GLOBAL ) { first_node = global_env; } if( try_remove( first_node, key.c_str(), var_mode ) ) { event_t ev = event_t::variable_event(key); ev.arguments.reset(new wcstring_list_t); ev.arguments->push_back(L"VARIABLE"); ev.arguments->push_back(L"ERASE"); ev.arguments->push_back(key); event_fire( &ev ); ev.arguments.reset(NULL); erased = 1; } } if( !erased && !(var_mode & ENV_GLOBAL) && !(var_mode & ENV_LOCAL) ) { erased = ! env_universal_remove( key.c_str() ); } react_to_variable_change(key); return !erased; }
bool WndProperty::Editor::on_mouse_down(int x, int y) { if (parent->on_mouse_down(x, y)) return true; #ifdef USE_GDI // If the Control is read-only -> drop this event, // so the default handler doesn't obtain the focus if (is_read_only()) return true; #endif return false; }
bool WndProperty::Editor::OnKeyCheck(unsigned key_code) const { switch (key_code) { case VK_RETURN: return is_read_only() || (parent->mDataField != NULL && parent->mDataField->supports_combolist) || !CanEditInPlace() || parent->HasHelp(); case VK_LEFT: case VK_RIGHT: return true; default: return EditWindow::OnKeyCheck(key_code); } }
ssize_t GridFTPModule::read(gfal_file_handle handle, void* buffer, size_t count) { GridFTPFileDesc* desc = static_cast<GridFTPFileDesc*>(gfal_file_handle_get_fdesc(handle)); ssize_t ret; Glib::Mutex::Lock locker(desc->lock); if (desc->is_not_seeked() && is_read_only(desc->open_flags) && desc->stream != NULL) { gfal_log(GFAL_VERBOSE_TRACE, " read in the GET main flow ... "); ret = gridftp_read_stream(GFAL_GRIDFTP_SCOPE_READ, desc->stream, buffer, count); } else { gfal_log(GFAL_VERBOSE_TRACE, " read with a pread ... "); ret = gridftp_rw_internal_pread(_handle_factory, desc, buffer, count, desc->current_offset); } desc->current_offset += ret; return ret; }
bool WndProperty::Editor::OnMouseDown(PixelScalar x, PixelScalar y) { if (parent->OnMouseDown(x, y)) return true; #ifdef USE_GDI // If the Control is read-only -> drop this event, // so the default handler doesn't obtain the focus if (is_read_only()) return true; #endif return EditWindow::OnMouseDown(x, y); }
bool WndProperty::Editor::on_key_check(unsigned key_code) const { switch (key_code) { case VK_RETURN: return is_read_only() || (parent->mDataField != NULL && parent->mDataField->SupportCombo) || !CanEditInPlace(); case VK_LEFT: case VK_RIGHT: return true; default: return false; } }
int do_mount(kdev_t dev, const char * dev_name, const char * dir_name, const char * type, int flags, void * data) { struct inode * dir_i; struct super_block * sb; struct vfsmount *vfsmnt; int error; if (!(flags & MS_RDONLY) && dev && is_read_only(dev)) return -EACCES; /*flags |= MS_RDONLY;*/ error = namei(dir_name, &dir_i); if (error) return error; if (dir_i->i_count != 1 || dir_i->i_mount) { iput(dir_i); return -EBUSY; } if (!S_ISDIR(dir_i->i_mode)) { iput(dir_i); return -ENOTDIR; } if (!fs_may_mount(dev)) { iput(dir_i); return -EBUSY; } sb = read_super(dev,type,flags,data,0); if (!sb) { iput(dir_i); return -EINVAL; } if (sb->s_covered) { iput(dir_i); return -EBUSY; } vfsmnt = add_vfsmnt(dev, dev_name, dir_name); if (vfsmnt) { vfsmnt->mnt_sb = sb; vfsmnt->mnt_flags = flags; } sb->s_covered = dir_i; dir_i->i_mount = sb->s_mounted; return 0; /* we don't iput(dir_i) - see umount */ }
bool WndProperty::Editor::on_mouse_down(int x, int y) { // if it's an Combopicker field if (parent->mDialogStyle) // call the combopicker routine if (parent->on_mouse_down(x, y)) return true; #ifndef ENABLE_SDL // If the Control is read-only -> drop this event, // so the default handler doesn't obtain the focus if (is_read_only()) return true; #endif return false; }
/* * Swap partitions are now read via brw_page. ll_rw_page is an * asynchronous function now --- we must call wait_on_page afterwards * if synchronous IO is required. */ void ll_rw_page(int rw, kdev_t dev, unsigned long page, char * buffer) { int block = page; switch (rw) { case READ: break; case WRITE: if (is_read_only(dev)) { printk("Can't page to read-only device %s\n", kdevname(dev)); return; } break; default: panic("ll_rw_page: bad block dev cmd, must be R/W"); } if (set_bit(PG_locked, &mem_map[MAP_NR(buffer)].flags)) panic ("ll_rw_page: page already locked"); brw_page(rw, (unsigned long) buffer, dev, &block, PAGE_SIZE, 0); }
int SystemProperties::Add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen) { if (valuelen >= PROP_VALUE_MAX && !is_read_only(name)) { return -1; } if (namelen < 1) { return -1; } if (!initialized_) { return -1; } prop_area* serial_pa = contexts_->GetSerialPropArea(); if (serial_pa == nullptr) { return -1; } prop_area* pa = contexts_->GetPropAreaForName(name); if (!pa) { async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Access denied adding property \"%s\"", name); return -1; } bool ret = pa->add(name, namelen, value, valuelen); if (!ret) { return -1; } // There is only a single mutator, but we want to make sure that // updates are visible to a reader waiting for the update. atomic_store_explicit(serial_pa->serial(), atomic_load_explicit(serial_pa->serial(), memory_order_relaxed) + 1, memory_order_release); __futex_wake(serial_pa->serial(), INT32_MAX); return 0; }
static int do_remount_sb(struct super_block *sb, int flags, char *data) { int retval; struct vfsmount *vfsmnt; if (!(flags & MS_RDONLY) && sb->s_dev && is_read_only(sb->s_dev)) return -EACCES; /*flags |= MS_RDONLY;*/ /* If we are remounting RDONLY, make sure there are no rw files open */ if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) if (!fs_may_remount_ro(sb->s_dev)) return -EBUSY; if (sb->s_op && sb->s_op->remount_fs) { retval = sb->s_op->remount_fs(sb, &flags, data); if (retval) return retval; } sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); vfsmnt = lookup_vfsmnt(sb->s_dev); if (vfsmnt) vfsmnt->mnt_flags = sb->s_flags; return 0; }
static gboolean is_any_change_read_only (xmlNodePtr current_node, xmlNodePtr new_node) { GList *changes = get_toplevel_changes (current_node, new_node); GList *iter; gboolean read_only = FALSE; for (iter = changes; iter != NULL; iter = iter->next) { NodeDiff *diff = (NodeDiff *) iter->data; if (is_read_only (diff->node_name, diff->attribute_name)) { read_only = TRUE; break; } } if (changes != NULL) g_list_free_full (changes, (GDestroyNotify) node_diff_free); return read_only; }
int SystemProperties::Read(const prop_info* pi, char* name, char* value) { while (true) { uint32_t serial = Serial(pi); // acquire semantics size_t len = SERIAL_VALUE_LEN(serial); memcpy(value, pi->value, len + 1); // TODO: Fix the synchronization scheme here. // There is no fully supported way to implement this kind // of synchronization in C++11, since the memcpy races with // updates to pi, and the data being accessed is not atomic. // The following fence is unintuitive, but would be the // correct one if memcpy used memory_order_relaxed atomic accesses. // In practice it seems unlikely that the generated code would // would be any different, so this should be OK. atomic_thread_fence(memory_order_acquire); if (serial == load_const_atomic(&(pi->serial), memory_order_relaxed)) { if (name != nullptr) { size_t namelen = strlcpy(name, pi->name, PROP_NAME_MAX); if (namelen >= PROP_NAME_MAX) { async_safe_format_log(ANDROID_LOG_ERROR, "libc", "The property name length for \"%s\" is >= %d;" " please use __system_property_read_callback" " to read this property. (the name is truncated to \"%s\")", pi->name, PROP_NAME_MAX - 1, name); } } if (is_read_only(pi->name) && pi->is_long()) { async_safe_format_log( ANDROID_LOG_ERROR, "libc", "The property \"%s\" has a value with length %zu that is too large for" " __system_property_get()/__system_property_read(); use" " __system_property_read_callback() instead.", pi->name, strlen(pi->long_value())); } return len; } } }
/** * @brief Changes the position of the rectangle the user is drawing or moving. * * If the specified area is the same as before, nothing is done. * * @param new_area new position of the rectangle. */ void TilesetView::set_current_area(const QRect& area) { if (current_area_item->rect().toRect() == area) { // No change. return; } current_area_item->setRect(area); if (state == State::DRAWING_RECTANGLE) { // Select items strictly in the rectangle. scene->clearSelection(); QPainterPath path; path.addRect(QRect(area.topLeft() - QPoint(1, 1), area.size() + QSize(2, 2))); scene->setSelectionArea(path, Qt::ContainsItemBoundingRect); } if (state == State::MOVING_PATTERN) { // Check overlapping existing patterns. if (!area.isEmpty() && sceneRect().contains(area) && get_items_intersecting_current_area().isEmpty() && model->get_selection_count() == 1 && !is_read_only()) { current_area_item->setPen(QPen(Qt::yellow)); } else { current_area_item->setPen(QPen(Qt::red)); } } // Re-select items that were already selected if Ctrl or Shift was pressed. for (QGraphicsItem* item : initially_selected_items) { item->setSelected(true); } }
ssize_t block_write(struct file * filp, const char * buf, size_t count, loff_t *ppos) { struct inode * inode = filp->f_dentry->d_inode; ssize_t blocksize, blocksize_bits, i, buffercount, write_error; ssize_t block, blocks; loff_t offset; ssize_t chars; ssize_t written; struct buffer_head * bhlist[NBUF]; size_t size; kdev_t dev = inode->i_rdev; struct buffer_head * bh, *bufferlist[NBUF]; register char * p; if (is_read_only(dev)) return -EPERM; written = write_error = buffercount = 0; blocksize = BLOCK_SIZE; if (blksize_size[MAJOR(dev)] && blksize_size[MAJOR(dev)][MINOR(dev)]) blocksize = blksize_size[MAJOR(dev)][MINOR(dev)]; i = blocksize; blocksize_bits = 0; while(i != 1) { blocksize_bits++; i >>= 1; } block = *ppos >> blocksize_bits; offset = *ppos & (blocksize-1); if (blk_size[MAJOR(dev)]) size = ((loff_t) blk_size[MAJOR(dev)][MINOR(dev)] << BLOCK_SIZE_BITS) >> blocksize_bits; else
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode) { ASSERT_IS_MAIN_THREAD(); bool has_changed_old = has_changed_exported; bool has_changed_new = false; int done=0; if (val && contains(key, L"PWD", L"HOME")) { /* Canoncalize our path; if it changes, recurse and try again. */ wcstring val_canonical = val; path_make_canonical(val_canonical); if (val != val_canonical) { return env_set(key, val_canonical.c_str(), var_mode); } } if ((var_mode & (ENV_LOCAL | ENV_UNIVERSAL)) && (is_read_only(key) || is_electric(key))) { return ENV_SCOPE; } if ((var_mode & ENV_EXPORT) && is_electric(key)) { return ENV_SCOPE; } if ((var_mode & ENV_USER) && is_read_only(key)) { return ENV_PERM; } if (key == L"umask") { wchar_t *end; /* Set the new umask */ if (val && wcslen(val)) { errno=0; long mask = wcstol(val, &end, 8); if (!errno && (!*end) && (mask <= 0777) && (mask >= 0)) { umask(mask); /* Do not actually create a umask variable, on env_get, it will be calculated dynamically */ return 0; } } return ENV_INVALID; } /* Zero element arrays are internaly not coded as null but as this placeholder string */ if (!val) { val = ENV_NULL; } if (var_mode & ENV_UNIVERSAL) { const bool old_export = uvars() && uvars()->get_export(key); bool new_export; if (var_mode & ENV_EXPORT) { // export new_export = true; } else if (var_mode & ENV_UNEXPORT) { // unexport new_export = false; } else { // not changing the export new_export = old_export; } if (uvars()) { uvars()->set(key, val, new_export); env_universal_barrier(); if (old_export || new_export) { mark_changed_exported(); } } } else { // Determine the node env_node_t *preexisting_node = env_get_node(key); bool preexisting_entry_exportv = false; if (preexisting_node != NULL) { var_table_t::const_iterator result = preexisting_node->env.find(key); assert(result != preexisting_node->env.end()); const var_entry_t &entry = result->second; if (entry.exportv) { preexisting_entry_exportv = true; has_changed_new = true; } } env_node_t *node = NULL; if (var_mode & ENV_GLOBAL) { node = global_env; } else if (var_mode & ENV_LOCAL) { node = top; } else if (preexisting_node != NULL) { node = preexisting_node; if ((var_mode & (ENV_EXPORT | ENV_UNEXPORT)) == 0) { // use existing entry's exportv var_mode = preexisting_entry_exportv ? ENV_EXPORT : 0; } } else { if (! get_proc_had_barrier()) { set_proc_had_barrier(true); env_universal_barrier(); } if (uvars() && ! uvars()->get(key).missing()) { bool exportv; if (var_mode & ENV_EXPORT) { exportv = true; } else if (var_mode & ENV_UNEXPORT) { exportv = false; } else { exportv = uvars()->get_export(key); } uvars()->set(key, val, exportv); env_universal_barrier(); done = 1; } else { /* New variable with unspecified scope. The default scope is the innermost scope that is shadowing, which will be either the current function or the global scope. */ node = top; while (node->next && !node->new_scope) { node = node->next; } } } if (!done) { // Set the entry in the node // Note that operator[] accesses the existing entry, or creates a new one var_entry_t &entry = node->env[key]; if (entry.exportv) { // this variable already existed, and was exported has_changed_new = true; } entry.val = val; if (var_mode & ENV_EXPORT) { // the new variable is exported entry.exportv = true; node->exportv = true; has_changed_new = true; } else { entry.exportv = false; } if (has_changed_old || has_changed_new) mark_changed_exported(); } } event_t ev = event_t::variable_event(key); ev.arguments.reserve(3); ev.arguments.push_back(L"VARIABLE"); ev.arguments.push_back(L"SET"); ev.arguments.push_back(key); // debug( 1, L"env_set: fire events on variable %ls", key ); event_fire(&ev); // debug( 1, L"env_set: return from event firing" ); react_to_variable_change(key); return 0; }
void env_init(const struct config_paths_t *paths /* or NULL */) { /* env_read_only variables can not be altered directly by the user */ const wchar_t * const ro_keys[] = { L"status", L"history", L"version", L"_", L"LINES", L"COLUMNS", L"PWD", //L"SHLVL", // will be inserted a bit lower down L"FISH_VERSION", }; for (size_t i=0; i < sizeof ro_keys / sizeof *ro_keys; i++) { env_read_only.insert(ro_keys[i]); } /* Names of all dynamically calculated variables */ env_electric.insert(L"history"); env_electric.insert(L"status"); env_electric.insert(L"umask"); env_electric.insert(L"COLUMNS"); env_electric.insert(L"LINES"); top = new env_node_t; global_env = top; global = &top->env; /* Now the environemnt variable handling is set up, the next step is to insert valid data */ /* Import environment variables */ for (char **p = (environ ? environ : __environ); p && *p; p++) { const wcstring key_and_val = str2wcstring(*p); //like foo=bar size_t eql = key_and_val.find(L'='); if (eql == wcstring::npos) { // no equals found if (is_read_only(key_and_val) || is_electric(key_and_val)) continue; env_set(key_and_val, L"", ENV_EXPORT | ENV_GLOBAL); } else { wcstring key = key_and_val.substr(0, eql); if (is_read_only(key) || is_electric(key)) continue; wcstring val = key_and_val.substr(eql + 1); if (variable_is_colon_delimited_array(key)) { std::replace(val.begin(), val.end(), L':', ARRAY_SEP); } env_set(key, val.c_str(), ENV_EXPORT | ENV_GLOBAL); } } /* Set the given paths in the environment, if we have any */ if (paths != NULL) { env_set(FISH_DATADIR_VAR, paths->data.c_str(), ENV_GLOBAL); env_set(FISH_SYSCONFDIR_VAR, paths->sysconf.c_str(), ENV_GLOBAL); env_set(FISH_HELPDIR_VAR, paths->doc.c_str(), ENV_GLOBAL); env_set(FISH_BIN_DIR, paths->bin.c_str(), ENV_GLOBAL); } /* Set up the PATH variable */ setup_path(); /* Set up the USER variable */ if (env_get_string(L"USER").missing_or_empty()) { const struct passwd *pw = getpwuid(getuid()); if (pw && pw->pw_name) { const wcstring uname = str2wcstring(pw->pw_name); env_set(L"USER", uname.c_str(), ENV_GLOBAL | ENV_EXPORT); } } /* Set up the version variables */ wcstring version = str2wcstring(get_fish_version()); env_set(L"version", version.c_str(), ENV_GLOBAL); env_set(L"FISH_VERSION", version.c_str(), ENV_GLOBAL); /* Set up SHLVL variable */ const env_var_t shlvl_str = env_get_string(L"SHLVL"); wcstring nshlvl_str = L"1"; if (! shlvl_str.missing()) { wchar_t *end; long shlvl_i = wcstol(shlvl_str.c_str(), &end, 10); while (iswspace(*end)) ++end; /* skip trailing whitespace */ if (shlvl_i >= 0 && *end == '\0') { nshlvl_str = to_string<long>(shlvl_i + 1); } } env_set(L"SHLVL", nshlvl_str.c_str(), ENV_GLOBAL | ENV_EXPORT); env_read_only.insert(L"SHLVL"); /* Set up the HOME variable */ if (env_get_string(L"HOME").missing_or_empty()) { const env_var_t unam = env_get_string(L"USER"); char *unam_narrow = wcs2str(unam.c_str()); struct passwd *pw = getpwnam(unam_narrow); if (pw->pw_dir != NULL) { const wcstring dir = str2wcstring(pw->pw_dir); env_set(L"HOME", dir.c_str(), ENV_GLOBAL | ENV_EXPORT); } free(unam_narrow); } /* Set PWD */ env_set_pwd(); /* Set up universal variables. The empty string means to use the deafult path. */ assert(s_universal_variables == NULL); s_universal_variables = new env_universal_t(L""); s_universal_variables->load(); /* Set g_log_forks */ env_var_t log_forks = env_get_string(L"fish_log_forks"); g_log_forks = ! log_forks.missing_or_empty() && from_string<bool>(log_forks); /* Set g_use_posix_spawn. Default to true. */ env_var_t use_posix_spawn = env_get_string(L"fish_use_posix_spawn"); g_use_posix_spawn = (use_posix_spawn.missing_or_empty() ? true : from_string<bool>(use_posix_spawn)); /* Set fish_bind_mode to "default" */ env_set(FISH_BIND_MODE_VAR, DEFAULT_BIND_MODE, ENV_GLOBAL); /* Now that the global scope is fully initialized, add a toplevel local scope. This same local scope will persist throughout the lifetime of the fish process, and it will ensure that `set -l` commands run at the command-line don't affect the global scope. */ env_push(false); }