Example #1
0
void cleanup_ignore(ignores *ig) {
    if (ig == NULL) {
        return;
    }
    free_strings(ig->extensions, ig->extensions_len);
    free_strings(ig->names, ig->names_len);
    free_strings(ig->slash_names, ig->slash_names_len);
    free_strings(ig->regexes, ig->regexes_len);
    free_strings(ig->slash_regexes, ig->slash_regexes_len);
    if (ig->abs_path) {
        free(ig->abs_path);
    }
    free(ig);
}
Example #2
0
static void dag_parse(struct dag * slf){

    int i;
    struct pkg * pk; 
    char * pkg_name;
    struct hash * hs = slf->pkgs;
    const char * root = global_get_str("-src");
    int (*filter)(const char *);

    int include_tests = global_get_bool("-test") || global_get_bool("-clean");

    filter = (include_tests)? &all_c_code : &c_code_no_tests;

    char ** files = path_walk_filter(root, filter);
    
    if( files != NULL ){
        for(i = 0; files[i] != NULL; i++){
            pkg_name = pkg_name_from_fname(root, files[i]);
            if(hs->has(hs, pkg_name)){
                pk = hs->get(hs, pkg_name);
                pk->add_file(pk, files[i]);
                free(pkg_name);
            }else{
                pk = new_pkg(pkg_name);
                pk->add_file(pk, files[i]);
                hs->put(hs, pkg_name, pk);
            }
        }
    }

    free_strings(files);

};
Example #3
0
CodeBuffer::~CodeBuffer() {
  verify_section_allocation();

  // If we allocate our code buffer from the CodeCache
  // via a BufferBlob, and it's not permanent, then
  // free the BufferBlob.
  // The rest of the memory will be freed when the ResourceObj
  // is released.
  for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) {
    // Previous incarnations of this buffer are held live, so that internal
    // addresses constructed before expansions will not be confused.
    cb->free_blob();
  }

  // free any overflow storage
  delete _overflow_arena;

  // Claim is that stack allocation ensures resources are cleaned up.
  // This is resource clean up, let's hope that all were properly copied out.
  free_strings();

#ifdef ASSERT
  // Save allocation type to execute assert in ~ResourceObj()
  // which is called after this destructor.
  assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object");
  ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type();
  Copy::fill_to_bytes(this, sizeof(*this), badResourceValue);
  ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at);
#endif
}
Example #4
0
static void build_bufed_list(EditState *s)
{
    QEmacsState *qs = s->qe_state;
    EditBuffer *b, *b1;
    BufedState *hs;
    int last_index = list_get_pos(s);
    int i, flags;

    hs = s->mode_data;

    free_strings(&hs->items);
    for (b = qs->first_buffer; b != NULL; b = b->next) {
        if (!(b->flags & BF_SYSTEM) || (hs->flags & BUFED_ALL_VISIBLE))
            add_string(&hs->items, b->name);
    }

    /* build buffer */
    b = s->b;
    flags = b->flags;
    b->flags &= ~BF_READONLY;
    eb_delete(b, 0, b->total_size);
    for (i = 0; i < hs->items.nb_items; i++) {
        eb_printf(b, " %-20s", hs->items.items[i]->str);
        b1 = eb_find(hs->items.items[i]->str);
        if (b1) {
            /* CG: should also display mode */
            eb_printf(b, " %10d  %s", b1->total_size, b1->filename);
        }
        eb_printf(b, "\n");
    }
    b->flags = flags;
    s->offset = eb_goto_pos(s->b, last_index, 0);
}
Example #5
0
static guestfs_int_isoinfo *
isoinfo (const char *path)
{
  char *out = NULL, *err = NULL;
  int r;
  char **lines = NULL;
  guestfs_int_isoinfo *ret = NULL;

  /* --debug is necessary to get additional fields, in particular
   * the date & time fields.
   */
  r = command (&out, &err, str_isoinfo, "--debug", "-d", "-i", path, NULL);
  if (r == -1) {
    reply_with_error ("%s", err);
    goto done;
  }

  lines = split_lines (out);
  if (lines == NULL)
    goto done;

  ret = parse_isoinfo (lines);
  if (ret == NULL)
    goto done;

 done:
  free (out);
  free (err);
  if (lines)
    free_strings (lines);

  return ret;
}
Example #6
0
static void bufed_mode_close(EditState *s)
{
    BufedState *bs = s->mode_data;

    free_strings(&bs->items);

    list_mode.mode_close(s);
}
Example #7
0
static void free_config(struct config_data *data)
{
  /* Free strings. */
  free_strings(data, OASIS_CFG);

  /* Free the data structure. */
  free(data);
}
Example #8
0
void
free_string_array(char *array[], size_t len)
{
	if(array != NULL)
	{
		free_strings(array, len);
		free(array);
	}
}
Example #9
0
END_TEST


