/* * The write buffer implementation for Python v2. */ static SIP_SSIZE_T sipArray_getwritebuffer(PyObject *self, SIP_SSIZE_T seg, void **ptr) { if (check_writable((sipArrayObject *)self) < 0) return -1; return sipArray_getreadbuffer(self, seg, ptr); }
/* * Implement mapping assignment sub-script for the type. */ static int sipArray_ass_subscript(PyObject *self, PyObject *key, PyObject *value) { sipArrayObject *array = (sipArrayObject *)self; SIP_SSIZE_T start, len; void *value_data; if (check_writable(array) < 0) return -1; if (PyIndex_Check(key)) { start = PyNumber_AsSsize_t(key, PyExc_IndexError); if (start == -1 && PyErr_Occurred()) return -1; if (start < 0) start += array->len; if (check_index(array, start) < 0) return -1; if ((value_data = get_value(array, value)) == NULL) return -1; len = 1; } else if (PySlice_Check(key)) { Py_ssize_t stop, step; if (sipConvertFromSliceObject(key, array->len, &start, &stop, &step, &len) < 0) return -1; if (step != 1) { PyErr_SetNone(PyExc_NotImplementedError); return -1; } if ((value_data = get_slice(array, value, len)) == NULL) return -1; } else { bad_key(key); return -1; } memmove(element(array, start), value_data, len * array->stride); return 0; }
/* * Processes a single top-level man directory. If section isn't NULL, * it will only process that section sub-directory, otherwise it will * process all of them. */ static void process_mandir(char *dir_name, char *section) { fchdir(starting_dir); if (already_visited(NULL, dir_name, section == NULL)) return; check_writable(dir_name); if (verbose) fprintf(stderr, "man directory %s\n", dir_name); if (pretend) fprintf(stderr, "cd %s\n", dir_name); if (chdir(dir_name) < 0) { warn("%s: chdir", dir_name); exit_code = 1; return; } if (section != NULL) { process_section(dir_name, section); } else { struct dirent **entries; char *machine_dir, *arch_dir; int nsections; int i; nsections = scandir(".", &entries, select_sections, alphasort); if (nsections < 0) { warn("%s", dir_name); exit_code = 1; return; } for (i = 0; i < nsections; i++) { process_section(dir_name, entries[i]->d_name); asprintf(&machine_dir, "%s/%s", entries[i]->d_name, machine); if (test_path(machine_dir, NULL) & TEST_DIR) process_section(dir_name, machine_dir); free(machine_dir); if (strcmp(machine_arch, machine) != 0) { asprintf(&arch_dir, "%s/%s", entries[i]->d_name, machine_arch); if (test_path(arch_dir, NULL) & TEST_DIR) process_section(dir_name, arch_dir); free(arch_dir); } free(entries[i]); } free(entries); } }
/* * Implement sequence assignment item sub-script for the type. */ static int sipArray_ass_item(PyObject *self, int idx, PyObject *value) { sipArrayObject *array = (sipArrayObject *)self; void *value_data; if (check_writable(array) < 0 || check_index(array, idx) < 0) return -1; if ((value_data = get_value(array, value)) == NULL) return -1; memmove(element(array, idx), value_data, array->stride); return 0; }
/* * Implement sequence assignment slice sub-script for the type. */ static int sipArray_ass_slice(PyObject *self, int left, int right, PyObject *value) { sipArrayObject *array = (sipArrayObject *)self; void *value_data; if (check_writable(array) < 0) return -1; fix_bounds(array->len, &left, &right); if ((value_data = get_slice(array, value, right - left)) == NULL) return -1; memmove(element(array, left), value_data, (right - left) * array->stride); return 0; }
bool find_file (const char *filename) { Buffer bp; for (bp = head_bp; bp != NULL; bp = get_buffer_next (bp)) if (get_buffer_filename (bp) != NULL && STREQ (get_buffer_filename (bp), filename)) break; if (bp == NULL) { if (exist_file (filename) && !is_regular_file (filename)) { minibuf_error ("File exists but could not be read"); return false; } else { bp = buffer_new (); set_buffer_names (bp, filename); set_buffer_dir (bp, astr_new_cstr (dir_name (filename))); estr es = estr_readf (filename); if (es) set_buffer_readonly (bp, !check_writable (filename)); else es = estr_new_astr (astr_new ()); set_buffer_text (bp, es); /* Reset undo history. */ set_buffer_next_undop (bp, NULL); set_buffer_last_undop (bp, NULL); set_buffer_modified (bp, false); } } switch_to_buffer (bp); thisflag |= FLAG_NEED_RESYNC; return true; }
/* * Read the file contents into a buffer. * Return quietly if the file doesn't exist, or other error. */ void read_from_disk(const char *filename) { Line *lp; FILE *fp; int i, size, first_eol = TRUE; char *this_eol_type; size_t eol_len = 0, total_eols = 0; char buf[BUFSIZ]; if ((fp = fopen(filename, "r")) == NULL) { if (errno != ENOENT) { minibuf_write("%s: %s", filename, strerror(errno)); cur_bp->flags |= BFLAG_READONLY; } return; } #if HAVE_UNISTD_H if (!check_writable(filename)) cur_bp->flags |= BFLAG_READONLY; #endif lp = cur_bp->pt.p; /* Read first chunk and determine EOL type. */ if ((size = fread(buf, 1, BUFSIZ, fp)) > 0) { for (i = 0; i < size && total_eols < MAX_EOL_CHECK_COUNT; i++) { if (buf[i] == '\n' || buf[i] == '\r') { total_eols++; if (buf[i] == '\n') this_eol_type = coding_eol_lf; else if (i >= size || buf[i + 1] != '\n') this_eol_type = coding_eol_cr; else { this_eol_type = coding_eol_crlf; i++; } if (first_eol) { /* This is the first end-of-line. */ cur_bp->eol = this_eol_type; first_eol = FALSE; } else if (cur_bp->eol != this_eol_type) { /* This EOL is different from the last; arbitrarily choose LF. */ cur_bp->eol = coding_eol_lf; break; } } } /* Process this and subsequent chunks into lines. */ eol_len = strlen(cur_bp->eol); do { for (i = 0; i < size; i++) { if (strncmp(cur_bp->eol, buf + i, eol_len) != 0) astr_cat_char(lp->item, buf[i]); else { lp = list_prepend(lp, astr_new()); ++cur_bp->num_lines; i += eol_len - 1; } } } while ((size = fread(buf, 1, BUFSIZ, fp)) > 0); } list_next(lp) = cur_bp->lines; list_prev(cur_bp->lines) = lp; cur_bp->pt.p = list_next(cur_bp->lines); fclose(fp); }
void Flag::set_double(double value) { check_writable(); *((double*) _addr) = value; }
void Flag::set_ccstr(ccstr value) { check_writable(); *((ccstr*) _addr) = value; }
void Flag::set_size_t(size_t value) { check_writable(); *((size_t*) _addr) = value; }
void Flag::set_uint64_t(uint64_t value) { check_writable(); *((uint64_t*) _addr) = value; }
void Flag::set_uintx(uintx value) { check_writable(); *((uintx*) _addr) = value; }
void Flag::set_int(int value) { check_writable(); *((int*) _addr) = value; }
void Flag::set_bool(bool value) { check_writable(); *((bool*) _addr) = value; }