Exemplo n.º 1
0
void delete_record(TTBIN_FILE *ttbin, TTBIN_RECORD *record)
{
    switch (record->tag)
    {
    case TAG_GPS: remove_array(&ttbin->gps_records, record); break;
    case TAG_LAP: remove_array(&ttbin->lap_records, record); break;
    case TAG_HEART_RATE: remove_array(&ttbin->heart_rate_records, record); break;
    case TAG_TREADMILL: remove_array(&ttbin->treadmill_records, record); break;
    case TAG_SWIM: remove_array(&ttbin->swim_records, record); break;
    case TAG_STATUS: remove_array(&ttbin->status_records, record); break;
    case TAG_GOAL_PROGRESS: remove_array(&ttbin->goal_progress_records, record); break;
    case TAG_INTERVAL_START: remove_array(&ttbin->interval_start_records, record); break;
    case TAG_INTERVAL_FINISH: remove_array(&ttbin->interval_finish_records, record); break;
    }

    if (record != ttbin->first)
        record->prev->next = record->next;
    else
        ttbin->first = record->next;
    if (record != ttbin->last)
        record->next->prev = record->prev;
    else
        ttbin->last = record->prev;
    free(record);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    if (argc != 2)
    {
        printf("usage: ./array0 <valid file path>\n");
        return 1;
    }
    if (argv[1] == NULL)
    {
        printf("can not process empty file name\n");
        return 2;
    }

    FILE* file = fopen(argv[1], "r");
    if (file == NULL)
    {
        printf("can not open file %s\n", argv[1]);
        return 2;
    }

    int_array numbers = read_numbers(file);
    print_array(numbers);

    remove_array(&numbers);
    fclose(file);

    return 0;
}
Exemplo n.º 3
0
/* delete a job array struct from memory and disk. This is used when the number
 *  of jobs that belong to the array becomes zero.
 *  returns zero if there are no errors, non-zero otherwise
 */
int array_delete(
    
  job_array *pa)

  {
  int                      i;
  char                     path[MAXPATHLEN + 1];
  char                     log_buf[LOCAL_LOG_BUF_SIZE];
  array_request_node      *rn;
  struct array_depend     *pdep;
  struct array_depend_job *pdj;

  /* first thing to do is take this out of the servers list of all arrays */
  remove_array(pa);

  /* unlock the mutex and free it */
  unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);
  free(pa->ai_mutex);

  /* delete the on disk copy of the struct */
  snprintf(path, sizeof(path), "%s%s%s",
    path_arrays, pa->ai_qs.fileprefix, ARRAY_FILE_SUFFIX);

  if (unlink(path))
    {
    sprintf(log_buf, "unable to delete %s", path);
    log_err(errno, "array_delete", log_buf);
    }

  /* clear array request linked list */
  for (rn = (array_request_node *)GET_NEXT(pa->request_tokens);
       rn != NULL;
       rn = (array_request_node *)GET_NEXT(pa->request_tokens))
    {
    delete_link(&rn->request_tokens_link);
    free(rn);
    }

  /* free the memory for the job pointers */
  for (i = 0; i < pa->ai_qs.array_size; i++)
    {
    if (pa->job_ids[i] != NULL)
      free(pa->job_ids[i]);
    }

  free(pa->job_ids);

  /* free the dependencies, if any */
  for (pdep = (struct array_depend *)GET_NEXT(pa->ai_qs.deps); 
       pdep != NULL;
       pdep = (struct array_depend *)GET_NEXT(pa->ai_qs.deps))
    {
    delete_link(&pdep->dp_link);

    for (pdj = (struct array_depend_job *)GET_NEXT(pdep->dp_jobs);
         pdj != NULL;
         pdj = (struct array_depend_job *)GET_NEXT(pdep->dp_jobs))
      {
      delete_link(&pdj->dc_link);
      free(pdj);
      }

    free(pdep);
    }

  /* purge the "template" job, 
     this also deletes the shared script file for the array*/
  if (pa->ai_qs.parent_id[0] != '\0')
    {
    job *pjob;
    if ((pjob = svr_find_job(pa->ai_qs.parent_id, FALSE)) != NULL)
      svr_job_purge(pjob);
    }

  /* free the memory allocated for the struct */
  free(pa);

  return 0;
  } /* END array_delete() */