START_TEST(test_make_lower)
{
    char strs[][4][20] = {{ "oNe", "TWO", "three", "Four" },
    { "ALPHA", "beta", "Gamma", "Theta" }};
    char ref[][4][20] = {{ "one", "two", "three", "four" },
    { "alpha", "beta", "gamma", "theta" }};

    const unsigned int num = 4;
    
    for (int k = 0; k < 2; k++) {
    char **arr = init_array();
    if(!arr) {
      fail("[Task 4.3.c] init_array returned NULL");
    }
    for (unsigned int i = 0; i < num; i++) {
        char **a2 = add_string(arr, strs[k][i]);
	if (!a2) {
	  free_strings(arr);
	  fail("[Task 4.3.c] add_string returned NULL");
	}
	arr = a2;
    }
    
    char buf[200];
    printref(buf, strs[k], num);
    
    make_lower(arr);
    
    for (unsigned int i = 0; i < num; i++) {
        if (strcmp(arr[i], ref[k][i])) {
            remove_nonascii(arr[i]);
            char buf2[200];
            sprintf(buf2, "[Task 4.3.c] After adding strings {%s}, array member %d is '%s', should be '%s'",
                    buf, i, arr[i], ref[k][i]);
            free_strings(arr);
            fail(buf2);
        }
    }
    free_strings(arr);
    }
}
Example #10
0
/* Convert a non-canonical LV path like /dev/mapper/vg-lv or /dev/dm-0
 * to a canonical one.
 *
 * This is harder than it should be.  A LV device like /dev/VG/LV is
 * really a symlink to a device-mapper device like /dev/dm-0.  However
 * at the device-mapper (kernel) level, nothing is really known about
 * LVM (a userspace concept).  Therefore we use a convoluted method to
 * determine this, by listing out known LVs and checking whether the
 * rdev (major/minor) of the device we are passed matches any of them.
 *
 * Note use of 'stat' instead of 'lstat' so that symlinks are fully
 * resolved.
 *
 * Returns:
 *   1  =  conversion was successful, path is an LV
 *         '*ret' is set to the updated path if 'ret' is non-NULL.
 *   0  =  path is not an LV
 *  -1  =  error, reply_with_* has been called
 *
 */
int
lv_canonical (const char *device, char **ret)
{
  struct stat stat1, stat2;

  int r = stat (device, &stat1);
  if (r == -1) {
    reply_with_perror ("stat: %s", device);
    return -1;
  }

  char **lvs = do_lvs ();
  if (lvs == NULL)
    return -1;

  size_t i;
  for (i = 0; lvs[i] != NULL; ++i) {
    r = stat (lvs[i], &stat2);
    if (r == -1) {
      reply_with_perror ("stat: %s", lvs[i]);
      free_strings (lvs);
      return -1;
    }
    if (stat1.st_rdev == stat2.st_rdev) { /* found it */
      if (ret) {
        *ret = strdup (lvs[i]);
        if (*ret == NULL) {
          reply_with_perror ("strdup");
          free_strings (lvs);
          return -1;
        }
      }
      free_strings (lvs);
      return 1;
    }
  }

  /* not found */
  free_strings (lvs);
  return 0;
}
Example #11
0
static void process_detach(void)
{
    close_gecko();
    release_typelib();

    if(shdoclc)
        FreeLibrary(shdoclc);
    if(mshtml_tls != TLS_OUT_OF_INDEXES)
        TlsFree(mshtml_tls);
    if(display_dc)
        DeleteObject(display_dc);

    free_strings();
}
Example #12
0
/******************************************************************
 *              DllMain (jscript.@)
 */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
    TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);

    switch(fdwReason) {
    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(hInstDLL);
        jscript_hinstance = hInstDLL;
        if(!init_strings())
            return FALSE;
        break;
    case DLL_PROCESS_DETACH:
        if (lpv) break;
        free_strings();
    }

    return TRUE;
}
Example #13
0
static void free_syntax(struct syntax *syn)
{
	int i;

	for (i = 0; i < syn->states.count; i++)
		free_state(syn->states.ptrs[i]);
	free(syn->states.ptrs);

	for (i = 0; i < syn->string_lists.count; i++)
		free_string_list(syn->string_lists.ptrs[i]);
	free(syn->string_lists.ptrs);

	for (i = 0; i < syn->default_colors.count; i++)
		free_strings(syn->default_colors.ptrs[i]);
	free(syn->default_colors.ptrs);

	free(syn->name);
	free(syn);
}
Example #14
0
int
add_string (char ***argv, int *size, int *alloc, const char *str)
{
  char *new_str;

  if (str) {
    new_str = strdup (str);
    if (new_str == NULL) {
      reply_with_perror ("strdup");
      free_strings (*argv);
      *argv = NULL;
      return -1;
    }
  } else {
    new_str = NULL;
  }

  return add_string_nodup (argv, size, alloc, new_str);
}
Example #15
0
void
pg_statement_send( VALUE conn, VALUE cmd, VALUE par)
{
    struct pgconn_data *c;
    int res;

    Data_Get_Struct( conn, struct pgconn_data, c);
    pg_check_conninvalid( c);
    if (NIL_P( par))
        res = PQsendQuery( c->conn, pgconn_destring( c, cmd, NULL));
    else {
        char **v;
        int len;

        v = params_to_strings( conn, par, &len);
        res = PQsendQueryParams( c->conn, pgconn_destring( c, cmd, NULL), len,
                                 NULL, (const char **) v, NULL, NULL, 0);
        free_strings( v, len);
    }
    if (res <= 0)
        pg_raise_connexec( c);
}
Example #16
0
int
add_string_nodup (char ***argv, int *size, int *alloc, char *str)
{
  char **new_argv;

  if (*size >= *alloc) {
    *alloc += 64;
    new_argv = realloc (*argv, *alloc * sizeof (char *));
    if (new_argv == NULL) {
      reply_with_perror ("realloc");
      free_strings (*argv);
      *argv = NULL;
      return -1;
    }
    *argv = new_argv;
  }

  (*argv)[*size] = str;

  (*size)++;
  return 0;
}
Example #17
0
static void pkg_add_file(struct pkg * slf, const char * fname){

    if(ends_with(fname, ".h")){
        slf->h_file = strdup(fname);
    }else if(ends_with(fname, ".c")){
        slf->c_file = strdup(fname);
    }else{
        panic("pkg.add_file only allows .h or .c files", __FILE__,__LINE__);
    }
    
    char ** imports = get_deps_from_fname(fname);

    if(imports){
        int i;
        for(i = 0; imports[i]; i++){
            if(! eq_str(imports[i], slf->name) ){
                slf->deps->add(slf->deps, imports[i]);
            }
        }
        free_strings(imports);
    }
};
Example #18
0
guestfs_int_xfsinfo *
do_xfs_info (const char *pathordevice)
{
  int r;
  char *buf;
  char *out = NULL, *err = NULL;
  char **lines = NULL;
  guestfs_int_xfsinfo *ret = NULL;
  int is_dev;

  is_dev = STREQLEN (pathordevice, "/dev/", 5);
  buf = is_dev ? strdup (pathordevice)
               : sysroot_path (pathordevice);
  if (buf == NULL) {
    reply_with_perror ("malloc");
    return NULL;
  }

  r = command (&out, &err, "xfs_info", buf, NULL);
  free (buf);
  if (r == -1) {
    reply_with_error ("%s", err);
    goto error;
  }

  lines = split_lines (out);
  if (lines == NULL)
    goto error;

  ret = parse_xfs_info (lines);

error:
  free (err);
  free (out);
  if (lines)
    free_strings (lines);
  return ret;
}
Example #19
0
static PyObject *
py_hivex_value_multiple_strings (PyObject *self, PyObject *args)
{
  PyObject *py_r;
  char **r;
  hive_h *h;
  PyObject *py_h;
  long val;

  if (!PyArg_ParseTuple (args, (char *) "Ol:hivex_value_multiple_strings", &py_h, &val))
    return NULL;
  h = get_handle (py_h);
  r = hivex_value_multiple_strings (h, val);
  if (r == NULL) {
    PyErr_SetString (PyExc_RuntimeError,
                     strerror (errno));
    return NULL;
  }

  py_r = put_string_list (r);
  free_strings (r);
  return py_r;
}
Example #20
0
VALUE
pg_statement_exec( VALUE conn, VALUE cmd, VALUE par)
{
    struct pgconn_data *c;
    PGresult *result;

    Data_Get_Struct( conn, struct pgconn_data, c);
    pg_check_conninvalid( c);
    if (NIL_P( par))
        result = PQexec( c->conn, pgconn_destring( c, cmd, NULL));
    else {
        char **v;
        int len;

        v = params_to_strings( conn, par, &len);
        result = PQexecParams( c->conn, pgconn_destring( c, cmd, NULL), len,
                               NULL, (const char **) v, NULL, NULL, 0);
        free_strings( v, len);
    }
    if (result == NULL)
        pg_raise_connexec( c);
    return pgresult_new( result, c, cmd, par);
}
Example #21
0
static void build_bufed_list(EditState *s)
{
    QEmacsState *qs = s->qe_state;
    EditBuffer *b;
    BufedState *hs;
    int i;

    hs = s->mode_data;

    free_strings(&hs->items);
    for(b = qs->first_buffer; b != NULL; b = b->next) {
        if (!(b->flags & BF_SYSTEM))
            add_string(&hs->items, b->name);
    }
    
    /* build buffer */
    b = s->b;
    eb_delete(b, 0, b->total_size);
    for(i=0;i<hs->items.nb_items;i++) {
        eb_printf(b, " %s", hs->items.items[i]->str);
        if (i != hs->items.nb_items - 1)
            eb_printf(b, "\n");
    }
}
Example #22
0
static int read_device(int fd, struct device_context *dev_ctx)
{
	/* name, description, icon_file */
	struct device dev;
	twin_pixmap_t *icon;
	int index = -1;

	if (!read_strings(fd, dev))
		return TWIN_FALSE;

	LOG("got device: '%s'\n", dev.name);

	icon = get_icon(dev.icon_file);

	if (!icon)
		goto out;

	index = dev_ctx->device_idx = pboot_add_device(dev.id, dev.name, icon);

out:
	free_strings(dev);

	return index != -1;
}
Example #23
0
char *
do_part_get_parttype (const char *device)
{
  int parted_has_m_opt = test_parted_m_opt ();
  if (parted_has_m_opt == -1)
    return NULL;

  char *out = print_partition_table (device, parted_has_m_opt);
  if (!out)
    return NULL;

  if (parted_has_m_opt) {
    /* New-style parsing using the "machine-readable" format from
     * 'parted -m'.
     */
    char **lines = split_lines (out);
    free (out);

    if (!lines)
      return NULL;

    if (lines[0] == NULL || STRNEQ (lines[0], "BYT;")) {
      reply_with_error ("unknown signature, expected \"BYT;\" as first line of the output: %s",
                        lines[0] ? lines[0] : "(signature was null)");
      free_strings (lines);
      return NULL;
    }

    if (lines[1] == NULL) {
      reply_with_error ("parted didn't return a line describing the device");
      free_strings (lines);
      return NULL;
    }

    /* lines[1] is something like:
     * "/dev/sda:1953525168s:scsi:512:512:msdos:ATA Hitachi HDT72101;"
     */
    char *r = get_table_field (lines[1], 5);
    if (r == NULL) {
      free_strings (lines);
      return NULL;
    }

    free_strings (lines);

    /* If "loop" return an error (RHBZ#634246). */
    if (STREQ (r, "loop")) {
      free (r);
      reply_with_error ("not a partitioned device");
      return NULL;
    }

    return r;
  }
  else {
    /* Old-style.  Look for "\nPartition Table: <str>\n". */
    char *p = strstr (out, "\nPartition Table: ");
    if (!p) {
      reply_with_error ("parted didn't return Partition Table line");
      free (out);
      return NULL;
    }

    p += 18;
    char *q = strchr (p, '\n');
    if (!q) {
      reply_with_error ("parted Partition Table has no end of line char");
      free (out);
      return NULL;
    }

    *q = '\0';

    p = strdup (p);
    free (out);
    if (!p) {
      reply_with_perror ("strdup");
      return NULL;
    }

    /* If "loop" return an error (RHBZ#634246). */
    if (STREQ (p, "loop")) {
      free (p);
      reply_with_error ("not a partitioned device");
      return NULL;
    }

    return p;                   /* caller frees */
  }
}
Example #24
0
File: hist.c Project: langner/vifm
void
hist_trunc(hist_t *hist, size_t new_size, size_t removed_count)
{
	free_strings(hist->items + new_size, removed_count);
	hist->pos = MIN(hist->pos, (int)new_size - 1);
}
Example #25
0
static void
save_cb(void *data, PurpleRequestFields *allfields)
{
	finch_request_save_in_prefs(data, allfields);
	free_strings();
}
Example #26
0
void g95_iresolve_done_1(void) {          
          
  free_strings();          
}  
Example #27
0
int
do_part_get_bootable (const char *device, int partnum)
{
  if (partnum <= 0) {
    reply_with_error ("partition number must be >= 1");
    return -1;
  }

  int parted_has_m_opt = test_parted_m_opt ();
  if (parted_has_m_opt == -1)
    return -1;

  char *out = print_partition_table (device, parted_has_m_opt);
  if (!out)
    return -1;

  char **lines = split_lines (out);
  free (out);

  if (!lines)
    return -1;

  if (parted_has_m_opt) {
    /* New-style parsing using the "machine-readable" format from
     * 'parted -m'.
     *
     * Partitions may not be in any order, so we have to look for
     * the matching partition number (RHBZ#602997).
     */
    if (lines[0] == NULL || STRNEQ (lines[0], "BYT;")) {
      reply_with_error ("unknown signature, expected \"BYT;\" as first line of the output: %s",
                        lines[0] ? lines[0] : "(signature was null)");
      free_strings (lines);
      return -1;
    }

    if (lines[1] == NULL) {
      reply_with_error ("parted didn't return a line describing the device");
      free_strings (lines);
      return -1;
    }

    size_t row;
    int pnum;
    for (row = 2; lines[row] != NULL; ++row) {
      if (sscanf (lines[row], "%d:", &pnum) != 1) {
        reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
        free_strings (lines);
        return -1;
      }
      if (pnum == partnum)
        break;
    }

    if (lines[row] == NULL) {
      reply_with_error ("partition number %d not found", partnum);
      free_strings (lines);
      return -1;
    }

    char *boot = get_table_field (lines[row], 6);
    if (boot == NULL) {
      free_strings (lines);
      return -1;
    }

    int r = STREQ (boot, "boot");

    free (boot);
    free_strings (lines);

    return r;
  }
  else {
    /* Old-style: First look for the line matching "^Number". */
    size_t start = 0, header, row;

    for (row = 0; lines[row] != NULL; ++row)
      if (STRPREFIX (lines[row], "Number")) {
        start = row+1;
        header = row;
        break;
      }

    if (start == 0) {
      reply_with_error ("parted output has no \"Number\" line");
      free_strings (lines);
      return -1;
    }

    /* Now we have to look at the column number of the "Flags" field.
     * This is because parted's output has no way to represent a
     * missing field except as whitespace, so we cannot just count
     * fields from the left.  eg. The "File system" field is often
     * missing in the output.
     */
    char *p = strstr (lines[header], "Flags");
    if (!p) {
      reply_with_error ("parted output has no \"Flags\" field");
      free_strings (lines);
      return -1;
    }
    size_t col = p - lines[header];

    /* Look for the line corresponding to this partition number. */
    row = start + partnum - 1;
    if (row >= count_strings (lines) || !STRPREFIX (lines[row], " ")) {
      reply_with_error ("partition number out of range: %d", partnum);
      free_strings (lines);
      return -1;
    }

    int r = STRPREFIX (&lines[row][col], "boot");
    free_strings (lines);
    return r;
  }
}
Example #28
0
int sporth_oscmorph4(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT out;
    sporth_oscmorph *oscmorph;

    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            fprintf(stderr, "oscmorph: Creating\n");
#endif
            oscmorph = malloc(sizeof(sporth_oscmorph));
            sp_oscmorph_create(&oscmorph->data);
            oscmorph->nft = 4;
            oscmorph->ft = malloc(sizeof(sp_ftbl *) * 4);
            oscmorph->ftname = malloc(sizeof(char *) * 4);
            plumber_add_ugen(pd, SPORTH_OSCMORPH4, oscmorph);

            if(sporth_check_args(stack, "ffffssss") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for oscmorph\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }

            get_strings(stack, oscmorph);
            pop_args(stack, oscmorph);

            if(search_for_ft(pd, oscmorph) == PLUMBER_NOTOK) {
                stack->error++;
                return PLUMBER_NOTOK;
            }

            sporth_stack_push_float(stack, 0);
            free_strings(oscmorph);
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            fprintf(stderr, "oscmorph: Initialising\n");
#endif

            oscmorph = pd->last->ud;
            get_strings(stack, oscmorph);

            pop_args(stack, oscmorph);

            sp_oscmorph_init(pd->sp, oscmorph->data, oscmorph->ft, oscmorph->nft, oscmorph->phase);

            sporth_stack_push_float(stack, 0);
            free_strings(oscmorph);
            break;
        case PLUMBER_COMPUTE:
            oscmorph = pd->last->ud;
            pop_args(stack, oscmorph);
            
            set_args(oscmorph);

            sp_oscmorph_compute(pd->sp, oscmorph->data, NULL, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            oscmorph = pd->last->ud;
            free(oscmorph->ftname);
            free(oscmorph->ft);
            sp_oscmorph_destroy(&oscmorph->data);
            free(oscmorph);
            break;
        default:
            fprintf(stderr, "oscmorph: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
Example #29
0
guestfs_int_partition_list *
do_part_list (const char *device)
{
  int parted_has_m_opt = test_parted_m_opt ();
  if (parted_has_m_opt == -1)
    return NULL;

  char *out = print_partition_table (device, parted_has_m_opt);
  if (!out)
    return NULL;

  char **lines = split_lines (out);
  free (out);

  if (!lines)
    return NULL;

  guestfs_int_partition_list *r;

  if (parted_has_m_opt) {
    /* New-style parsing using the "machine-readable" format from
     * 'parted -m'.
     *
     * lines[0] is "BYT;", lines[1] is the device line which we ignore,
     * lines[2..] are the partitions themselves.  Count how many.
     */
    size_t nr_rows = 0, row;
    for (row = 2; lines[row] != NULL; ++row)
      ++nr_rows;

    r = malloc (sizeof *r);
    if (r == NULL) {
      reply_with_perror ("malloc");
      goto error1;
    }
    r->guestfs_int_partition_list_len = nr_rows;
    r->guestfs_int_partition_list_val =
      malloc (nr_rows * sizeof (guestfs_int_partition));
    if (r->guestfs_int_partition_list_val == NULL) {
      reply_with_perror ("malloc");
      goto error2;
    }

    /* Now parse the lines. */
    size_t i;
    for (i = 0, row = 2; lines[row] != NULL; ++i, ++row) {
      if (sscanf (lines[row], "%d:%" SCNi64 "B:%" SCNi64 "B:%" SCNi64 "B",
                  &r->guestfs_int_partition_list_val[i].part_num,
                  &r->guestfs_int_partition_list_val[i].part_start,
                  &r->guestfs_int_partition_list_val[i].part_end,
                  &r->guestfs_int_partition_list_val[i].part_size) != 4) {
        reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
        goto error3;
      }
    }
  }
  else {
    /* Old-style.  Start at the line following "^Number", up to the
     * next blank line.
     */
    size_t start = 0, end = 0, row;

    for (row = 0; lines[row] != NULL; ++row)
      if (STRPREFIX (lines[row], "Number")) {
        start = row+1;
        break;
      }

    if (start == 0) {
      reply_with_error ("parted output has no \"Number\" line");
      goto error1;
    }

    for (row = start; lines[row] != NULL; ++row)
      if (STREQ (lines[row], "")) {
        end = row;
        break;
      }

    if (end == 0) {
      reply_with_error ("parted output has no blank after end of table");
      goto error1;
    }

    size_t nr_rows = end - start;

    r = malloc (sizeof *r);
    if (r == NULL) {
      reply_with_perror ("malloc");
      goto error1;
    }
    r->guestfs_int_partition_list_len = nr_rows;
    r->guestfs_int_partition_list_val =
      malloc (nr_rows * sizeof (guestfs_int_partition));
    if (r->guestfs_int_partition_list_val == NULL) {
      reply_with_perror ("malloc");
      goto error2;
    }

    /* Now parse the lines. */
    size_t i;
    for (i = 0, row = start; row < end; ++i, ++row) {
      if (sscanf (lines[row], " %d %" SCNi64 "B %" SCNi64 "B %" SCNi64 "B",
                  &r->guestfs_int_partition_list_val[i].part_num,
                  &r->guestfs_int_partition_list_val[i].part_start,
                  &r->guestfs_int_partition_list_val[i].part_end,
                  &r->guestfs_int_partition_list_val[i].part_size) != 4) {
        reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
        goto error3;
      }
    }
  }

  free_strings (lines);
  return r;

 error3:
  free (r->guestfs_int_partition_list_val);
 error2:
  free (r);
 error1:
  free_strings (lines);
  return NULL;
}
Example #30
0
/************************************************************************\
 ** Description :                                                      **
 **   Free's strings from any object, room, mobiles, or player.        **
 **                                                                    **
 ** Return Value:                                                      **
 **   TRUE if successful, otherwise, it returns FALSE.                 **
 **                                                                    **
 ** Parameters  :                                                      **
 **   type - The OLC type constant relating to the data type of data.  **
\************************************************************************/
int free_strings(void *data, int type)
{
  struct room_data *room;
  struct config_data *config;
  int i;
  
  switch (type) {
    case OASIS_WLD:
      room = (struct room_data *) data;
      
      /* Free Descriptions */
      if (room->name)
        free(room->name);
      
      if (room->description)
        free(room->description);
      
      if (room->ex_description)
	free_ex_descriptions(room->ex_description);
      
      /* Return the return value of free_strings(). */
      return (free_strings(room, OASIS_EXI));
    
    case OASIS_EXI:
      room = (struct room_data *) data;
      
      for (i = 0; i < NUM_OF_DIRS; i++) {
        if (room->dir_option[i]) {
          if (room->dir_option[i]->general_description)
            free(room->dir_option[i]->general_description);
            
          if (room->dir_option[i]->keyword)
            free(room->dir_option[i]->keyword);
          
          free(room->dir_option[i]);
        }
      }
      
      return (TRUE);
    
    case OASIS_MOB:
    case OASIS_OBJ:
      return (FALSE);		/* For now... */
    
    case OASIS_CFG:
      config = (struct config_data *) data;
      
      if (config->play.OK)
        free(config->play.OK);
        
      if (config->play.NOPERSON)
        free(config->play.NOPERSON);
        
      if (config->play.NOEFFECT)
        free(config->play.NOEFFECT);
      
      if (config->operation.DFLT_IP)
        free(config->operation.DFLT_IP);
        
      if (config->operation.DFLT_DIR)
        free(config->operation.DFLT_DIR);
        
      if (config->operation.LOGNAME)
        free(config->operation.LOGNAME);
        
      if (config->operation.MENU)
        free(config->operation.MENU);
        
      if (config->operation.WELC_MESSG)
        free(config->operation.WELC_MESSG);
        
      if (config->operation.START_MESSG)
        free(config->operation.START_MESSG);
      
      return (TRUE);
    
    default:
      mudlog(BRF, LVL_GOD, TRUE, "SYSERR: oasis_delete.c: free_strings: Invalid type handled (Type %d).", type);
      return (FALSE);
  }
}